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:
- Log in to IBM Quantum Experience® at https://quantum-computing.ibm.com/login.
- On the IBM Quantum Experience® dashboard, find your user icon in the upper-right corner, click it, and select My account.
- 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...
- Activate your virtual environment:
$ conda activate environment_name
- Run the following command to check for outdated
pip
packages for your virtual environment:(environment_name) … $  pip list --outdated
- 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 …
- It is then a breeze to update Qiskit® using
pip
:(environment_name) … $  pip install qiskit --upgrade
- 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: [email protected] 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: …
- 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!