A qubit is two numbers, not one value
A qubit is the quantum version of a bit. It is described by two numbers, not one value. Those two numbers give the chance of reading 0 and the chance of reading 1.
The lab in this module is a simulator on an ordinary computer. It is not a quantum computer. A simulator cannot show that a quantum computer is faster. It shows the rules, and the rules are the same.
By the end of this lesson
Note
I can describe a qubit's state with two numbers.
Key words
| Word | What it means | Example |
|---|---|---|
| Qubit | the quantum version of a bit | |
| Amplitude | a number for one outcome; its size squared is a chance | 0.6 |
| State vector | the list of all the amplitudes | [0.6, 0.8] |
| Probability | the chance of an outcome, from 0 to 1 | |
| Normalised | scaled so the chances add up to 1 | |
| Simulator | a program that follows the rules on an ordinary computer |
The cells students fill in are left blank in this preview.
A qubit has one amplitude for each answer
A bit is 0 or 1. A qubit has a state: a pair of numbers called amplitudes. One belongs to the answer 0 and one to the answer 1.
A list of numbers in a fixed order is a vector, so the state is a state vector, such as [0.6, 0.8]. The chance of an answer is the size of its amplitude, squared. Amplitudes can be complex numbers, which Python writes like 0.6+0.8j. The size of any of them is abs(z).
Worked example: four states and their chances
| State vector | Amplitude of 0 | Amplitude of 1 | Chance of 0 | Chance of 1 |
|---|---|---|---|---|
| [1, 0] | 1 | 0 | 1 | 0 |
| [0, 1] | 0 | 1 | 0 | 1 |
| [0.707, 0.707] | 0.707 | 0.707 | about 0.5 | about 0.5 |
| [0.6, 0.8] | 0.6 | 0.8 | 0.36 | 0.64 |
The cells students fill in are left blank in this preview.
Make a qubit in the lab
The lab keeps a short Python file, qsim.py, that you can read. The first script makes a qubit in the state |0>, which means "certainly 0". It prints the state as 1.000|0>, then the chances [1. 0.].
It also makes two qubits. Two qubits need four amplitudes, one for each of 00, 01, 10 and 11.
Run the qubit script
docker exec jupyter python3 steps/qubit.pyShown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
Why a simulator cannot show a speed-up
The simulator stores one amplitude for every outcome. One qubit needs 2, two need 4, ten need 1,024 and twenty need 1,048,576. Each extra qubit doubles the work.
So a simulator gets slower as it grows. A program that is fast on a real quantum computer would not be fast here. Use the lab to learn the rules, and never to time anything.
Count the amplitudes for 10 and 20 qubits
docker exec jupyter python3 -c "from qsim import *; print(len(zero(10)), len(zero(20)))"Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
The chances must add up to 1
Something must happen when you measure, so the chances add up to 1. A state like that is normalised.
The state [3, 4] is not: 9 and 16 add up to 25. Divide each amplitude by the square root of 25, which is 5, and you get [0.6, 0.8]. Check it: 0.36 and 0.64 add up to 1.
Worked example: normalise [3, 4]
| Step | Work | Result |
|---|---|---|
| Square each size | 3 squared, 4 squared | 9 and 16 |
| Add them | 9 + 16 | 25 |
| Take the square root | square root of 25 | 5 |
| Divide each amplitude | 3 / 5 and 4 / 5 | 0.6 and 0.8 |
| Check the chances | 0.36 + 0.64 | 1 |
The cells students fill in are left blank in this preview.
Normalise a list in Python
def normalise(amps):
total = 0
for a in amps:
total = total + abs(a) ** 2
size = total ** 0.5
result = []
for a in amps:
result.append(a / size)
return result
# Change the list to [1, 1] and press Run. Then add up the squares of what you get.
print(normalise([3, 4]))
A common mistake
Warning
Many people think an amplitude is a chance. It is not. The chance is the amplitude's size squared. Two amplitudes of 0.707 give two chances of 0.5, and their sum is 1. An amplitude may even be negative, but a chance never is.