Exercises: Error Mitigation
All of these run on fake backends — no credentials, no queue. Solutions to starred exercises are in Answers to Selected Exercises.
Warm-up
13.1 ★ State three things error mitigation cannot do that error correction can. Then name one algorithm from Part IV that mitigation cannot help at all, and explain why in one sentence.
13.2 Build the $4\times4$ assignment matrix for qubits [122, 123]. Verify each column sums to 1.0 to within $10^{-9}$. Why must columns sum to 1 rather than rows?
13.3 ★ Build assignment matrices for three different qubit pairs and compare their condition numbers. Is a higher condition number always associated with worse readout error?
13.4 Show empirically that np.linalg.solve(A, p) and np.linalg.inv(A) @ p agree for a
well-conditioned matrix. Then construct a poorly-conditioned $A$ (hint: use qubits with readout errors
near 0.5) and show they diverge.
Readout mitigation
13.5 ★ Apply readout mitigation to a 3-qubit GHZ state on the best layout from Chapter 12. Report the L1 error before and after. How does the improvement compare to the 4× measured on a Bell state?
13.6 ★★ Mitigated probability vectors can contain negative entries, which are physically impossible. Construct a case that produces them (few shots and a poor pair will do it). Then implement two repairs: (a) clip to zero and renormalize, (b) solve the constrained least-squares problem $\min \|A\mathbf{p} - \mathbf{p}_{\text{obs}}\|^2$ subject to $p_i \geq 0$, $\sum p_i = 1$. Compare their accuracy.
13.7 ★★ Implement tensored mitigation: build one $2\times2$ matrix per qubit from just two calibration circuits (all-zeros and all-ones), and take the tensor product. Compare against the full matrix on 3 and 4 qubits. How much accuracy does the independence assumption cost, and how many circuits does it save?
13.8 ★★ §13.3 showed the stuck qubit's matrix has rank 2 instead of 4. Predict the rank of the assignment matrix for a 3-qubit layout containing exactly one stuck qubit, then verify. State the general rule relating rank deficit to destroyed qubits.
13.9 ★★ Write can_mitigate(backend, layout) that returns (True, "") or (False, reason)
without running any calibration circuits — using only calibration data. It should reject layouts
containing a stuck qubit. Verify it agrees with actually building the matrix and checking the rank.
13.10 ★★★ Readout error drifts. Build an assignment matrix, then build a second one an hour later (simulate by rebuilding with a different seed and adding a small perturbation). How stale can a calibration be before mitigation makes things worse? Design an experiment to answer this and report your criterion.
Zero-noise extrapolation
13.11 ★ Implement global folding and verify it is the identity: for factors 3 and 5, check that
Operator(fold(qc, f)).equiv(Operator(qc)).
13.12 Reproduce §13.5's decay for scale factors 1, 3, 5, 7 on a 4-qubit GHZ. Then extend to 9 and 11. Does the decay stay linear? At what point does extrapolation stop being justified?
13.13 ★★ Implement local folding (fold individual gates rather than the whole circuit) and compare to global folding at the same nominal scale factor. Which gives a cleaner decay? Which lets you access non-integer scale factors?
13.14 ★★ §13.5 found a readout floor of 0.03772 from a gate-free circuit. Predict that floor from calibration data alone — the readout errors of the four qubits — and compare to the measured value. (Hint: for $\langle ZZZZ\rangle$, each qubit's readout error flips the sign of that qubit's contribution.)
13.15 ★★ Run ZNE on a circuit whose error is entirely gate error by using a $\langle Z\rangle$ observable on a single qubit prepared in $|0\rangle$ after many identity-equivalent gate pairs. Does ZNE reach the true value now? What does this confirm about §13.5's decomposition?
13.16 ★★★ The three extrapolators agreed to 0.0009 in §13.5. Construct a circuit where they disagree by more than 0.05, and explain what property of the data causes the disagreement. Then state a threshold on the spread above which you would refuse to report a ZNE result.
Dynamical decoupling
13.17 ★ Reproduce §13.6's table. Confirm that the default configuration inserts fewer than ten
X gates into a depth-213 circuit and changes the result by less than $10^{-4}$.
13.18 ★★ Write dd_engaged(isa, isa_dd) returning a boolean and a diagnostic string, using the
count of inserted pulses relative to circuit depth. Choose a threshold and defend it.
13.19 ★★ Construct a circuit where the default DD configuration does engage — that is, where
the idle time falls after the qubits have been operated on. Confirm the pulse count jumps into the
hundreds without changing skip_reset_qubits.
13.20 ★★★ §13.6 argues DD cannot help under a Markovian noise model. Test this directly: build a
custom noise model with only thermal_relaxation_error (Markovian) and confirm DD does not help.
Then argue — without being able to simulate it — what a correlated-noise model would need in order for
DD to show a benefit.
Ordering and cost
13.21 ★★ Reproduce §13.7's central result: ZNE improves the raw value by ~14% and the readout-mitigated value by ~42%. Then run the two techniques in the wrong order (ZNE first, then attempt readout mitigation on the extrapolated value). Explain why that order is not merely worse but meaningless.
13.22 ★★ Compute the total shot cost of each row in §13.9's table for a 4-qubit circuit: raw, readout-mitigated, ZNE, and both. Express each as a multiple of the unmitigated cost. Then compute the error reduction per extra shot for each, and rank them.
13.23 ★★★ §13.9 claims fixing the layout is worth more than any mitigation technique and costs nothing. Test it: run the 4-qubit GHZ on the worst 4-qubit chain with the full mitigation stack, and on the best chain with no mitigation. Which wins? By how much? What does this imply about where to spend your effort?
13.24 ★★★ PEC's overhead scales as $\gamma^{2d}$. Using a plausible $\gamma$ derived from
FakeSherbrooke's median two-qubit gate error, compute the shot count PEC would require at depths 5,
10, 20, and 50 to achieve the same precision as 4096 unmitigated shots. At what depth does it exceed
the number of shots executable in a year?
Project
13.25 ★★ (Project Checkpoint) Build vqelab/mitigation.py with AssignmentMatrix (exposing
condition_number, rank, dead_qubits(), and refusing to apply itself when singular), fold(),
extrapolate() returning three methods plus their spread, and a MitigationRecord. Then write tests
asserting:
foldrejects even factors and ISA circuits.- Folding preserves the unitary (
Operator(...).equiv). extrapolaterecovers a known line exactly.- Extrapolator spread is larger for curved data than for linear data.
- The good-pair matrix has rank 4 and condition number below 1.5.
- Readout mitigation at least halves the L1 error on a Bell state.
- The stuck-qubit matrix has rank 2, reports qubit 84 dead, and raises on
apply. - ZNE improves a readout-mitigated value by more than twice what it improves a raw one.
Test 8 encodes the ordering result as an executable property — it is the one that would break silently if someone reordered the pipeline.
13.26 ★★★ Extend MitigationRecord into a full report generator: given a backend, circuit,
observable, and layout, produce a text report containing the layout and its score (Ch. 12), the
preflight result, the condition number, every intermediate expectation value, all three extrapolations
with their spread, the total shot cost, and the date. This is what "report the stack" means in
practice.