29,99 €
The IBM Quantum Platform was built to enable developers to learn the basics of quantum computing by providing access to high performant quantum computers and provide documentation and courses to help get up to speed with the latest features in quantum computing.
Updated with new examples and changes to the platform, this edition begins with an introduction to the IBM Quantum Platform and the Quantum Information Science Kit (Qiskit) SDK. You will become well versed in the IBM Quantum Composer interface as well as running your quantum circuits on a real quantum computer. Along the way, you’ll learn some of the fundamental principles regarding quantum mechanics, qubits, quantum gates, quantum circuits, and the error mitigation techniques that are used to perform operations on qubits.
As you build on your knowledge, you’ll understand the functionality of IBM Qiskit and the developer-focused resources so you can create your own quantum algorithms. You’ll learn how to monitor and optimize your quantum circuits. Lastly, you’ll look at the fundamental quantum algorithms and understand how they can be applied effectively.
By the end of this quantum computing book, you'll know how to build quantum algorithms and will have gained a practical understanding of quantum computation that you can apply to your research or business.
Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:
Seitenzahl: 511
Veröffentlichungsjahr: 2025
Learn Quantum Computing with Python and IBM Quantum
Second Edition
Write your own practical quantum programs with Python
Robert Loredo
Learn Quantum Computing with Python and IBM Quantum
Second Edition
Copyright © 2024 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
Senior Publishing Product Manager: Denim Pinto
Acquisition Editor – Peer Reviews: Saby Dsilva
Project Editor: Namrata Katare
Senior Development Editor: Elliot Dallow
Copy Editor: Safis Editing
Technical Editor: Simanta Rajbangshi
Proofreader: Safis Editing
Indexer: Pratik Shirodkar
Presentation Designer: Ajay Patule
Developer Relations Marketing Executive: Vidhi Vashisth
First published: September 2020
Second edition: January 2025
Production reference: 1280125
Published by Packt Publishing Ltd.
Grosvenor House
11 St Paul’s Square
Birmingham
B3 1RB, UK.
ISBN 978-1-80324-480-8
www.packt.com
Robert Loredo is the IBM Quantum Ambassador worldwide lead, a Qiskit Advocate, and a Master Inventor with over 20 years of experience in the technical industry. He is a prolific inventor holding over 250 patents in areas such as: AI, life sciences, and quantum. He taught computer and software engineering at Florida International University and holds both a Bachelors and Masters degree in computer and electrical engineering from the University of Miami. As a philanthropist, he donated the royalties from his previous book to the charity Doctors without Borders.
I would like to thank the following people for their guidance, expertise, and motivational support: Arvind Krishna, Dario Gil, Jay Gambetta, Scott Crowder, Steffen Thoss, Katie Pizzolato, Blake Johnson, Tammy Cornell, Birgit Schwarz, Bob Sutor, Denise Ruffner, Brian Ingmanson, Charles Robinson, Chris Nay, Dan Maynard, Edward Van Halen, Enrique Vargas, Gabe Chang, Hanhee Paik, James Weaver, Jerry Chow, John Buselli, Julian Tan, Kenneth Wood, M. Lewis Temares, Mark Ritter, Matthew Broomhall, Matthias Steffen, Michele Grossi, Mohammed Abdel-Mottaleb, Nick Bronn, Olivia Lanes, Paul Bastide, Pete Martinez, Petra Florizoone, Voica Radescu, Vishal Bajpe, and Zaira Nazario for their continued support.
Hassi Norlén is a client engagement leader with IBM Innovation Studio. He is also an IBM quantum technical ambassador and Qiskit advocate and has been at IBM for 18 years. He holds an MSc. in physics from Uppsala University, Sweden. He has worked as a science journalist, astronomy teacher, software developer, content designer, and an engagement leader in various places around the world. Since becoming an IBM quantum technical ambassador and Qiskit advocate he has reconnected with his physics roots and has first-hand insights into the rapidly evolving field of quantum computing, and specifically Qiskit/IBM Quantum.
He is the author of Quantum Computing in Practice with IBM Quantum Experience, and has also written about exploring quantum computing on non-standard platforms in Qrasp - Quantum on a Raspberry Pi on Medium.
Michele Grossi is a senior fellow in quantum computing at CERN. He received his industrial PhD in High Energy Physics from the University of Pavia while working at IBM. Michele has worked as as a quantum technical ambassador at IBM and a hybrid cloud solutions architect, and in his current role he co-supervises quantum machine learning projects within the CERN Quantum Technology Initiative. His focus is the development of QML pipelines for high-energy physics problems with possible extensions to different fields. He is a co-author of several scientific publications, a conference speaker, and a lecturer at various universities. In 2019, Forbes selected Michele as one of the top 30 under 30 young Italian leaders in enterprise technology.
Sean Wagner is a research scientist, Quantum Technical Ambassador, and Accelerated Discovery Ambassador at IBM Canada. As a member of the IBM Canada National Innovation Team, Sean works with researchers at academic institutions and industry partners in Canada, from start-ups to large companies. The projects involve high-performance computing, computer architecture, data science, and artificial intelligence applied to numerous scientific and business domains. His most recent work focuses on hardware acceleration, particularly for deep neural networks, and software tools for machine learning. As a member of the IBM Quantum team, Sean is an advocate for and conducts workshops on quantum computing. He earned a BASc. in Computer Engineering from the University of Waterloo in 2003, and completed MASc. and PhD. degrees in electrical and computer engineering at the University of Toronto in 2006 and 2011, respectively.
Voica Radescu holds a PhD in particle physics from the University of Pittsburgh, PA USA. She currently works as the quantum alliances leader in Europe for IBM, where she is committed to enabling quantum partners to achieve success. Before joining IBM in 2017, Voica worked as a high energy physics researcher at top institutions in Europe, such as DESY, CERN, and the University of Oxford.
Join our community’s Discord space for discussions with the author and other readers:
https://packt.link/3FyN1
Contributors
Join us on Discord
Preface
Who this book is for
What this book covers
To get the most out of this book
Get in touch
Leave a Review!
Exploring the IBM Quantum Tools
Technical requirements
Getting started with the IBM Quantum Platform
Registering to the IBM Quantum Platform
Understanding the Manage account settings view
Getting familiar with the Compute resources view
Learning about pending and latest jobs
Using the Documentation to quickly start up
Understanding the IBM Quantum tools
Summary
Questions
Join us on Discord
Creating Quantum Circuits with IBM Quantum Composer
Technical requirements
Getting started with the IBM Quantum Composer
Launching the Composer
Familiarizing yourself with the Composer components
Understanding the Composer
Customizing your views
Creating a quantum circuit with the Quantum Composer
Building a quantum circuit with classical bit behaviors
Reviewing your results
Summary
Questions
Join us on Discord
Introducing and Installing Qiskit
Technical requirements
Understanding quantum and classical system interconnections
Reviewing the Qiskit library
Understanding how to organize and interact with Qiskit
Understanding Qiskit APIs
Aer
The Aer simulator
The Qasm simulator
Statevector simulator
The Unitary simulator
Installing and configuring Qiskit on your local machine
Preparing the installation
Installing Anaconda
Installing Qiskit
Configuring your local Qiskit environment
Getting support from the Qiskit community
Introducing the Qiskit community
Contributing to the Qiskit community
Specializing your skill set in the Qiskit community
Summary
Questions
Join us on Discord
Understanding Basic Quantum Computing Principles
Technical requirements
Introducing quantum computing
Understanding superposition
Learning about classical randomness
Preparing a qubit in a superposition state
Building a coin-flipping experiment
Understanding entanglement
Implementing the behavior of entangled qubits
Entangling two coins together
Understanding interference
Exploring the Bell states
Preparing the Bell states
Implementing the Bell states
Summary
Questions
Join us on Discord
Understanding the Qubit
Technical requirements
Comparing classical and quantum bits
Reviewing the classical bit
Understanding the qubit
Visualizing the state vector of a qubit
Visualizing the representation of a qubit
Visualizing the state vectors of multiple qubits
Implementing qubits on a superconducting system
Summary
Questions
Join us on Discord
Understanding Quantum Logic Gates
Technical requirements
Reviewing classical logic gates
Understanding quantum unitary operators
Understanding single-qubit gates
Hadamard (H) gate
Pauli gates
Identity (I) Pauli gate
NOT (X) Pauli gate
Y Pauli gate
Z gate
Phase gates
S gate
S† (dagger) gate
T gate
T† (dagger) gate
Rx gate
Universal U gate
Understanding multi-qubit gates
CNOT two-qubit gate
Toffoli multi-qubit gate
Swap gate
Understanding the measurement operator
Summary
Questions
Join us on Discord
Programming with Qiskit
Technical requirements
Customizing and optimizing quantum circuits
Components of a quantum circuit
Obtaining circuit properties and analysis
Customizing and parameterizing circuit libraries
Generating pulse schedules on hardware
Learning about instructions
Understanding pulses and Pulse libraries
Leveraging channels to transmit and receive instructions
Generating and executing schedules
Understanding the Job component
Summary
Questions
Join us on Discord
Optimizing and Visualizing Quantum Circuits
Technical requirements
Optimizing circuits using Preset Passmanager
Transpiling a quantum circuit
Generating preset passmanagers
Comparing circuit mappings on different backend devices
Understanding passes and pass managers
Learning about the Layout Selection type
Leveraging the pass manager
Visualizing and enhancing circuit graphs
Learning about customized visual circuits
Drawing the directed acyclic graph of a circuit
Summary
Questions
Join us on Discord
Simulating Quantum Systems and Noise Models
Technical requirements
Understanding the differences between simulators
Viewing all available backends
Running circuits on the Aer simulator
Adding parameters to the backend options
Initializing the qubits on a circuit
Running circuits on the statevector simulator
Running circuits on the unitary simulator
Accounting for noise in quantum circuits
Implementing an Aer noise model
Tracing the source of noise
Understanding decoherence
Understanding single-gate, multi-gate, and readout errors
Building your own noise model
Summary
Questions
Join us on Discord
Suppressing and Mitigating Quantum Noise
Technical requirements
Understanding the Qiskit Runtime service
Understanding Sessions
Understanding the Qiskit Runtime Options
Understanding Primitives
Understanding the Sampler primitive
Understanding the noise effects of decoherence
Understanding decoherence errors
Understanding dephasing errors
Differences between error suppression, mitigation, and correction
Summary
Questions
Further reading
Join us on Discord
Understanding Quantum Algorithms
Technical requirements
Understanding the meaning of outperforming classical systems
Learning about Deutsch’s algorithm
Understanding the problem
Defining the problem
Describing the problem as a quantum problem
Implementing Deutsch’s algorithm
Understanding the Deutsch-Jozsa algorithm
Understanding the Deutsch-Jozsa problem
Generating a quantum solution using the Deutsch-Jozsa algorithm
Implementing the Deutsch-Jozsa algorithm
Learning about the foundational oracle-based quantum algorithm
Learning about the Bernstein-Vazirani algorithm
Understanding the Bernstein-Vazirani problem
Generating a quantum solution using the Bernstein-Vazirani algorithm
Implementing the Bernstein-Vazirani algorithm
Summary
Questions
Join us on Discord
Applying Quantum Algorithms
Technical requirements
Understanding periodic quantum algorithms
Learning about the QFT algorithm
Understanding the QFT algorithm
Implementing the QFT algorithm
Learning about Grover’s search algorithm
Understanding the problem
Understanding Grover’s search algorithm
Implementing Grover’s search algorithm
Summary
Questions
Join us on Discord
Understanding Quantum Utility and Qiskit Patterns
Technical requirements
Understanding quantum utility
Understanding Qiskit Patterns
Step 1, Map
Step 2, Optimize your circuit
Step 3, Execute your circuit
Step 4, Post-process
Implementing the logical expression oracle
Summary
Questions
Join us on Discord
Appendix A: Resources
Join us on Discord
Appendix B: Assessments
Chapter 1 – Exploring the IBM Quantum Tools
Question 1
Answer
Question 2
Answer
Question 3
Answer
Chapter 2 – Creating Quantum Circuits with IBM Quantum Composer
Question 1
Answer
Question 2
Answer
Question 3
Answer
Question 4
Answer
Chapter 3 – Introducing and Installing Qiskit
Question 1
Answer
Question 2
Answer
Question 3
Answer
Question 4
Answer
Chapter 4 – Understanding Basic Quantum Computing Principles
Question 1
Answer
Question 2
Answer
Question 3
Answer
Question 4
Answer
Chapter 5 – Understanding the Qubit
Question 1
Answer
Question 2
Answer
Question 3
Answer
Question 4
Answer
Chapter 6 – Understanding Quantum Logic Gates
Question 1
Answer
Question 2
Answer
Question 3
Answer
Question 4
Answer
Question 5
Answer
Question 6
Answer
Chapter 7 – Programming with Qiskit
Question 1
Answer
Question 2
Answer
Question 3
Answer
Question 4
Answer
Chapter 8 – Optimizing and Visualizing Quantum Circuits
Question 1
Answer
Question 2
Answer
Question 3
Answer
Question 4
Answer
Chapter 9 – Simulating Quantum Systems and Noise Models
Question 1
Answer
Question 2
Answer
Question 3
Answer
Question 4
Answer
Question 5
Answer
Question 6
Answer
Chapter 10 – Suppressing and Mitigating Quantum Noise
Question 1
Answer
Question 2
Answer
Question 3
Answer
Question 4
Answer
Question 5
Answer
Chapter 11 – Understanding Quantum Algorithms
Question 1
Answer
Question 2
Answer
Question 3
Answer
Chapter 12 – Applying Quantum Algorithms
Question 1
Answer
Question 2
Answer
Question 3
Answer
Question 4
Answer
Question 5
Answer
Chapter 13 – Understanding Quantum Utility and Qiskit Patterns
Question 1
Answer
Question 2
Answer
Question 3
Answer
Question 4
Answer
Join us on Discord
Other Book You May Enjoy
Leave a Review!
Index
Cover
Index
Thank you for purchasing this book from Packt Publishing—we hope you enjoy it! Your feedback is invaluable and helps us improve and grow. Once you’ve completed reading it, please take a moment to leave an Amazon review; it will only take a minute, but it makes a big difference for readers like you.
Scan the QR code below to receive a free ebook of your choice.
https://packt.link/NzOWQ
Thanks for purchasing this book!
Do you like to read on the go but are unable to carry your print books everywhere?
Is your eBook purchase not compatible with the device of your choice?
Don’t worry, now with every Packt book you get a DRM-free PDF version of that book at no cost.
Read anywhere, any place, on any device. Search, copy, and paste code from your favorite technical books directly into your application.
The perks don’t stop there, you can get exclusive access to discounts, newsletters, and great free content in your inbox daily.
Follow these simple steps to get the benefits:
Scan the QR code or visit the link below:https://packt.link/free-ebook/9781803244808
Submit your proof of purchase.That’s it! We’ll send your free PDF and other benefits to your email directly.Quantum computing has been growing in popularity over the past few years, most recently since IBM released the first commercially available quantum computer on the cloud back in May 2016, back then referred to as the IBM Quantum Experience, now rebranded as the IBM Quantum Platform (IQP). This release was the first of its kind, hosted on the cloud and providing the world with the opportunity to experiment with quantum devices for free. The platform includes a user interface (UI) that allows anyone to run experiments on a real quantum computer. And just recently added was direct access to all documentation and learning resources, such as tutorials and courses, right from the platform, making it easier to run circuits as you learn.
The goal of this chapter is to first introduce you to the IBM Quantum Platform, which contains everything you need to learn how to create and run quantum circuits on real quantum systems. It also provides you with courses and tutorials to experiment with existing quantum algorithms and applications. The IBM Quantum Platform is comprised of the following three applications, which you can see listed in the Application Switcher located at the top-right corner of the platform (see Figure 1.1):
Platform: Lists all the jobs and systems (dashboard, systems, and jobs) you have access to on the platform.Documentation: Provides a list of resources to help you get started. Resources include how to set up your development environment and build/test/execute quantum circuits on quantum systems. It also provides API documentation of the latest version of the Quantum Information Science Kit (Qiskit) open-source code.Learning: Provides quantum courses and tutorials for users of all different levels. These cover topics such as the basics of quantum computing, variational algorithm design, and a new addition: quantum-safe cryptography!You can select and switch between each of these applications using the top-left applications icon next to your avatar, the switcher is shown in the following figure:
Figure 1.1: Application selection
This chapter will help you understand what actions and information are available in each application, each of which we will also cover in more detail in later chapters, to give you an overview of where everything is. This includes creating circuits, running the circuits on both simulators and real quantum devices, viewing information about your profile and available backend systems, and visualizing the results of your experiments. So, let’s get started!
The following topics will be covered in this chapter:
Getting started with the IBM Quantum PlatformUsing the documentation to quickly start upUnderstanding IBM quantum toolsThroughout this book, it is expected that you will have some experience in developing with Python and, although it isn’t necessary, some basic knowledge of classical and quantum mechanics would help. Most of the information will be provided with each chapter, so if you do not have knowledge of classical or quantum mechanics, we will cover what you need to know here. For those of you who have existing knowledge in this area, the information here will serve as a useful refresher.
The Python editor used throughout this book is Jupyter Notebook. You can, of course, use any Python editor of your choice. This may include Watson Studio, PyCharm, Spyder, Visual Studio Code, and so on.
Here is the source code used throughout this book: https://github.com/PacktPublishing/Learning-Quantum-Computing-with-Python-and-IBM-Quantum-Second-Edition
As mentioned earlier, the IBM Quantum Platform application is your high-level view of what you will normally see once you log in. It’s good to mention here that there may be updates to the tools as the platform evolves with the technology after the time of writing, so some visualizations and results may vary. The platform aggregates multiple views that you can see, and this helps you to get an idea as to what machines you have access to and what jobs you have pending, running, or completed.
In this section, we will go through the steps to get registered. Let’s get started.
In this section, we will get registered and explain what happens in the background once you sign up to the IBM Quantum Platform for the first time. This will help you understand what features and configurations are prepared and available to you upon registration.
To register, follow these steps:
The first step is to head over to the IBM Quantum Platform site at the following link: https://quantum.ibm.com/You should see the login screen, as shown in Figure 1.2. Your individual situation will determine how to proceed from there:If you already have an account or are already signed in, you can sign in and skip this section.If you have not registered, then you can select the login method of your choice from the sign-in screen. As you can see, you can register using various methods, such as with your IBMid, Google, GitHub, Twitter, LinkedIn, or by email.If you do not have any of the account types listed, then you can simply register for an IBMid account and use that to sign in:Figure 1.2: The IBM Quantum Platform sign-in page
Once you select the login method of your choice, you will see the login screen for that method. Simply fill out the information, if it’s not already there, and select login.Once signed in, you will land on the IBM Quantum Platform home page. This is the first page you will see each time you log in:Figure 1.3: The IBM Quantum home page
Now that you have registered with IBM Quantum Platform, let’s take a quick tour and delve into some features that make up the home page.
Note first that across the top of the Platform application page you have three tabs: Dashboard, Systems, and Jobs. Each of these provides various information for you, which we will cover in detail in the following sections. But before we get started, let’s look at the Manage account settings view.
Let’s start by reviewing the home page, specifically the Manage account settings view. You can access your user account and settings view via your avatar, located at the top right of the page (as visible in Figure 1.3).
This view provides profile settings of the logged-in user, as illustrated in Figure 1.4:
Figure 1.4: The Manage account settings view
This view also provides actions regarding your profile such as setting your password, email, API token, and in-app notification settings.
The API token is used by the provider to determine which systems you have provisioned for your account. This is autogenerated when you use the platform; however, should you ever decide to run a notebook off the platform, then you will need to save your API token locally. We describe how to save and load your account details locally in Chapter 7, Programming with Qiskit and the Qiskit Runtime Service.
Below the Manage account settings is the Instances list, which allows you to see which instances you are a member of. Instances are used to determine which IBM Quantum systems you have access to based on which hub, project, or group you belong to, as illustrated in Figure 1.4. Also, below the list of instances is the option Delete Account, which will also remove all your account data.
Figure 1.5: Instances and Delete Account views
Finally, at the bottom of the Profile settings you will see your Notification settings, which you can enable based on your preferences.
The Compute resources view provides you with a list of all the various quantum services available to you, which include the quantum systems. You can see all the available services by selecting the grid icon, located at the top left of the IBM Quantum Platform view, and selecting the Platform tab.
Once the Compute resources page is open you will see a grouping of systems via a pull-down selector highlighted by a box in the following figure. The groupings are of systems that you have access to and a list of all systems including those systems reserved for premium users, as illustrated in Figure 1.6:
Figure 1.6: The Compute resources view
The view contains all the systems available to you.
Each card (or row if viewing in table mode) represents a different quantum system available to you and details that describe each system. In the previous figure you can see it lists out detailed specifications. Systems with a lock icon next to them are those reserved for premium users such as those who are active members of the IBM Quantum Network.
The details you can see for each system are:
Qubits, which is the number of qubits availableError Per Layered Gate (EPLG), which is the latest metric used to measure the quality and performance of a quantum systemCircuit layer operations per second (CLOPS)Status, which is the availability of the system (Online, Maintenance, etc.)Total pending jobs, which is the number of jobs waiting to run on the system (queue)Processor type, which is the type and version of the processor of the systemThis information allows you to visualize all the systems and their metrics so you can select an ideal system to run your quantum circuits.
The second selector is to view All Instances; this lists all the quantum systems that are available to you, including the open systems as well as premium quantum systems, if you are a quantum network member. To view the list as a table, rather than cards, you can select table view (located just above the system selector) as illustrated in Figure 1.7:
Figure 1.7: A table view of all available systems – shows all available quantum systems, including premium systems
In this view, same as the Your resources view, each row represents details about each quantum system’s properties such as the status, processor type, number of qubits, quantum volume, and CLOPS.
CLOPS is one of the measurements that is used to determine the performance of a quantum computer. It measures the speed at which a quantum processor can execute layers of a circuit, similar to the parameterized model circuits used to measure the quantum volume of a quantum computer.
The names of the systems do not represent the location of the device; the city names originated from where IBM Research has a lab and have since expanded to include cities where IBM has offices around the world. At the time of writing, the IBM Quantum systems reside in many locations around the world. The largest groups are located at the IBM Research Lab in Yorktown Heights and in Poughkeepsie, NY. There are now many on-prem systems in many locations, such as IBM Ehningen, Germany (via a partnership with Fraunhofer-Gesellschaft), and University of Tokyo. The first on-prem system that is not on an IBM site was recently installed in Cleveland Clinic, with many more scheduled to be installed in other countries such as Spain and South Korea.
Above the rows you have a few features; one is a search window to help you find a specific system and next to that is a filter option, which allows you to narrow down the visible list of systems based on provider, status, or processor types. You can also see them as cards if you select the card selection on the top right of the table.
To view further details of each quantum system, let’s select one of the systems; in this case I will select ibm-brisbane, as seen in Figure 1.8. Keep in mind that systems will continue to evolve and may be replaced after the time of writing this, so if a system is mentioned in this book that you do not see, don’t worry; just select any that you like as the details you see will vary per device.
Figure 1.8: The device details view (truncated view of all 127 qubits)
In this view you can examine each system in more detail. Each quantum system has a set of properties that you have access to view. This helps greatly if there are some constraints or requirements to the type of system you wish to run your quantum programs on—for example, the connectivity between qubits, the error rate of each qubit and its physical connection, the basis gates, and other details that we will cover in detail in various chapters throughout this book.
This view also allows you to download a CSV file that contains all these properties so you can analyze them using any analysis tools you wish. To download the properties, simply click on the download icon located below the Last calibrated time in the Calibration data section.
You’ll also notice that there are two pull-down options available just above the qubit map of the system, where one has a set of options for Qubit and another for the Connection between the qubits. The options provide you with the ability to see what properties you wish to have rendered for each qubit and connection, respectively. In the qubit options you can select to see the details of each qubit, such as its frequency, T1/T2 times, anharmonicity, and readout assignment error. The connection options allow you to view the CNOT error and gate time (in nanoseconds) between each physically connected qubit.
There are of course other ways to obtain these properties programmatically using Qiskit code, but we will get to that later in this book. For now, this is just for awareness, so in later chapters when you learn more about them, you’ll know where the information is located.
We are now familiar with the systems, and their details, on which we will run our quantum circuits; let’s see how we can view the results after the quantum systems have completed their job.
When you send a circuit to run on a simulator or a quantum system you will want to know the status of the circuit. This is where the Jobs view comes in handy. To get to the Jobs view, go back to the grid icon located at the top left of the dashboard and select Jobs from the list of views. Once the view is open you will see a table, as shown in Figure 1.9, that contains a complete list of jobs that are pending completion on either the simulators or backend devices. You can use this view to see the status of your circuit or program, the job ID, which provider and service were used, and other details for each job you submitted:
Figure 1.9: The Jobs view list
The job ID is listed so that you can call back the details of that job later. Each job is initially sorted by creation date but can also be filtered by Status (completed, pending, or returned), Session Id (the unique ID for the session the job was run in), Compute resource (which simulator or quantum system was used), or Usage (time indicating how long the job took to run).
Details regarding job objects will be covered in Chapter 7, Programming with Qiskit.
In this section, you have learned where to find information about your experiments, and hardware details about the quantum devices from the various views available on the IBM Quantum Platform. There are views that also provide you with the tools you need to start programming and running circuits on a quantum computer, in an easy-to-use format that does not include any installation of software.
In the next section we will review what the Documentation application provides you to help get started using the systems we just learned in this section.
Earlier in this chapter we covered what systems you have access to and details about each system. In this section we will review the Documentation application, which will provide you with information and guidance on how to get yourself up and running and executing quantum circuits on a quantum computer.
First, from the application selector, select the Documentation application. This will open the Documentation page as illustrated in Figure 1.10:
Figure 1.10: Documentation application view
Let’s look across the top of the page where you will see seven shortcuts each to help you get started. They are described as follows:
Overview: The view that you see when you first get to the documentation page that has all the optionsStart: Directions on how to get your local system set up and install QiskitBuild: Instructions on how to design and develop your first quantum circuitsTranspile: How to optimize the mapping of your circuit onto the selected device to ensure the highest quality and performanceVerify: As the title indicates, how to test, verify, and evaluate your quantum circuitsRun: Executing your tested quantum circuits on the quantum systemsAPI reference: Quick links to key documentation on common objects and functionsBelow the Get started with Qiskit and APIReference section of the page, you will also see the various tutorials available for those of you who already have your system set up and want to dive right into running quantum algorithms on a quantum computer. Each tile represents a different tutorial and they are independent of each other so you can pick whichever you’d like to get started on without worrying about any dependency on another tutorial.
Now that you know where to find the documentation needed to help you get up and running quickly, let’s continue and explore the tools you can use to generate quantum circuits using the IBM Quantum Composer.
Understanding the systems and knowing the status of our circuit jobs is great, but knowing how to create these circuits and run them is clearly an important step. In this section we will review both tools that are available to you. Using the application switcher, select the last application listed, Learning.
The following figure, Figure 1.11 is the IBM Quantum Learning application view. This view provides you with a one-stop shop of resources. At first you will see that at the top, it highlights the latest course that was released. At the time of writing this, it was the Fundamentals of quantum algorithms. Below that is the catalog of courses available to you on the platform with topics ranging from the basics of quantum information science to quantum-safe cryptography.
Figure 1.11: IBM Quantum Learning application view
Below the courses you will see three other sections. The first is the list of tutorials. This is the same list you saw in the previous section. It is duplicated in this section for completeness as it is of course the learning application. And at the bottom is the Resources section, which lists other helpful learning resources, as illustrated in the following figure:
Figure 1.12: Courses, Tutorials, Tools, and Resources sections.
We have two ways to launch each tool. First, as illustrated in Figure 1.12, you can launch each tool by clicking on it within the Tools section. The second way is by selecting it from the top of the page as illustrated in Figure 1.11.
The Composer is a graphical UI where you can create your quantum circuits by dragging and dropping quantum gates onto a quantum circuit. The Composer also provides various visual representations of the results such as the state of the circuit and the expected probability measurements. This makes the Composer a fantastic tool to help you get a visual, and perhaps intuitive, understanding of how the various quantum gates and properties affect the results of both the qubit itself and the overall quantum state. This is a tool I highly recommend you start with as it contains some very nice introductory tutorials that you can follow to create your first quantum circuit and run it on an actual quantum computer. We will create a simple circuit and run it on a quantum computer in Chapter 2, Creating Quantum Circuits with IBM Quantum Composer.
Now that we are done with our tour of the IBM Quantum tools, we’re ready to get to work. In the following chapters, we will delve further into the Composer and progress to writing quantum programs.
In this chapter, we reviewed the IBM Quantum Platform, which provides plenty of information to help you get a good lay of the land. You now know where to find information regarding your profile, details for each of the devices you have available, the status of each device, as well as the status and results of your experiments. Some views might look a little different based on the level of provider you have. I have chosen to use the free open provider throughout this book so all users can see the general views. If you are a premium or partner user, then your views may have more information or options that are specific to your provider. Details about those differences are outside the scope of this book; however, you can check with your IBM Quantum representative for details about the additional views and roles.
Knowing where to find this information will help you monitor your experiments and enable you to understand the state of your experiments by reviewing your backend services, monitoring queue times, and viewing your results queues.
In the next chapter, we will learn about the Composer in detail and run our very first quantum circuit.
Join our community’s Discord space for discussions with the author and other readers:
https://packt.link/3FyN1
In this chapter, you will learn how to use the IBM Quantum Composer and what each of its component functions are with respect to creating and running experiments. The Composer will help you to visually create a quantum circuit via its built-in UI, which in turn will help you to visually conceptualize some of the basic principles of quantum mechanics used to optimize your experiments. You will also learn how to preview the results of each experiment and create your first quantum circuit.
The following topics will be covered in this chapter:
Getting started with the Quantum ComposerCreating a quantum circuit with the Quantum ComposerBy the end of this chapter, you will know how to create a quantum circuit using the Composer, and create experiments that simulate classic gates and quantum gates. You will also have learned where to examine the various results of your experiments, such as state vectors and their probabilities. This will help you understand how some quantum gate operations affect each qubit.
In this chapter, some basic knowledge of computing is assumed, such as understanding the basic gates of a classic computing system.
Here is the full source code used throughout the book: https://github.com/PacktPublishing/Learning-Quantum-Computing-with-Python-and-IBM-Quantum-Second-Edition
In this section, we will review the IBM Quantum Composer (hereafter referred to as simply the Composer) layout so that you can understand its functionality and behavior when creating or editing quantum circuits. Here, you will also create a few circuits, leveraging the visualization features from the Composer to make it easy for you to understand how quantum circuits are created. So, let’s start at the beginning: by launching the Composer.
To create a quantum circuit, let’s first start by opening the Composer. To open the Composer view, click on the Composer button located at the top of the IBM Quantum Learning (https://learning.quantum.ibm.com) application as shown in the following screenshot:
Figure 2.1: Launch the Composer
Now that you have the Composer open, let’s take a tour of what each component of the Composer editor provides you with.
In this section, we will get familiar with each of the components that make up the Composer. These allow you to do things such as visually inspect the results of your experiments in a variety of ways. Visualizing the construction of the quantum circuit will help you conceptualize how each quantum gate affects a qubit.
In this section, we will review the various functionalities available to ensure you have a good understanding of all the different features available to you.
In Figure 2.2, you can see the landing page of the Composer view:
Figure 2.2: The IBM Quantum Composer view
From the preceding screenshot, you can see the Composer view, containing three qubits (q[0], q[1], and q[2]). This might not look the same when you launch the Composer for the first time. If you would like to add or remove qubits, you can simply select a qubit, for example q[1], by clicking on it, and selecting the plus icon or the trash icon, which will appear over the specific qubit.
If any of the views are not visible, this just means they have not been enabled. You can enable them by selecting the View pull-down menu located across the top of the Composer, hovering over Panels, and selecting the views that are not visible: for example, the Statevector view.
To reproduce the views used throughout this chapter, simply add or remove the qubits until you only have three qubits left. You can add/remove by clicking on the qubit label. The default is three.
Now that you have your views set up, let’s continue to the Composer view itself. In the following screenshot, you can see a series of gates and operations:
Figure 2.3: Gates and operations
Each of the components shown has a specific function or operation that acts upon the qubit(s), which we will cover in detail in Chapter 6, Understanding Quantum Logic Gates.
As we can see in the following screenshot, we also have the circuit editor itself, which is the part of the Composer where we will create our quantum circuit by placing various gates and operations:
Figure 2.4: Circuit editor
As you can see from the preceding screenshot, the default circuit includes three qubits (though this might change over time) each of which is labeled with a q, and the index appended in order from left to right (in this case, q[2], q[1], and q[0]). This will be significant when we want to map the results from our quantum circuit. Each qubit is initialized to an initial state of 0 before running the experiment.
The last line is the classical bits, which are what we will map each qubit to so that when we complete running our quantum circuit, the results are then passed to the classical bits according to the mapping. By default, the mapping from qubit to bit is done based on the index of the qubit. For example, q0 measurement results will be mapped to c0 via the measurement operator, which we will see when we run our quantum circuit. You can add or remove classical bits in the same manner as qubits.
Next to the qubit you will see a line, which looks like a wire running out from each qubit, in the circuit editor:
Figure 2.5: Qubits and circuit wires
These lines are where you will be creating a circuit by placing various gates, operations, and barriers on them. This circuit has three wires, each of which pertains to one of the three qubits on the quantum computer. The reason it is called a Composer is primarily that these lines look very similar to a music staff used by musicians to compose their music. In our case, the notes on the music staff are represented by the gates and operations used to ultimately create a quantum algorithm.
In the next section, we will review the various options you have available to customize the views of the Composer. This will allow you to ensure that you can only see what you want to see while creating your quantum circuit.
Continuing with our Composer tour, at the top of the Composer view are the circuit menu options that allow you to save your circuit, clear the circuit, or share your quantum circuit:
Figure 2.6: The Composer menu options
First, we will cover how to save your circuit. To do this, simply click on the default text at the top left of the Composer where it currently reads Untitled circuit, and type in any title you wish. Ideally, select a name that is associated with the experiment. In this case, let’s call it MyFirstCircuit and save it by either hitting the Enter key or clicking the checkmark icon to the right of the title, as shown below:
Figure 2.7: Renaming the circuit
Across the top of the Composer, you will see a list of drop-down menu options. The menu items in the preceding screenshot have the following options:
File provides options to create and open circuits, as well as copy, export, share, or delete the current circuit.Edit allows you to manage your circuit and clear gates and operators.View enables the various view options, which we look at in the following sections.Let’s now look at each of the various views in the following sections.
The Graphical Editor view contains a few components used to create quantum circuits:
Figure 2.8: The Graphical Editor view options
The components include the following:
Circuit Composer: UI components used to create quantum circuits.Operations: A list of available drag-and-drop gates and operators to generate a quantum circuit.Options: The ability to set up the alignment and turn on the Inspect feature, which allows you to step through each gate and operation as you would to debug your code on an IDE or browser.Disk: A disk that is located at the end of the circuit to serve as a visual representation of each qubit as you add gates and operations.Now that we know where we can create a quantum circuit, let’s move on to displays, which provide various ways to visualize the results of our quantum circuit.
The Statevectorview allows you to preview the state vector results, which is to say the quantum state result of your quantum circuit. The state vector view presents the computational basis states of the quantum circuit in a few different ways. To simplify the view, I have removed all but one qubit so it is easier to read the values.
You can do the same if you wish, otherwise your x axis may have more than just the two states of 0 and 1, as shown in the following figures:
Figure 2.9: The Statevector view
First, we see the Amplitude bar graph, which represents the amplitude of the computational basis states. In this case, as mentioned earlier, for simplicity we have reduced the number of qubits to just one qubit, for which there are two computational basis states, 0 and 1. These are represented along the x axis. The value of the amplitude of each basis state is represented along the y axis. In this case, since we do not have any gates or operators on our circuit, the state vector representation is that of the initial (ground) state. The initial state indicates that all qubits are set to the 0 (zero) state, indicated by an amplitude value of 1.
At the bottom of the Statevector view we see the Output state representing the complex value of each computational basis state. In this case since we are in the initial state, we see the 0 state at 1 + 0j and the 1 state at 0 + 0j.
To the bottom left is the phase wheel. The phase wheel is a color visual representation of the phase for each basis state, which has a range between 0 and 2π. Since we have not applied any phase gates, we see the default phase of 0 represented by the color blue. As you apply phase shifts to each qubit, the color of the bar will update according to the color representation of the phase.
We will cover what phases are in more detail in later chapters, but for now just know where they are and how they are indicated, both by value in the state vector results and in the phase wheel by color.
The state vector information is just one of the visual representations of your quantum circuit. There are a couple of others we want to visit before moving on.
The next view is the Probabilities view. This view presents the expected probability result of the quantum circuit (with the addition of a single measurement operator to the qubit). As mentioned in the previous description, and illustrated in the following screenshot, since we do not have any operators on the circuit, the results shown are all in the initial state of 0:
Figure 2.10: The Probabilities view
The probability view is a general representation of the results based on expected values, not the actual results you will get from a quantum system. This view currently represents what the Composer is calculating classically as we have not yet run this circuit on an actual quantum computer. The results you will see as we create this circuit are computed by the classical system and not by a quantum system. The results from a quantum system are received after we send the completed circuit to run.
Finally, the last of the state visualizations we must review is the Q-sphere view. The Q-sphere looks similar to a Bloch sphere, which is used to represent the statevector of the current state of a qubit. However, the Bloch sphere does have some limitations, particularly that it can only represent the state of a single qubit. On the other hand, the Q-sphere can be used to visually represent the state information of a single qubit or multiple qubits at once in one sphere, including the phase information. The following screenshot shows a representation of a circuit with three qubits, all of which are in the initial state:
Figure 2.11: The Q-sphere view
The Q-sphere view has two components; the first is the Q-sphere itself, which