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

Now that you have installed Qiskit®, you can immediately start creating your quantum programs and run these on local simulators. If, however, at some point, you want to run your quantum code on actual IBM Quantum® hardware, you must install your own unique API key locally.
API keys on IBM Quantum Experience®
If you are running your Qiskit® programs in the IBM Quantum Experience® notebook environment, your API key is automatically registered.
Before you can install your API key, you must first have an IBM Quantum Experience® account. If you have not yet created one, go back and do it (see the Creating your IBM Quantum Experience® account section).
Let's take a look at how to install the API key locally:
$ conda activate environment_name
$(environment_name) … $ python3
Verify that the Python header displays and that you are running the correct version of Python:
Python 3.7.6 (default, Jan 8 2020, 13:42:34) [Clang 4.0.1 (tags/RELEASE_401/final)] :: Anaconda, Inc. on darwin Type "help", "copyright", "credits" or "license" for more information. >>>
IBMQ
class:>>> from qiskit import IBMQ
>>> IBMQ.save_account('MY_API_TOKEN')
Here, instead of MY_API_TOKEN
, paste in the API token that you just copied from IBM Quantum Experience®: Keep the single quotes as they are required for the command.
Now that the token is in place, let's verify that all is in order and that your account has the correct privileges:
>>> IBMQ.load_account()
This should display the following output:
<AccountProvider for IBMQ(hub='ibm-q', group='open', project='main')>
This is the provider information for your account, with hub
, group
, and project
.
The main class that you import for this exercise is IBMQ
, which is a toolbox for working with the quantum hardware and software that is provided by IBM in the cloud.
In this chapter, we used save.account()
to store your account locally. As we go forward, in the recipes where we will access the IBM Quantum® machines, we will use the IBMQ.load_account()
and IBMQ.get_provider()
classes in your quantum programs to make sure that you have the correct access.
Updating your API key
If for some reason, you need to create a new API token on IBM Quantum Experience® and update your locally saved token, you can use the following command:
>>> IBMQ.save_account('NEW_API_TOKEN', overwrite=True)
In the code that follows in the recipes in this cookbook, we will set a provider
variable to hold the provider information for your account by using the following command:
>>> provider = IBMQ.get_provider()
We can then use the provider
information when selecting the IBM Quantum® computer, or backend, to run your quantum programs on. In the following example, we select a quantum computer that is called IBM Q 5 Yorktown (ibmqx2
) as our backend. The internal reference for this machine is ibmqx2
:
>>> backend = provider.get_backend('ibmqx2')