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

Keeping your Qiskit® environment up to date

Qiskit® is an open source programming environment that is in continuous flux. Over the course of writing this book, I have passed through many minor and major version updates of the software.

It is generally a good idea to stay updated with the latest version, but with some updates, components of the code might change behavior. It is always a good idea to have a good look at the release notes for each new version. Sometimes changes are introduced that will change the way your code behaves. In those cases, you might want to hold off on upgrading until you have verified that your code still works as expected.

If you are using Anaconda environments, then you can maintain more than one environment at different Qiskit® levels, to have a fallback environment in case an upgraded Qiskit® version breaks your code.

Qiskit® moves fast

The IBM Quantum Experience® Notebook environment always runs the latest version of Qiskit®, and it might be a good idea to test drive your code in that environment before you upgrade your local environment.

You can also subscribe to notification updates, to find out when a new release has been offered:

  1. Log in to IBM Quantum Experience® at https://quantum-computing.ibm.com/login.
  2. On the IBM Quantum Experience® dashboard, find your user icon in the upper-right corner, click it, and select My account.
  3. On the account page, under Notification settings, set Updates and new feature announcements to On.

Getting ready

Before you begin, verify which version of Qiskit® you are running for each of your environments (if you have more than one).

For each environment, launch Python, either from the command line, from an IDE such as Spyder, or as a Jupyter notebook, then execute the following code:

>>> import qiskit
>>> qiskit.__qiskit_version__

If you have an old version of Qiskit® installed, the preceding code might result in the following output:

{'qiskit-terra': '0.9.0', 'qiskit-aer': '0.3.0', 'qiskit-ibmq-provider': '0.3.0', 'qiskit-aqua': '0.6.0', 'qiskit': '0.12.0'}

You can then go to the Qiskit® release notes to find out if there is a more up-to-date version available: https://qiskit.org/documentation/release_notes.html

This is a lot of steps just to make sure. The whole process is automated in Python. To go down that path, go to the next section.

How to do it...

  1. Activate your virtual environment:
    $ conda activate environment_name
  2. Run the following command to check for outdated pip packages for your virtual environment:
    (environment_name) … $  pip list --outdated
  3. This will return a list of all your pip packages that are currently outdated and list the available versions:
    Example:Package                  Version  Latest   Type 
    ------------------------ -------- -------- -----
    …
    qiskit                   0.19.6   0.21.0   sdist
    qiskit-aer               0.5.2    0.6.1    wheel
    qiskit-aqua              0.7.3    0.7.5    wheel
    qiskit-ibmq-provider     0.7.2    0.9.0    wheel
    qiskit-ignis             0.3.3    0.4.0    wheel
    qiskit-terra             0.14.2   0.15.1   wheel 
    …
  4. It is then a breeze to update Qiskit® using pip:
    (environment_name) … $  pip install qiskit --upgrade
  5. From the command line, verify that Qiskit® is installed:
    (environment_name)… $ pip show qiskit

    This will result in an output similar to the following:

    Name: qiskit
    Version: 0.21.0
    Summary: Software for developing quantum computing programs
    Home-page: https://github.com/Qiskit/qiskit
    Author: Qiskit Development Team
    Author-email: qiskit@us.ibm.com
    License: Apache 2.0
    Location: /Users/hassi/opt/anaconda3/envs/packt_qiskit/lib/python3.7/site-packages
    Requires: qiskit-aer, qiskit-terra, qiskit-aqua, qiskit-ignis, qiskit-ibmq-provider
    Required-by: 
    …
  6. Verify that Qiskit® is integrated with Python in your isolated environment.

    Open Python:

    (environment_name)… $ python3

    Import Qiskit®:

    >>> import qiskit

    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® upgrade worked; you are now running the latest code!

How it works...

Depending on how you consume this book, you might be looking over this process as part of your first read-through, and no upgrades were available. If so, go ahead and bookmark this recipe, and come back to it at a later time when there has been a Qiskit® upgrade.

The pip tool will manage your upgrade for you for each virtual environment. As I mentioned before, it might be a good idea to do a staged upgrade of your environments if you have more than one.

For example, you can upgrade one environment and test run your quantum programs in that environment to make sure that the new version did not break anything in your code.

OK, with this you should be reasonably set with one or more Qiskit® environments on which to run your quantum programs. If you feel ready for it, you can now take the plunge and go directly to Chapter 4, Starting at the Ground Level with Terra, to start writing quantum programs in Python using Qiskit®. If you are up for some prep work to get a feel for what programming a quantum computer is all about, start with Chapter 2, Quantum Computing and Qubits with Python, to get an introduction to qubits and gates, or Chapter 3, IBM Quantum Experience® – Quantum Drag and Drop, to get a visual feel for quantum programs by using the IBM Quantum Experience® drag-and-drop programming interface.

No matter which path you take, don't worry, we'll let Python do the hard work. Again, have fun!

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 $19.99/month. Cancel anytime