Learn Quantum Computing with Python and Q#

Book description

Learn Quantum Computing with Python and Q# demystifies quantum computing. Using Python and the new quantum programming language Q#, you’ll build your own quantum simulator and apply quantum programming techniques to real-world examples including cryptography and chemical analysis.

About the Technology
Quantum computers present a radical leap in speed and computing power. Improved scientific simulations and new frontiers in cryptography that are impossible with classical computing may soon be in reach. Microsoft’s Quantum Development Kit and the Q# language give you the tools to experiment with quantum computing without knowing advanced math or theoretical physics.

About the Book
Learn Quantum Computing with Python and Q# introduces quantum computing from a practical perspective. Use Python to build your own quantum simulator and take advantage of Microsoft’s open source tools to fine-tune quantum algorithms. The authors explain complex math and theory through stories, visuals, and games. You’ll learn to apply quantum to real-world applications, such as sending secret messages and solving chemistry problems.

What's Inside
  • The underlying mechanics of quantum computers
  • Simulating qubits in Python
  • Exploring quantum algorithms with Q#
  • Applying quantum computing to chemistry, arithmetic, and data


About the Reader
For software developers. No prior experience with quantum computing required.

About the Authors
Dr. Sarah Kaiser works at the Unitary Fund, a non-profit organization supporting the quantum open-source ecosystem, and is an expert in building quantum tech in the lab. Dr. Cassandra Granade works in the Quantum Systems group at Microsoft, and is an expert in characterizing quantum devices.

Quotes
Quantum computing is the next big thing and it’s happening now. You will need this book to get ahead of the game.
- Clive Harber, Distorted Thinking Ltd.

An excellent introductory book on quantum computing.
- Dimitri Denisjonok, Fyld

A hands-on guide to learning about quantum computing that will have you up and running in no time.
- Thomas Heiman, TechnoGems

A great introduction to quantum computing with great applications!
- William E. Wheeler, TekSystems

Publisher resources

View/Submit Errata

