Skip to content

learnqc/code

Repository files navigation

Building Quantum Software: A Developer's Guide

Building Quantum Software: A Developer's Guide will teach you the foundations of quantum computing, how to implement quantum computations, and when to take advantage of the benefits of quantum computing.

This repository is the official companion to Building Quantum Software: A Developer's Guide. It includes the code for creating and running a quantum simulator, as well as a natural language assistant to help run quantum computations, exercises to accompany the book content, and a complete, standalone quantum simulator.

The code uses minimal dependencies to facilitate learning and ensure the longevity of its functionality. The notebooks for each chapter build incrementally on previous chapters, and only use code dependencies within each chapter module.

Hume, our standalone quantum simulator, is the result of piecing together the code throughout the entire book.

Resources

The book and its repository can help you at different levels:

  • Read the book content and the inline code to learn the concepts behind quantum computing.
  • Read or run the Jupyter notebooks in each chapter to interact with the code.
  • Complete the exercises in each chapter to gain intuition and experience in problem-solving in quantum.
  • Implement new experiments in notebooks, unit tests, or more complex applications to use your knowledge to create your own work in quantum.

In addition to the book, there are two more resources available for users:

  • A series of mini applications based on specific topics in the book. These applications feature a simple UI that allows you to experiment with different concepts.
  • An AI assistant that responds to written and spoken commands to run and visualize quantum computations.

These are available in a separate repository: https://github.com/learnqc/code_plus.

Table of Contents

Chapter Code
1. The Advantages and Challenges of Programming Quantum Computers --
2. A first look at quantum computations: the knapsack problem ch02 / notebook
3. Single-qubit state and gates ch03 / notebook / exercises
4. Quantum state and circuits: beyond one qubit ch04 / notebook / exercises
5. Selecting outcomes with quantum oracles ch05 / notebook / exercises
6. Quantum search and probability estimation ch06 / notebook / exercises
7. The quantum Fourier transform ch07 / notebook / exercises
8. Using the quantum Fourier transform ch08 / notebook / exercises
9. Quantum Phase Estimation ch09 / notebook / exercises
10. Encoding functions in quantum states ch10 / notebook / exercises
11. Search-based quantum optimization ch11 / notebook
12. Conclusions and outlook ch12 / notebook

Getting Started

Below you'll find the structure of the repository and instructions for how to get started with using the code.

Overview of contents and structure

├── README.md
├── src                            # notebooks are designed to run from the src directory
│   ├── chXX
│   │   ├── chXX.ipynb             # notebook with chapter code that can be used for experimentation
│   │   ├── chXX_exercises.ipynb   # notebook with chapter exercises and solutions
│   │   └── x.py                   # the source code introduced in each chapter
│   ├── hume                       # the complete quantum simulator implemented over the course of the book
│   ├── ibmq                       # real quantum hardware experiments using IBMQ Quantum Platform Open Plan
│   ├── ...

Setting up the code

Clone repository

Start by cloning the repository:

 git clone https://github.com/learnqc/code

Runing the notebooks with Docker

Navigate to the project root directory:

cd code

Build the image for the Jupyter Notebook server:

docker-compose build

Start the Jupyter Notebook server:

docker-compose up

After running this command, the Jupyter Notebook server should be accessible at http://localhost:8888 in your browser, Jupyter token is token

Using GitHub Code Spaces or Dev Containers VSCode pluging

This setup can also be used with GitHub Code Spaces. All the necessary configuration is provided in the devcontainer.json file. Just open this repository in a new code space, and the environment will be ready to go.

Code Setup

  1. Next, create a virtual environment where you can run the code.
python -m venv bqs-env
  1. Activate the new environment.
source bqs-env/bin/activate
  1. Install the dependencies for the repository in the virtual environment.
pip install -r requirements.txt

Notebooks

The notebooks included in the repository contain the code for each chapter as well as accompanying exercises. You can read through the notebooks to learn how to code for different tasks, or you can edit them and experiment with how changing the code impacts the different computations being run. All exercise notebooks include answers and explanations to help you continue to build your intuition with the material.

Hume

Hume is a standalone quantum simulator constructed in a couple of hundred lines of code. It can be translated directly to Qiskit and most of its syntax matches Qiskit, and (which can then be run on a real quantum computer). Because Hume allows the use of classical methods, running it can be more efficient than a purely gate-based simulator. For a high-performance version of Hume implemented in Rust, check out this repository!

Tests can be run with pytest from the src directory. For example:

python -m pytest hume --no-header  -qs

Or a more specific test file:

python -m pytest hume/tests/test_unitary.py --no-header  -qs

Or a more specific test:

python -m pytest hume/tests/test_util_qiskit.py::test_same_as_qiskit --no-header --no-summary -qs

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published