Easier to read with cream paper, a tint, more contrast or larger text? Choose your colours and text, once, for every page.

Free lesson

What is a qubit? States and amplitudes

After this lesson: I can describe a qubit's state with two numbers.

50 min lesson2 commandsQuantum simulator lab: qubits, gates and measurement in JupyterLab

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

WordWhat it meansExample
Qubitthe quantum version of a bit
Amplitudea number for one outcome; its size squared is a chance0.6
State vectorthe list of all the amplitudes[0.6, 0.8]
Probabilitythe chance of an outcome, from 0 to 1
Normalisedscaled so the chances add up to 1
Simulatora 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 vectorAmplitude of 0Amplitude of 1Chance of 0Chance of 1
[1, 0]1010
[0, 1]0101
[0.707, 0.707]0.7070.707about 0.5about 0.5
[0.6, 0.8]0.60.80.360.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

Command
docker exec jupyter python3 steps/qubit.py

Shown 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

Command
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]

StepWorkResult
Square each size3 squared, 4 squared9 and 16
Add them9 + 1625
Take the square rootsquare root of 255
Divide each amplitude3 / 5 and 4 / 50.6 and 0.8
Check the chances0.36 + 0.641

The cells students fill in are left blank in this preview.

Normalise a list in Python

Code: 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.

About this lab and its source: Quantum simulator lab: qubits, gates and measurement in JupyterLab

Teaching a class? Set this module for your students with a teacher guide, marked assignments and a lab for every student.