Table of contents

  1. inside front cover
  2. Learn Quantum Computing with Python and Q#
  3. Copyright
  4. dedication
  5. contents
  6. front matter
    1. foreword
    2. preface
    3. acknowledgments
    4. about this book
      1. Who should read this book
      2. How this book is organized: A roadmap
      3. About the code
      4. liveBook discussion forum
      5. Other online resources
      6. Going further
    5. about the authors
    6. about the cover illustration
  7. Part 1. Getting started with quantum
  8. 1 Introducing quantum computing
    1. 1.1 Why does quantum computing matter?
    2. 1.2 What is a quantum computer?
    3. 1.3 How will we use quantum computers?
      1. 1.3.1 What can quantum computers do?
      2. 1.3.2 What can’t quantum computers do?
    4. 1.4 What is a program?
      1. 1.4.1 What is a quantum program?
    5. Summary
  9. 2 Qubits: The building blocks
    1. 2.1 Why do we need random numbers?
    2. 2.2 What are classical bits?
      1. 2.2.1 What can we do with classical bits?
      2. 2.2.2 Abstractions are our friend
    3. 2.3 Qubits: States and operations
      1. 2.3.1 State of the qubit
      2. 2.3.2 The game of operations
      3. 2.3.3 Measuring qubits
      4. 2.3.4 Generalizing measurement: Basis independence
      5. 2.3.5 Simulating qubits in code
    4. 2.4 Programming a working QRNG
    5. Summary
  10. 3 Sharing secrets with quantum key distribution
    1. 3.1 All’s fair in love and encryption
      1. 3.1.1 Quantum NOT operations
      2. 3.1.2 Sharing classical bits with qubits
    2. 3.2 A tale of two bases
    3. 3.3 Quantum key distribution: BB84
    4. 3.4 Using a secret key to send secret messages
    5. Summary
  11. 4 Nonlocal games: Working with multiple qubits
    1. 4.1 Nonlocal games
      1. 4.1.1 What are nonlocal games?
      2. 4.1.2 Testing quantum physics: The CHSH game
      3. 4.1.3 Classical strategy
    2. 4.2 Working with multiple qubit states
      1. 4.2.1 Registers
      2. 4.2.2 Why is it hard to simulate quantum computers?
      3. 4.2.3 Tensor products for state preparation
      4. 4.2.4 Tensor products for qubit operations on registers
    3. Summary
  12. 5 Nonlocal games: Implementing a multi-qubit simulator
    1. 5.1 Quantum objects in QuTiP
      1. 5.1.1 Upgrading the simulator
      2. 5.1.2 Measuring up: How can we measure multiple qubits?
    2. 5.2 CHSH: Quantum strategy
    3. Summary
  13. 6 Teleportation and entanglement: Moving quantum data around
    1. 6.1 Moving quantum data
      1. 6.1.1 Swapping out the simulator
      2. 6.1.2 What other two-qubit gates are there?
    2. 6.2 All the single (qubit) rotations
      1. 6.2.1 Relating rotations to coordinates: The Pauli operations
    3. 6.3 Teleportation
    4. Summary
    5. Part 1: Conclusion
  14. Part 2. Programming quantum algorithms in Q#
  15. 7 Changing the odds: An introduction to Q#
    1. 7.1 Introducing the Quantum Development Kit
    2. 7.2 Functions and operations in Q#
      1. 7.2.1 Playing games with quantum random number generators in Q#
    3. 7.3 Passing operations as arguments
    4. 7.4 Playing Morgana’s game in Q#
    5. Summary
  16. 8 What is a quantum algorithm?
    1. 8.1 Classical and quantum algorithms
    2. 8.2 Deutsch–Jozsa algorithm: Moderate improvements for searching
      1. 8.2.1 Lady of the (quantum) Lake
    3. 8.3 Oracles: Representing classical functions in quantum algorithms
      1. 8.3.1 Merlin’s transformations
      2. 8.3.2 Generalizing our results
    4. 8.4 Simulating the Deutsch–Jozsa algorithm in Q#
    5. 8.5 Reflecting on quantum algorithm techniques
      1. 8.5.1 Shoes and socks: Applying and undoing quantum operations
      2. 8.5.2 Using Hadamard instructions to flip control and target
    6. 8.6 Phase kickback: The key to our success
    7. Summary
  17. 9 Quantum sensing: It’s not just a phase
    1. 9.1 Phase estimation: Using useful properties of qubits for measurement
      1. 9.1.1 Part and partial application
    2. 9.2 User-defined types
    3. 9.3 Run, snake, run: Running Q# from Python
    4. 9.4 Eigenstates and local phases
    5. 9.5 Controlled application: Turning global phases into local phases
      1. 9.5.1 Controlling any operation
    6. 9.6 Implementing Lancelot’s best strategy for the phase-estimation game
    7. Summary
    8. Part 2: Conclusion
  18. Part 3. Applied quantum computing
  19. 10 Solving chemistry problems with quantum computers
    1. 10.1 Real chemistry applications for quantum computing
    2. 10.2 Many paths lead to quantum mechanics
    3. 10.3 Using Hamiltonians to describe how quantum systems evolve in time
    4. 10.4 Rotating around arbitrary axes with Pauli operations
    5. 10.5 Making the change we want to see in the system
    6. 10.6 Going through (very small) changes
    7. 10.7 Putting it all together
    8. Summary
  20. 11 Searching with quantum computers
    1. 11.1 Searching unstructured data
    2. 11.2 Reflecting about states
      1. 11.2.1 Reflection about the all-ones state
      2. 11.2.2 Reflection about an arbitrary state
    3. 11.3 Implementing Grover’s search algorithm
    4. 11.4 Resource estimation
    5. Summary
  21. 12 Arithmetic with quantum computers
    1. 12.1 Factoring quantum computing into security
    2. 12.2 Connecting modular math to factoring
      1. 12.2.1 Example of factoring with Shor’s algorithm
    3. 12.3 Classical algebra and factoring
    4. 12.4 Quantum arithmetic
      1. 12.4.1 Adding with qubits
      2. 12.4.2 Multiplying with qubits in superposition
      3. 12.4.3 Modular multiplication in Shor’s algorithm
    5. 12.5 Putting it all together
    6. Summary
    7. Wrapping up
  22. appendix A. Installing required software
    1. A.1 Running samples online
      1. A.1.1 Using Binder
      2. A.1.2 Using GitHub Codespaces
    2. A.2 Installing locally using Anaconda
      1. A.2.1 Installing Anaconda
      2. A.2.2 Installing packages with Anaconda
    3. A.3 Installing the Quantum Development Kit
      1. A.3.1 Installing the .NET Core SDK
      2. A.3.2 Installing the project templates
      3. A.3.3 Installing the Visual Studio Code extension
      4. A.3.4 Installing IQ# for Jupyter Notebook
  23. appendix B. Glossary and quick reference
    1. B.1 Glossary
    2. B.2 Dirac notation
    3. B.3 Quantum operations
    4. B.4 Q# Language
      1. B.4.1 Types
      2. B.4.2 Q# declarations and statements
      3. B.4.3 Q# expressions and operators
      4. B.4.4 Q# standard libraries
      5. B.4.5 IQ# magic commands
  24. appendix C. Linear algebra refresher
    1. C.1 Approaching vectors
    2. C.2 Seeing the matrix for ourselves
      1. C.2.1 Party with inner products
  25. appendix D. Exploring the Deutsch–Jozsa algorithm by example
    1. D.1 Using our skills to try things
    2. D.2 Step 1: Preparing the input state for Deutsch–Jozsa
    3. D.3 Step 2: Applying the oracle
      1. D.3.1 Example 1: The “id” oracle
      2. D.3.2 Example 2: The “not” oracle
      3. D.3.3 Example 3: The “zero” oracle
    4. D.4 Steps 3 and 4: Undo the preparation on the target qubit, and measure
  26. index

Product information

  • Title: Learn Quantum Computing with Python and Q#
  • Author(s): Cassandra Granade, Sarah Kaiser
  • Release date: July 2021
  • Publisher(s): Manning Publications
  • ISBN: 9781617296130