12 min read
Measurement, Shots, and Running on a Simulator
Why measuring collapses a qubit, what "shots" are, and how Qiskit Aer turns a circuit into counts.
Suggested before this lesson
Every visualization so far has shown you the exact state of a circuit: the precise amplitudes, computed directly. A real quantum computer will never hand you that. All it gives you is measurement outcomes, one bit per qubit, and you have to run the circuit over and over to see the underlying pattern. This lesson is about that gap.
Measuring a qubit forces it out of superposition into a single classical outcome ( or ) with probability given by the amplitudes you already know: for , for . This is called collapse, and it's a one-way door: once measured, the superposition is gone. Measure the same qubit again immediately after and you'll get the same result every time, with certainty.
This is fundamentally different from reading a classical bit. Checking a classical bit's value doesn't change it. Checking a qubit's value is what produces a definite value in the first place: before that, "0 or 1" wasn't a fact about the qubit waiting to be read, it was genuinely undetermined.
.measure()You've already met ClassicalRegister: this is what it's for. .measure(qubit, clbit) measures a qubit and writes the classical outcome ( or ) into a classical bit:
Live preview of the circuit detected in your code
.measure() doesn't only take a single qubit and a single classical bit; it accepts the same shapes any Qiskit list-like argument does, as long as the qubit list and classical-bit list are the same length:
Mismatched lengths (say, three qubits but two classical bits) is exactly the kind of thing real Qiskit refuses to run, and this course's checker refuses it too, for the same reason: it genuinely doesn't know which classical bit the third qubit's result should go to.
measure_all() and measure_active()Two convenience methods exist so you don't always have to build a ClassicalRegister by hand:
measure_active() is handy for circuits where you've allocated more qubits than you ended up using; it skips the untouched ones rather than measuring qubits that never did anything.
These are worth recognizing when you read other people's code, but this course's exercises stick to the explicit .measure(qubit, clbit) form you just practiced above: it says exactly which qubit goes to which classical bit, with nothing implicit, which makes it the clearest way to learn measurement even once measure_all() becomes the one you reach for day to day.
Here's the problem: a single run of the circuit above gives you exactly one bit: a or a . That single outcome tells you almost nothing about whether the qubit was 50/50, or 90/10, or anything else. It's like trying to judge whether a coin is fair from a single flip.
The fix is the same as with a coin: flip it a lot of times and look at the fraction of heads. In quantum computing, one full run of a circuit (prepare, evolve, measure) is called a shot. Run the circuit for many shots, tally up how often each outcome occurred, and that tally approximates the true probabilities. More shots means less noise, exactly like more coin flips means a more reliable estimate of its bias.
Qiskit Aer (qiskit_aer) is Qiskit's high-performance local simulator: the thing you run circuits on when you don't have (or don't need) real quantum hardware. The pattern is: build a circuit with measurements, hand it to a backend, ask for a number of shots, and read back the counts.
counts is a dictionary: each key is an observed bitstring, each value is how many of the shots runs produced it. Divide by shots and you get an estimate of the probability: the same probabilities the exact panels earlier in this course have been showing you directly.
We can't run real Aer in your browser: there's no Python here, just a static checker for your circuits. But the sampling underneath the widget below works the same way: it draws random outcomes from this lesson's exact probabilities, exactly as if AerSimulator had run them.
Click a shot count to (re-)run the 'simulation'. At 10 shots, expect noise. By 10,000, the measured split should look close to a clean 50/50 between 00 and 11.
Circuit
circuit: bell_pair
Shots
Measured counts (1,000 shots)
509 (50.9%)
0 (0.0%)
0 (0.0%)
491 (49.1%)
Exact probabilities
50.0%
0.0%
0.0%
50.0%
Each run of a real quantum circuit gives one random outcome, sampled from these exact probabilities. "Shots" is how many times the circuit is run — click a few shot counts above and watch the measured counts settle closer to the exact probabilities as shots go up.
Python
Python
Python
Python
Python