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

Free lesson

Measuring a qubit: the measuring rule

After this lesson: I can predict what measuring a state gives.

55 min lesson4 commandsQuantum simulator lab: qubits, gates and measurement in JupyterLab

Measuring a qubit gives one answer by chance

Measuring a qubit gives one answer, 0 or 1, chosen by chance. The chance of each answer is its amplitude squared. This is called the measuring rule, or the Born rule.

It matters because measuring is the only way to get a result out of a quantum program. In this lesson you predict the counts from a state, then check them in the lab.

By the end of this lesson

Note

I can predict what measuring a state gives.

Key words

WordWhat it meansExample
Measurementreading a qubit, which gives one 0 or 1
Shotone run of the program, ending in a measurement
Countshow many times each answer appeared{'0': 507}
Expected countthe shots times the chance of an answer
Seeda number that makes a simulator's chance repeat
Probabilitythe chance of an outcome, from 0 to 1

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

An answer's chance is its amplitude squared

Take a state. For each possible answer, square the size of its amplitude. That is the chance of reading that answer.

If you run the program many times, you expect each answer about that share of the time. The expected count is the number of shots times the chance.

Worked example: expected counts for 1000 shots

StateChance of 0Chance of 1Expected 0sExpected 1s
[1, 0]1010000
[0.707, 0.707]0.50.5500500
[0.6, 0.8]0.360.64360640
[0.6, -0.8]0.360.64360640

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

Measure the H state 1000 times

The lab's measure script puts a qubit in the state made by H, then reads it 1000 times. It uses a seed, a number that makes the simulator's chance repeat, so every copy of the lab prints the same counts.

Seed 1 gives 507 zeros and 493 ones. Seed 2 gives 503 and 497. Seed 1 again repeats the first. Real hardware has no seed.

Run the measure script

Command
docker exec jupyter python3 steps/measure.py

Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.

More shots bring the share closer

Counts wobble around the expected counts. They are almost never exact.

With more shots the wobble is bigger in number but smaller as a share of the shots. A share of 0.4 from 10 shots is a long way from 0.5. A share of 0.4953 from 10,000 shots is very close.

Worked example: the H state with more shots

ShotsSeedCounts of 0 and 1Share of zeros
1074 and 60.4
10001507 and 4930.507
1000014953 and 50470.4953

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

Ten shots with seed 7

Command
docker exec jupyter python3 -c "from qsim import *; print(measure(apply(H, zero(1), 0), 10, 7))"

Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.

Ten thousand shots with seed 1

Command
docker exec jupyter python3 -c "from qsim import *; print(measure(apply(H, zero(1), 0), 10000, 1))"

Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.

A common mistake

Warning

Many people think one measurement shows the amplitudes. It shows a single 0 or 1. To estimate the chances you must repeat the whole program many times. Even then you learn only the squares, so you cannot tell a plus sign from a minus sign.

Two qubits give four possible answers

A state of two qubits has four outcomes: 00, 01, 10 and 11. Each has its own chance, and the chances add up to 1.

If H is applied to both qubits, every amplitude is 0.5 and every chance is 0.25. The expected count of each outcome in 1000 shots is 250.

Measure H on both of two qubits

Command
docker exec jupyter python3 -c "from qsim import *; print(measure(apply(H, apply(H, zero(2), 0), 1), 1000, 1))"

Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.

What the four counts say

The Run printed 239, 268, 223 and 270. None is exactly 250, and each is within about 30 of it. The counts add up to 1000, as they must.

An outcome with no chance never appears. A qubit that is certain to read 0 only ever gives 0.

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.