Get started with Qiskit in the classroom
Ang pahinang ito ay hindi pa naisalin. Nakikita mo ang orihinal na bersyon sa Ingles.
For this Qiskit in Classrooms module, students must have a working Python environment with the following packages installed:
qiskitv2.1.0 or newerqiskit-ibm-runtimev0.40.1 or newerqiskit-aerv0.17.0 or newerqiskit.visualizationnumpypylatexenc
To set up and install the packages above, see the Install Qiskit guide. In order to run jobs on real quantum computers, students will need to set up an account with IBM Quantum® by following the steps in the Set up your IBM Cloud® account guide.
This module was tested and used 2 seconds of QPU time on a Heron v2 processor. This is an estimate only. Your actual usage may vary.
# Uncomment and modify this line as needed to install dependencies
#!pip install 'qiskit>=2.1.0' 'qiskit-ibm-runtime>=0.40.1' 'qiskit-aer>=0.17.0' 'numpy' 'pylatexenc'
Introduction
In the Qiskit in the Classroom modules, you'll have the opportunity to use a quantum computer to explore various concepts in quantum computing-adjacent fields such as quantum mechanics, computer science, chemistry, and more. This module serves as a prerequisite to the others - it introduces the fundamentals of quantum computing and how to use Qiskit to run quantum circuits.
First we'll give you a brief overview of how a classical computer works, then we'll show you how these concepts are adapted to fit the quantum computing paradigm. Finally, we'll show you how to put these concepts together to build and execute your first quantum circuit.
Classical computers
You're likely familiar with the basics of how classical computers work, but here we'll highlight a few of the key features so that we can then draw a comparison to quantum computers.
The basic units of information: bits
Classical computers process classical information, and the fundamental unit of classical information is the bit. A single bit can store the answer to one "yes/no" question. We usually represent the two binary states of a bit as "0" and "1".
Review of binary numbers
Combining bits enables you to store more information. For example, if you want to store a number from 0 to 15, you could do so with four bits in the following way:
| 0 = 0000 | 4 = 0100 | 8 = 1000 | 12 = 1100 |
| 1 = 0001 | 5 = 0101 | 9 = 1001 | 13 = 1101 |
| 2 = 0010 | 6 = 0110 | 10 = 1010 | 14 = 1110 |
| 3 = 0011 | 7 = 0111 | 11 = 1011 | 15 = 1111 |
In general, to convert from a binary number of bits to a familiar, base-10 number, you multiply the least-significant (rightmost) bit by , the next bit to the left by , then the next by , and so on, until you reach the most significant (leftmost bit), which you multiply .
So, that means that bits can be in one of different possible states.
Check your understanding
Read the question(s) below, think about your answer, then click the triangle to reveal the solution.
How many bits would you need to represent the number 86? Write out the bitstring that encodes this number in binary.
Answer:
Remember, bits allows you to represent the numbers through , so using six bits would get us up to . That's not quite enough. We add one more bit to get up to . Now let's break 86 down into powers of 2:
Fundamental operations: gates
Now, a computer needs to be able to do something with the bits in order to, well, compute. Binary gates are the operations that form the fundamental building blocks of all the more complicated algorithms and codes.
Single-bit gate:
NOT
When you have only one bit, there's only one way you can transform its state: flip the state from 0 to 1 or from 1 to 0. We call this the "NOT" gate. The effect of this gate — and the rest of the gates we'll discuss below — can be represented in a so-called "truth table," with columns for the input and output states of the qubits. The truth table for the NOT gate is:
| Input | Output |
|---|---|
| 0 | 1 |
| 1 | 0 |
Multi-bit gates:
AND
AND is a two-bit gate that takes two input bits and outputs a single bit. It outputs 1 if both input bits are 1, and 0 otherwise:
| Input | Output |
|---|---|
| 00 | 0 |
| 01 | 0 |
| 10 | 0 |
| 11 | 1 |
OR
OR is another two-bit gate with a single output bit. It outputs 1 if either of the bits are 1:
| Input | Output |
|---|---|
| 00 | 0 |
| 01 | 1 |
| 10 | 1 |
| 11 | 1 |
XOR
XOR stands for "exclusive OR" and it is like the OR gate, but outputs 1 if only one of the input bits are 1. It outputs 0 if they are either both 1 or both 0:
| Input | Output |
|---|---|
| 00 | 0 |
| 01 | 1 |
| 10 | 1 |
| 11 | 0 |
Measurements:
Typically, when learning about classical computing, not much attention is paid to the process of reading out the state of the bits. This is because it's not very complex from a conceptual perspective. You can measure the bits at anytime before, during, or after a computation, and it doesn't affect the outcome. This is not the case in quantum computing, as we will discuss below.
Circuits:
By combining the gates above, you can do any sort of operation you want on a computer. Let's take a simple example: Using the AND and XOR gates, you can construct the half-adder circuit, which calculates the sum of two bits. This is represented in a logical circuit diagram, where the wires represent the bits and the gates operating on the bits are shown as symbols on the corresponding wires:
So, the two bits are copied and fed through both an AND gate and an XOR gate. The result of the XOR gate is the "sum bit" (S), which remains in the ones place of the binary number, and the result of the AND gate is the "carry bit" (C), which is the value of the next most significant digit in the binary number. Here is the truth table:
| Sum () | Carry () | ||
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 1 |
Check your understanding
Read the question(s) below, think about your answer, then click the triangle to reveal the solution.
Verify that the above truth table yields the correct solution for an adder circuit. That is, for each of the four options of A and B, verify that .
Answer: