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
| Word | What it means | Example |
|---|---|---|
| Measurement | reading a qubit, which gives one 0 or 1 | |
| Shot | one run of the program, ending in a measurement | |
| Counts | how many times each answer appeared | {'0': 507} |
| Expected count | the shots times the chance of an answer | |
| Seed | a number that makes a simulator's chance repeat | |
| Probability | the 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
| State | Chance of 0 | Chance of 1 | Expected 0s | Expected 1s |
|---|---|---|---|---|
| [1, 0] | 1 | 0 | 1000 | 0 |
| [0.707, 0.707] | 0.5 | 0.5 | 500 | 500 |
| [0.6, 0.8] | 0.36 | 0.64 | 360 | 640 |
| [0.6, -0.8] | 0.36 | 0.64 | 360 | 640 |
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
docker exec jupyter python3 steps/measure.pyShown 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
| Shots | Seed | Counts of 0 and 1 | Share of zeros |
|---|---|---|---|
| 10 | 7 | 4 and 6 | 0.4 |
| 1000 | 1 | 507 and 493 | 0.507 |
| 10000 | 1 | 4953 and 5047 | 0.4953 |
The cells students fill in are left blank in this preview.
Ten shots with seed 7
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
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
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.