Programming Quantum Computers

Book Description

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.

Table of Contents

  1. Preface
    1. How This Book Is Structured
    2. Conventions Used in This Book
    3. Using Code Examples
    4. O’Reilly Online Learning
    5. How to Contact Us
    6. Acknowledgments
  2. 1. Introduction
    1. Required Background
    2. What Is a QPU?
    3. A Hands-on Approach
      1. A QCEngine Primer
    4. Native QPU Instructions
      1. Simulator Limitations
      2. Hardware Limitations
    5. QPU Versus GPU: Some Common Characteristics
  3. I. Programming for a QPU
  4. 2. One Qubit
    1. A Quick Look at a Physical Qubit
    2. Introducing Circle Notation
      1. Circle Size
      2. Circle Rotation
    3. The First Few QPU Operations
      1. QPU Instruction: NOT
      2. QPU Instruction: HAD
      3. QPU Instruction: READ
      4. QPU Instruction: WRITE
      5. Hands-on: A Perfectly Random Bit
      6. QPU Instruction: PHASE(θ)
      7. QPU Instructions: ROTX(θ) and ROTY(θ)
    4. COPY: The Missing Operation
    5. Combining QPU Operations
      1. QPU Instruction: ROOT-of-NOT
    6. Hands-on: Quantum Spy Hunter
    7. Conclusion
  5. 3. Multiple Qubits
    1. Circle Notation for Multi-Qubit Registers
    2. Drawing a Multi-Qubit Register
    3. Single-Qubit Operations in Multi-Qubit Registers
      1. Reading a Qubit in a Multi-Qubit Register
    4. Visualizing Larger Numbers of Qubits
    5. QPU Instruction: CNOT
    6. Hands-on: Using Bell Pairs for Shared Randomness
    7. QPU Instructions: CPHASE and CZ
      1. QPU Trick: Phase Kickback
    8. QPU Instruction: CCNOT (Toffoli)
    9. QPU Instructions: SWAP and CSWAP
      1. The Swap Test
    10. Constructing Any Conditional Operation
    11. Hands-on: Remote-Controlled Randomness
    12. Conclusion
  6. 4. Quantum Teleportation
    1. Hands-on: Let’s Teleport Something
    2. Program Walkthrough
      1. Step 1: Create an Entangled Pair
      2. Step 2: Prepare the Payload
      3. Step 3.1: Link the Payload to the Entangled Pair
      4. Step 3.2: Put the Payload into a Superposition
      5. Step 3.3: READ Both of Alice’s Qubits
      6. Step 4: Receive and Transform
      7. Step 5: Verify the Result
    3. Interpreting the Results
    4. How Is Teleportation Actually Used?
    5. Fun with Famous Teleporter Accidents
  7. II. QPU Primitives
  8. 5. Quantum Arithmetic and Logic
    1. Strangely Different
    2. Arithmetic on a QPU
      1. Hands-on: Building Increment and Decrement Operators
    3. Adding Two Quantum Integers
    4. Negative Integers
    5. Hands-on: More Complicated Math
    6. Getting Really Quantum
      1. Quantum-Conditional Execution
      2. Phase-Encoded Results
    7. Reversibility and Scratch Qubits
    8. Uncomputing
    9. Mapping Boolean Logic to QPU Operations
      1. Basic Quantum Logic
    10. Conclusion
  9. 6. Amplitude Amplification
    1. Hands-on: Converting Between Phase and Magnitude
    2. The Amplitude Amplification Iteration
    3. More Iterations?
    4. Multiple Flipped Entries
    5. Using Amplitude Amplification
      1. AA and QFT as Sum Estimation
      2. Speeding Up Conventional Algorithms with AA
    6. Inside the QPU
      1. The Intuition
    7. Conclusion
  10. 7. QFT: Quantum Fourier Transform
    1. Hidden Patterns
    2. The QFT, DFT, and FFT
    3. Frequencies in a QPU Register
    4. The DFT
      1. Real and Complex DFT Inputs
      2. DFT Everything
    5. Using the QFT
      1. The QFT Is Fast
    6. Inside the QPU
      1. The Intuition
      2. Operation by Operation
    7. Conclusion
  11. 8. Quantum Phase Estimation
    1. Learning About QPU Operations
    2. Eigenphases Teach Us Something Useful
    3. What Phase Estimation Does
    4. How to Use Phase Estimation
      1. Inputs
      2. Outputs
    5. The Fine Print
      1. Choosing the Size of the Output Register
      2. Complexity
      3. Conditional Operations
    6. Phase Estimation in Practice
    7. Inside the QPU
      1. The Intuition
      2. Operation by Operation
    8. Conclusion
  12. III. QPU Applications
  13. 9. Real Data
    1. Noninteger Data
    2. QRAM
    3. Vector Encodings
      1. Limitations of Amplitude Encoding
      2. Amplitude Encoding and Circle Notation
    4. Matrix Encodings
      1. How Can a QPU Operation Represent a Matrix?
      2. Quantum Simulation
  14. 10. Quantum Search
    1. Phase Logic
      1. Building Elementary Phase-Logic Operations
      2. Building Complex Phase-Logic Statements
    2. Solving Logic Puzzles
      1. Of Kittens and Tigers
    3. General Recipe for Solving Boolean Satisfiability Problems
      1. Hands-on: A Satisfiable 3-SAT Problem
      2. Hands-on: An Unsatisfiable 3-SAT Problem
    4. Speeding Up Conventional Algorithms
  15. 11. Quantum Supersampling
    1. What Can a QPU Do for Computer Graphics?
    2. Conventional Supersampling
    3. Hands-on: Computing Phase-Encoded Images
      1. A QPU Pixel Shader
      2. Using PHASE to Draw
      3. Drawing Curves
    4. Sampling Phase-Encoded Images
    5. A More Interesting Image
    6. Supersampling
    7. QSS Versus Conventional Monte Carlo Sampling
      1. How QSS Works
    8. Adding Color
    9. Conclusion
  16. 12. Shor’s Factoring Algorithm
    1. Hands-on: Using Shor on a QPU
    2. What Shor’s Algorithm Does
      1. Do We Need a QPU at All?
      2. The Quantum Approach
    3. Step by Step: Factoring the Number 15
      1. Step 1: Initialize QPU Registers
      2. Step 2: Expand into Quantum Superposition
      3. Step 3: Conditional Multiply-by-2
      4. Step 4: Conditional Multipy-by-4
      5. Step 5: Quantum Fourier Transform
      6. Step 6: Read the Quantum Result
      7. Step 7: Digital Logic
      8. Step 8: Check the Result
    4. The Fine Print
      1. Computing the Modulus
      2. Time Versus Space
      3. Coprimes Other Than 2
  17. 13. Quantum Machine Learning
    1. Solving Systems of Linear Equations
      1. Describing and Solving Systems of Linear Equations
      2. Solving Linear Equations with a QPU
    2. Quantum Principle Component Analysis
      1. Conventional Principal Component Analysis
      2. PCA with a QPU
    3. Quantum Support Vector Machines
      1. Conventional Support Vector Machines
      2. SVM with a QPU
    4. Other Machine Learning Applications
  18. IV. Outlook
  19. 14. Staying on Top: A Guide to the Literature
    1. From Circle Notation to Complex Vectors
    2. Some Subtleties and Notes on Terminology
    3. Measurement Basis
    4. Gate Decompositions and Compilation
    5. Gate Teleportation
    6. QPU Hall of Fame
    7. The Race: Quantum Versus Conventional Computers
    8. A Note on Oracle-Based Algorithms
      1. Deutsch-Jozsa
      2. Bernstein-Vazirani
      3. Simon
    9. Quantum Programming Languages
    10. The Promise of Quantum Simulation
    11. Error Correction and NISQ Devices
    12. Where Next?
      1. Books
      2. Lecture Notes
      3. Online Resources
  20. Index

Product Information

  • Title: Programming Quantum Computers
  • Author(s): Eric R. Johnston, Nic Harrigan, Mercedes Gimeno-Segovia
  • Release date: July 2019
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9781492039686