Book Image

Quantum Computing in Practice with Qiskit® and IBM Quantum Experience®

By : Hassi Norlen
5 (1)
Book Image

Quantum Computing in Practice with Qiskit® and IBM Quantum Experience®

5 (1)
By: Hassi Norlen

Overview of this book

IBM Quantum Experience® is a leading platform for programming quantum computers and implementing quantum solutions directly on the cloud. This book will help you get up to speed with programming quantum computers and provide solutions to the most common problems and challenges. You’ll start with a high-level overview of IBM Quantum Experience® and Qiskit®, where you will perform the installation while writing some basic quantum programs. This introduction puts less emphasis on the theoretical framework and more emphasis on recent developments such as Shor’s algorithm and Grover’s algorithm. Next, you’ll delve into Qiskit®, a quantum information science toolkit, and its constituent packages such as Terra, Aer, Ignis, and Aqua. You’ll cover these packages in detail, exploring their benefits and use cases. Later, you’ll discover various quantum gates that Qiskit® offers and even deconstruct a quantum program with their help, before going on to compare Noisy Intermediate-Scale Quantum (NISQ) and Universal Fault-Tolerant quantum computing using simulators and actual hardware. Finally, you’ll explore quantum algorithms and understand how they differ from classical algorithms, along with learning how to use pre-packaged algorithms in Qiskit® Aqua. By the end of this quantum computing book, you’ll be able to build and execute your own quantum programs using IBM Quantum Experience® and Qiskit® with Python.
Table of Contents (12 chapters)

Installing Qiskit®

With your Python environment prepared and ready to go, and your IBM Quantum Experience® account set up, you can now use pip to install the Qiskit® Python extension. The process should take about 10 minutes or so, after which you can use your Python command line, or your favorite Anaconda Python interpreter to start writing your quantum programs.

Getting ready

This recipe provides information about the generic way to install Qiskit® and does not go into any detail regarding operating system differences or general installation troubleshooting.

For detailed information about the most current requirements for Qiskit® installation, see the Qiskit® requirements page at

How to do it...

  1. Create your Anaconda virtual environment:
    $ conda create -n environment_name python=3

    This will install a set of environment-specific packages.

  2. Activate your virtual environment:
    $ conda activate environment_name
  3. Verify that you are in your virtual environment.

    Your Command Prompt should now include the name of your environment; I used something like this for my own environment with the name packt_qiskit:

    (packt_qiskit) Hassis-Mac:~ hassi$


    In this chapter, I will print out the full prompt like this (environment_name) … $ to remind you that you must execute the commands in the correct environment. In the rest of the book, I will assume that you are indeed in your Qiskit-enabled environment and just show the generic prompt: $.

  4. If needed, do a pip update.

    To install Qiskit®, you must use pip as Qiskit® is not distributed as conda packages. The latest Qiskit® requires pip 19 or newer.

    If you have an older version of pip, you must upgrade using the following command:

    (environment_name) … $  pip  install  -U  pip
  5. Install Qiskit®.

    So, with everything set up and prepared, we can now get on to the main course, installing the Qiskit® code in your environment. Here we go!

    (environment_name) … $  pip install qiskit

    Failed wheel build

    As part of the installation, you might see errors that the wheel failed to build. This error can be ignored.

  6. Use Python to Verify that Qiskit® installed successfully.

    Open Python:

    (environment_name) … $  python3

    Import Qiskit®:

    >>> import qiskit

    This is a little bit exciting; we are going to use Qiskit® code for the first time. Granted, not exactly for programming a quantum computer, but at least to make sure that we are now ready to start programming your quantum programs.

    List the version details:

    >>> qiskit.__qiskit_version__

    This should display the versions of the installed Qiskit® components:

    {'qiskit-terra': '0.15.2', 'qiskit-aer': '0.6.1', 'qiskit-ignis': '0.4.0', 'qiskit-ibmq-provider': '0.9.0', 'qiskit-aqua': '0.7.5', 'qiskit': '0.21.0'}

Congratulations, your Qiskit® installation is complete; you are ready to go!

By using pip install from your virtual environment, you can install Qiskit® in just that environment, which will then stay isolated from the rest of your Python environment.

There's more…

Qiskit® also comes with some optional visualization dependencies to use visualizations across the Qiskit® components. You can install these with the following command:

(environment_name) … $ pip install qiskit[visualization]


If you are using the zsh shell you must enclose the component in quotes:pip install 'qiskit[visualization]'

See also

For a quick introduction to Anaconda environments, see Managing environments in the Anaconda docs:

This book does not, in any way, act as a Qiskit® installation troubleshooting guide, and you might conceivably run into issues when installing it, depending on your local OS, versions, and more.

But fear not, help is on the way. Here are a couple of good and friendly channels on which to reach out for help:

  • Slack:
  • Stack Exchange: