Learn Quantum Computing with Python and Q#
This repository provides sample code for Learn Quantum Computing with Python and Q# (Dr. Sarah Kaiser and Dr. Chris Granade, Manning Publications), available from Manning Publications, Amazon, and a variety of local resellers.
Below, we provide some instructions on getting started with each sample; please see Appendix A for more details.
Getting Started with Code Samples
The samples for Chapters 2 through 6 are written in Python, while the examples in Chapters 7 and later are written in Q# and are called from either Python or by IQ# Notebooks. All samples can be run in one of two ways, depending on your preferences:
- Using conda (a distribution of Python) and the Quantum Development Kit together
- Using Visual Studio Code devcontainers and Docker to manage software installation
The Anaconda distribution of Python 3 provides the conda package manager to help you install and work with software written in Python. You can use conda and the Quantum Development Kit together to run all of the samples in this book.
- Anaconda for Python 3.7, available from https://www.anaconda.com/distribution/.
- The .NET Core SDK 3.0 or later, available from https://dotnet.microsoft.com/download.
Once you have all of the prerequisites installed, you can create a conda environment using the configuration provided in this repository:
conda env create -f environment.yml
This will provide all of the Python software you'll need to get started into a new conda environment called
To use this new environment, run
conda activate qsharp-book.
If you would optionally like to use IQ# from outside of your conda environment, you can use the .NET Core SDK:
dotnet tool install --global Microsoft.Quantum.IQSharp dotnet iqsharp install
This step is not required to use the samples shown in the book.
If you prefer, you can also use Visual Studio Code and Docker together to automatically configure all of the software required for use with the code samples in this book.
- Docker Desktop 2.0 or later (Windows and macOS).
- Docker CE or EE 18.06 or later (Linux).
- Visual Studio Code, available from https://code.visualstudio.com/download, with the Remote Development extension pack.
For more details about how to install and use Docker, check out Docker in Action, 2nd Edition.
Once you have all of the prerequisites installed, open the folder containing these samples in Visual Studio Code. You should then be prompted to reopen the folder in a development container; if not, press Ctrl+Shift+P (Windows and Linux) or ⌘+Shift+P (macOS) to open the command pallet and type "Reopen in Container." This will automatically download and install all software required for use with these samples into a Docker container, and will run Visual Studio Code within that new container.
- When using a devcontainer, the plotting examples in Chapter 8 and 9 can only be run through Jupyter Notebook, not by running
host.pyfrom the command line.
- To run Jupyter Notebook, use
jupyter notebook --ip 0.0.0.0rather than just
jupyter notebook, so as to allow your host operating system to access the Notebook server.