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 your API key and accessing your provider

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.

Getting ready

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).

How to do it...

Let's take a look at how to install the API key locally:

  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, find the Qiskit in local environment section, and click Copy token.
  4. You can now paste your token in a temporary location or keep it in the clipboard.
  5. On your local machine, access your Qiskit® environment. We have done this one, but here's a repeat of the process if you are using Anaconda.
  6. Activate your virtual environment:
    $ conda activate environment_name
  7. Open Python:
    $(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.
    >>> 
  8. Get the required IBMQ class:
    >>> from qiskit import IBMQ		
  9. Install your API token locally:
    >>> 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.

  10. Load your account.

    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.

How it works...

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)

There's more…

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')
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 R$50/month. Cancel anytime