Exercises: Measurement, Shots, and Statistics
Most of this chapter's work is measurement and arithmetic rather than circuit design, and that is the point — these are the skills that let you report a quantum result rather than merely produce one.
Difficulty: ⭐ warm-up · ⭐⭐ standard · ⭐⭐⭐ deeper.
Solutions: worked answers to the daggered (†) and odd-numbered problems are in
appendices/answers-to-selected.md; runnable code in
code/exercise-solutions.py. Exercises marked 🌐 use a fake backend.
Part A — Warm-ups ⭐
5.1 † Measurement does two things. Name both. Which one do people forget?
5.2 What does it mean to say measurement "happens in a basis"? Give a state that is deterministic in one basis and a fair coin in another.
5.3 † In the counts key '0110', which qubit measured 1? Which measured 0?
5.4 Write the formula for the standard error of a probability estimated from $N$ shots. What is its maximum value, and at what $p$?
5.5 † You need a probability to ±0.01 at 95% confidence. Roughly how many shots? To ±0.001?
5.6 What is the difference between a marginal and a partial measurement?
Part B — Bitstrings and Registers ⭐⭐
5.7 † For a 3-qubit circuit, apply x to each qubit in turn and report the counts. State the rule
relating qubit index to bitstring position.
5.8 Build a circuit with one 3-qubit quantum register and two classical registers, a of
size 1 and b of size 2. Measure into both. Which register appears leftmost in the counts key, and
why?
5.9 † Build a GHZ state on 3 qubits and measure it twice: once with measure([0,1,2],[0,1,2])
and once with measure([0,1,2],[2,1,0]). Are the results different? Now insert qc.x(2) before
measuring and repeat. What general rule about test design does this demonstrate?
Part C — Statistics ⭐⭐
5.10 † Measure the $1/\sqrt N$ law. For shot counts 10 through 100,000, run a fair-coin circuit 40 times at each and report the standard deviation of the estimated probability. Compare to $1/(2\sqrt N)$ and report the ratio.
5.11 Tabulate the shots required for precisions of 0.1, 0.05, 0.01, 0.005, 0.001, and 0.0001, and the QPU time each costs at 100 μs per shot. At which precision does a single measurement exceed one hour?
5.12 † Measure $\langle Z\rangle$, $\langle X\rangle$, and $\langle Y\rangle$ for the five states $|0\rangle$, $|1\rangle$, $|+\rangle$, $|-\rangle$, $|{+}i\rangle$. Present as a table. Which entries are exactly $\pm1$ and which should be zero? Are the "zero" entries exactly zero, and if not, is that a bug?
5.13 † Compute all six two-qubit Pauli correlators for the Bell state $|\Phi^+\rangle$ using the Estimator. Explain why $\langle YY\rangle = -1$ rather than $+1$, and state the practical consequence for building an entanglement witness.
5.14 Build a 3-qubit circuit with a Bell pair on qubits 0–1 and an x on qubit 2. Measure all
three, then compute every marginal: over $\{0\}$, $\{1\}$, $\{2\}$, $\{0,1\}$, $\{0,2\}$. Which
marginals show correlation and which do not?
5.15 † Statistical power. For true biases $P(1) = 0.50, 0.52, 0.55, 0.60$ and shot counts 100, 1,000, 10,000, run a chi-squared test against a fair-coin expectation and tabulate the p-values. Identify, for each bias, the smallest shot count that reliably rejects. Compare to $1/\delta^2$.
Part D — Deeper ⭐⭐⭐
5.16 † Write pauli_expval(counts, pauli) from scratch, handling identity positions correctly.
Test it against StatevectorEstimator on at least six Pauli strings for a 3-qubit GHZ state. Then
deliberately pass a Pauli string of the wrong length and describe what happens — does your function
detect it, or silently return a wrong number?
5.17 For the Bell state, $\langle ZI\rangle$ should be exactly 0. Estimate it at 256, 4,096, and 65,536 shots and report the value with its standard error each time. Does the true value fall inside your error bar every time? Run the whole experiment 20 times — how often does the 95% interval actually contain 0? Is it close to 19 out of 20?
5.18 † The standard error of an expectation value is $\sqrt{(1 - \langle P\rangle^2)/N}$. Explain why an observable near $\pm 1$ has a smaller error bar than one near 0 at the same shot count. What does that imply for how you should distribute a fixed shot budget across the terms of a Hamiltonian?
5.19 Amplitude estimation achieves $1/N$ scaling rather than $1/\sqrt N$. Without implementing it, work out the consequence: to reach a precision of $10^{-4}$, how many shots does each approach need? By what factor do they differ? Now state the catch (hint: what does the $1/N$ method require of the circuit?), and say why it is not currently usable on NISQ hardware.
5.20 † Design an experiment to distinguish a device with 2% readout error from one with 3%, using only the gate-free calibration circuit from Chapter 2. How many shots do you need to tell them apart at 95% confidence? Show the arithmetic.
5.21 🌐 Run a Bell state on FakeSherbrooke at 1,024 and 65,536 shots. Compute the error fraction
with its standard error at each. Does the error fraction change? Does its uncertainty? Write two
sentences distinguishing what more shots bought you from what they did not.
Part E — Project ⭐⭐
5.22 † Implement the Chapter 5 🧱 Project Checkpoint: vqelab/measure.py with probabilities,
pauli_expval, expval_stderr, basis_rotation, and shots_for_precision.
5.23 Make pauli_expval raise a clear error when the Pauli string length does not match the
bitstring width. Why is this specific check worth more than most input validation? (Consider what
happens without it.)
5.24 ⭐⭐⭐ Add estimate_hamiltonian(prep, terms, shots) to measure.py, where terms is a list
of (coefficient, pauli_string) pairs. It should measure each term in its own basis, combine them
into a weighted sum, and propagate the uncertainties into a total standard error. Test it on the
Hamiltonian $H = 0.5\,ZZ + 0.3\,XX - 0.2\,ZI$ applied to a Bell state, and check the result against
an exact StatevectorEstimator calculation.
This is, essentially, VQE's energy evaluation. Chapter 24 will call it in a loop.