Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Quantum Computing in Practice with Qiskit® and IBM Quantum Experience®

You're reading from   Quantum Computing in Practice with Qiskit® and IBM Quantum Experience® Practical recipes for quantum computer coding at the gate and algorithm level with Python

Arrow left icon
Product type Paperback
Published in Nov 2020
Publisher Packt
ISBN-13 9781838828448
Length 408 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Hassi Norlen Hassi Norlen
Author Profile Icon Hassi Norlen
Hassi Norlen
Arrow right icon
View More author details
Toc

Table of Contents (12) Chapters Close

Preface 1. Chapter 1: Preparing Your Environment 2. Chapter 2: Quantum Computing and Qubits with Python FREE CHAPTER 3. Chapter 3: IBM Quantum Experience® – Quantum Drag and Drop 4. Chapter 4: Starting at the Ground Level with Terra 5. Chapter 5: Touring the IBM Quantum® Hardware with Qiskit® 6. Chapter 6: Understanding the Qiskit® Gate Library 7. Chapter 7: Simulating Quantum Computers with Aer 8. Chapter 8: Cleaning Up Your Quantum Act with Ignis 9. Chapter 9: Grover's Search Algorithm 10. Chapter 10: Getting to Know Algorithms with Aqua 11. Other Books You May Enjoy

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 https://qiskit.org/documentation/install.html.

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$

    Nomenclature

    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]

Note

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: https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html.

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:

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime