Programming Quantum Computers : Essential Algorithms and Code Samples
معرفی کتاب «Programming Quantum Computers : Essential Algorithms and Code Samples» نوشتهٔ Johnston, Eric R;Gimeno-Segovia, Mercedes;Harrigan, Nic، منتشرشده توسط نشر O'Reilly Media در سال 2019. این کتاب در فرمت pdf، زبان انگلیسی ارائه شده است. «Programming Quantum Computers : Essential Algorithms and Code Samples» در دستهٔ بدون دستهبندی قرار دارد.
Quantum computers are poised to kick-start a new computing revolution—and you can join in right away. If you’re in software engineering, computer graphics, data science, or just an intrigued computerphile, this book provides a hands-on programmer’s guide to understanding quantum computing. Rather than labor through math and theory, you’ll work directly with examples that demonstrate this technology’s unique capabilities. Quantum computing specialists Eric Johnston, Nic Harrigan, and Mercedes Gimeno-Segovia show you how to build the skills, tools, and intuition required to write quantum programs at the center of applications. You’ll understand what quantum computers can do and learn how to identify the types of problems they can solve. This book includes three multichapter sections: • Programming for a QPU — Explore core concepts for programming quantum processing units, including how to describe and manipulate qubits and how to perform quantum teleportation. • QPU Primitives — Learn algorithmic primitives and techniques, including amplitude amplification, the Quantum Fourier Transform, and phase estimation. • QPU Applications — Investigate how QPU primitives are used to build existing applications, including quantum search techniques and Shor’s factoring algorithm. Programming Quantum Computers 2 Practical Programming on Quantum Computers 3 Revision History for the Early Release 3 Chapter 1. Introduction 4 Figure 1-1. Quantum logic can look a bit like sheet music 4 Required background 4 What is a QPU? 5 A Hands-on Approach 6 A QCEngine primer 7 RUNNING CODE 7 Figure 1-2. The QCEngine UI 8 Figure 1-3. QCEngine UI elements for visualizing QPU results 9 DEBUGGING CODE 9 Figure 1-4. Stepping through a QCEngine progam using the circuit and circle-notation visualizers 10 Native QPU Instructions 10 Simulator Limitations 18 Hardware Limitations 19 QPU vs. GPU: Some Common Characteristics 19 How this book is structured 20 Chapter 2. One Qubit 22 Qubits vs. Bits 22 Figure 2-1. Possible values of a conventional bit - a graphical representation 22 Figure 2-2. Some possible values of a qubit 24 BRA-KET NOTATION 24 Introducing Circle Notation 24 Size of the circles: 24 Figure 2-3. Probability of reading the value 1 for different superpositions represented in circle notation 25 DESTRUCTIVE OBSERVATION 25 Relative rotation of the circles: 25 Figure 2-4. Example relative phases in a single qubit 25 WARNING 25 Figure 2-5. Only relative rotations matter in circle notation. 26 A Quick Look at a Physical Qubit 26 Figure 2-6. Using a photon as a conventional bit 27 Figure 2-7. A simple implementation of one photonic qubit 27 WARNING 28 HANDS-ON 28 The First Few QPU Operations 29 QPU Instruction: NOT 29 Figure 2-8. The NOT operator in circle notation 30 QPU Instruction: HAD 30 Figure 2-9. Hadamard applied to some basic states 31 QPU Instruction: READ and WRITE 31 Figure 2-10. The READ operator produces random results 32 WHAT HAPPENED TO THE PHASE? 32 Hands-on: A perfectly random bit 33 Figure 2-11. Generating a perfectly random bit with a QPU 33 SAMPLE CODE 34 Example 2-1. One random bit 34 ABOUT THESE CODE SAMPLES 34 Figure 2-12. One random byte 35 SAMPLE CODE 35 Example 2-2. One random byte 35 EIGHT SEPARATE QUBITS 35 QPU Instruction: PHASE() 36 Figure 2-13. Operation of a PHASE gate 36 Figure 2-14. Four very commonly used single-qubit states 37 QPU Instructions: ROTX() and ROTY() rotation operations 37 Figure 2-15. ROTX and ROTY actions on 0 and 1 input states. 37 2D ROTATIONS ON A 4D OBJECT 38 The missing operation 38 Combining QPU operations 38 Figure 2-16. Building equivalent gates 39 WARNING 39 QPU Combo Instruction: ROOT-of-NOT 39 Figure 2-17. An impossible operation for classical bits 40 Figure 2-18. Recipe for root-of-not 40 SAMPLE CODE 40 Example 2-3. Showing the action of RNOT 40 NOTE 40 Figure 2-19. Operation of the ROOT-of-NOT gate 41 Figure 2-20. Inverse of root-of-not 41 Hands-on: Quantum Spy Hunter 41 Figure 2-21. Quantum spy hunter 42 SAMPLE CODE 42 Example 2-4. Quantum Random Spy Hunter 42 Conclusion 44 Chapter 3. Multiple Qubits 46 Circle notation for multi-qubit registers 46 Figure 3-1. Circle notation for various numbers of multiple qubits 47 Figure 3-2. Some multi-qubit quantum states can be understood in terms of single qubit states 48 SAMPLE CODE 48 Example 3-1. Creating a multi-qubit state that can be expressed in terms of its qubits 48 TIP 48 Figure 3-3. Quantum relationships between multiple qubits. 49 HOW MANY BITS PER QUBIT? 49 Drawing a Multi-Qubit Register 49 Figure 3-4. One random byte 50 NAMING QUBITS 50 Single-qubit Operations in Multi-Qubit Registers 50 Figure 3-5. The NOT operation swaps terms in each of the qubit’s operator pairs. 51 Figure 3-6. Single-qubit phase in a multi-qubit register. 51 Reading a qubit in a multi-qubit register 52 Figure 3-7. Reading one qubit in a multi-qubit register 52 Visualizing Larger Numbers of Qubits 52 Figure 3-8. Circle notation for larger qubit counts 53 Figure 3-9. Sometimes exaggeration is warranted 54 TIP 54 QPU Instruction: CNOT 54 Figure 3-10. CNOT in operation 55 Figure 3-11. CNOT with a target qubit in superposition 56 Figure 3-12. Bell Pair step 1 56 Figure 3-13. Bell Pair step 2 56 Figure 3-14. Bell Pair step 3 57 TIP 57 Hands-on: Using Bell Pairs for shared randomness 58 Figure 3-15. Bell Pair circuit 58 SAMPLE CODE 58 Example 3-2. Make a Bell Pair 58 QPU Instruction: CPHASE and CZ 59 Figure 3-16. Applying CPHASE in circle notation 60 Figure 3-17. CZ, CPHASE and CNOT 61 Phase kickback 61 Figure 3-18. Circuit for demonstrating phase kickback trick 61 Figure 3-19. States of both registers involved in phase kickback 62 NOTE 62 SAMPLE CODE 62 Example 3-3. Phase Kickback 62 Constructing Any Conditional Operation 63 Figure 3-20. Desired operation of a CPHASE(90) operation 64 Figure 3-21. Constructing a CPHASE operation 64 SAMPLE CODE 64 Example 3-4. Custom conditional-phase 64 Figure 3-22. Step-by-step through the constructed CPHASE operation 65 QPU Instruction: CCNOT (Toffoli) 65 Figure 3-23. Adding conditions makes the NOT operation more selective 67 FAN IN AND FAN OUT 67 QPU Instruction: SWAP and CSWAP 67 Figure 3-24. Swap can be made from CNOT operations 68 A DIGITAL PARALLEL 68 Figure 3-25. CSWAP constructed from Toffoli gates 68 The swap test 68 Figure 3-26. Using the swap test to determine whether two states match 69 SAMPLE CODE 69 Example 3-5. The swap test 69 Figure 3-27. How output of swap test varies as input states are made increasingly different 70 Figure 3-28. Number of swap tests that would need to return an outcome of 1 for us to be 99% confident inputs are identical 71 Hands-on: Remote-controlled randomness 72 SAMPLE CODE 72 Example 3-6. Remote-controlled Randomness 72 Figure 3-29. The remote-random sample, step by step 73 Figure 3-30. The state of one qubit in the remote control after the other is READ to be 0. 74 Figure 3-31. The state of one qubit in the remote control after the other is READ to be 1. 74 Conclusions 75 Chapter 4. Quantum Teleportation 76 Hands on: Let’s teleport something 76 Figure 4-1. This chip is very small, so the qubit does not have far to go.1 76 Figure 4-2. The IBM Quantum Experience QASM online editor2 77 SAMPLE CODE 77 Example 4-1. Teleport and verify 77 Figure 4-3. Complete teleportation circut 79 Figure 4-4. Teleportation circut in IBM QX6 79 Figure 4-5. Teleportation success? How can we tell? 80 WARNING 80 Program Step-by-step Walkthrough 80 Figure 4-6. The complete teleport-and-verify program 81 NOTE 81 STEP 1: CREATE AN ENTANGLED PAIR 81 Figure 4-7. Step 1: Create an entangled pair 81 STEP 2: PREPARE THE PAYLOAD 81 Figure 4-8. Step 2: Prepare the payload 82 STEP 3.1: LINK THE PAYLOAD TO THE ENTANGLED PAIR 82 Figure 4-9. Step 3.1: Link the payload to the network 82 STEP 3.2: PUT THE PAYLOAD INTO A SUPERPOSITION 83 Figure 4-10. Step 3.2: Put the payload into a superposition 83 STEP 3.3: READ BOTH SEND QUBITS 83 Figure 4-11. Step 3.3: READ both send qubits 84 STEP 4: RECEIVE AND TRANSFORM 84 Figure 4-12. Step 4: Receive and transform 84 NOTE 85 Figure 4-13. Sometimes, Bob can be the weak link. 85 STEP 5: VERIFY THE RESULT 85 Figure 4-14. Step 5: Verify the result 86 Interpreting the results 86 Figure 4-15. Interpreted teleportation results 87 WARNING 87 Fun with famous teleporter accidents 87 Figure 4-16. Be afraid. Be very afraid. 88 Gate teleportation 88 Quantum Computing in the cloud 88 Figure 4-17. Quantum Computing in the cloud 88 SAMPLE CODE 89 Example 4-2. Quantum Computing in the cloud 89 Teleporting entanglement 90 Figure 4-18. Teleporting entanglement 90 SAMPLE CODE 90 Example 4-3. Teleporting entanglement 90 How is teleportation actually used? 91 About the Authors 93 Programming Quantum Computers......Page 2 Revision History for the Early Release......Page 3 Required background......Page 4 What is a QPU?......Page 5 A Hands-on Approach......Page 6 RUNNING CODE......Page 7 Figure 1-2. The QCEngine UI......Page 8 DEBUGGING CODE......Page 9 Native QPU Instructions......Page 10 Simulator Limitations......Page 18 QPU vs. GPU: Some Common Characteristics......Page 19 How this book is structured......Page 20 Figure 2-1. Possible values of a conventional bit - a graphical representation......Page 22 Size of the circles:......Page 24 WARNING......Page 25 A Quick Look at a Physical Qubit......Page 26 Figure 2-7. A simple implementation of one photonic qubit......Page 27 HANDS-ON......Page 28 QPU Instruction: NOT......Page 29 QPU Instruction: HAD......Page 30 QPU Instruction: READ and WRITE......Page 31 WHAT HAPPENED TO THE PHASE?......Page 32 Figure 2-11. Generating a perfectly random bit with a QPU......Page 33 ABOUT THESE CODE SAMPLES......Page 34 EIGHT SEPARATE QUBITS......Page 35 Figure 2-13. Operation of a PHASE gate......Page 36 Figure 2-15. ROTX and ROTY actions on 0 and 1 input states.......Page 37 Combining QPU operations......Page 38 QPU Combo Instruction: ROOT-of-NOT......Page 39 NOTE......Page 40 Hands-on: Quantum Spy Hunter......Page 41 Example 2-4. Quantum Random Spy Hunter......Page 42 Conclusion......Page 44 Circle notation for multi-qubit registers......Page 46 Figure 3-1. Circle notation for various numbers of multiple qubits......Page 47 TIP......Page 48 Drawing a Multi-Qubit Register......Page 49 Single-qubit Operations in Multi-Qubit Registers......Page 50 Figure 3-6. Single-qubit phase in a multi-qubit register.......Page 51 Visualizing Larger Numbers of Qubits......Page 52 Figure 3-8. Circle notation for larger qubit counts......Page 53 QPU Instruction: CNOT......Page 54 Figure 3-10. CNOT in operation......Page 55 Figure 3-13. Bell Pair step 2......Page 56 TIP......Page 57 Example 3-2. Make a Bell Pair......Page 58 QPU Instruction: CPHASE and CZ......Page 59 Figure 3-16. Applying CPHASE in circle notation......Page 60 Figure 3-18. Circuit for demonstrating phase kickback trick......Page 61 Example 3-3. Phase Kickback......Page 62 Constructing Any Conditional Operation......Page 63 Example 3-4. Custom conditional-phase......Page 64 QPU Instruction: CCNOT (Toffoli)......Page 65 QPU Instruction: SWAP and CSWAP......Page 67 The swap test......Page 68 Example 3-5. The swap test......Page 69 Figure 3-27. How output of swap test varies as input states are made increasingly different......Page 70 Figure 3-28. Number of swap tests that would need to return an outcome of 1 for us to be 99% confident inputs are identical......Page 71 Example 3-6. Remote-controlled Randomness......Page 72 Figure 3-29. The remote-random sample, step by step......Page 73 Figure 3-31. The state of one qubit in the remote control after the other is READ to be 1.......Page 74 Conclusions......Page 75 Figure 4-1. This chip is very small, so the qubit does not have far to go.1......Page 76 Example 4-1. Teleport and verify......Page 77 Figure 4-4. Teleportation circut in IBM QX6......Page 79 Program Step-by-step Walkthrough......Page 80 STEP 2: PREPARE THE PAYLOAD......Page 81 Figure 4-9. Step 3.1: Link the payload to the network......Page 82 STEP 3.3: READ BOTH SEND QUBITS......Page 83 Figure 4-12. Step 4: Receive and transform......Page 84 STEP 5: VERIFY THE RESULT......Page 85 Interpreting the results......Page 86 Fun with famous teleporter accidents......Page 87 Figure 4-17. Quantum Computing in the cloud......Page 88 Example 4-2. Quantum Computing in the cloud......Page 89 Example 4-3. Teleporting entanglement......Page 90 How is teleportation actually used?......Page 91 About the Authors......Page 93 Quantum Computers Are Poised To Kick-start A New Computing Revolution, And You Can Join In Right Away. If You're In Software Engineering, Computer Graphics, Data Science, Or Just An Intrigued Computerphile, This Book Provides A Hands-on Programmer's Guide To Understanding Quantum Computing Technology. Rather Than Labor Through Math And Theory, You'll Work Directly With Examples That Demonstrate This Technology's Unique Capabilities. Quantum Computing Specialists Eric Johnson, Nic Harrigan, And Mercedes Gimeno-segovia Show You How To Build The Skills, Tools, And Intuition Required To Write Quantum Programs At The Center Of Applications. You'll Understand What Quantum Computers Can Do And Learn How To Identify The Types Of Problems They Can Solve. Quantum computers are set to kick-start a second computing revolution in an exciting and intriguing way. Learning to program a Quantum Processing Unit (QPU) is not only fun and exciting, but it's a way to get your foot in the door. Like learning any kind of programming, the best way to proceed is by getting your hands dirty and diving into code.This practical book uses publicly available quantum computing engines, clever notation, and a programmer's mindset to get you started. You'll be able to build up the intuition, skills, and tools needed to start writing quantum programs and solve problems that you care about.
دانلود کتاب Programming Quantum Computers : Essential Algorithms and Code Samples