Answers to Selected Exercises

Worked answers to the daggered (†) and odd-numbered problems from every chapter's exercises.md. Where an exercise asks you to run something on hardware, the answer gives the reasoning and a representative result rather than a number you should expect to reproduce exactly — your run will differ, and understanding why it differs is the actual exercise.

Full runnable solutions to the programming exercises live beside each chapter in code/exercise-solutions.py.

Try the problem before you read the answer. Reading a worked solution feels like learning and is not.


Part I: Getting Started

Chapter 1 — The Quantum Programming Landscape

1.1 A quantum circuit is a sequence of unitary gates and measurements applied to qubits. Unlike a classical circuit it is reversible up to measurement, and its state is not observable — you get samples, not values.

1.5 There is no "Python of quantum" because the frameworks disagree about things that are not cosmetic: endianness, whether scheduling is explicit, and whether circuits are differentiable. Chapter 18 measured what those disagreements cost.

1.9 NISQ — Noisy Intermediate-Scale Quantum. Preskill's 2018 term for devices with enough qubits to be interesting and too much noise to be reliable. It is a statement about error rates, not qubit counts, which is why growing qubit counts have not ended it.

Chapter 2 — Setting Up

2.1 A virtual environment isolates package versions. It matters more than usual here because Qiskit, Cirq, and PennyLane have overlapping transitive dependencies and conflicting pins.

2.5 Roughly 50/50 between 00 and 11, with 01 and 10 appearing only from readout error. If you see substantial 01/10 on a simulator, the circuit is wrong, not the physics.

2.9 Shot noise. With 1,024 shots the standard error on a probability near 0.5 is about 0.016, so a measured 0.48 or 0.52 is entirely expected. Chapter 5 makes this quantitative.

Chapter 3 — Qubit Manipulation

3.1 $H$ maps $|0\rangle \to |+\rangle$ and $Z \leftrightarrow X$. It is self-inverse, so $HH = I$.

3.5 A global phase multiplies the whole state and is unobservable. A relative phase between amplitudes is observable via interference. The distinction becomes critical the moment a gate is controlled — a global phase on the target becomes relative on the control.

3.9p(λ) and rz(λ) differ by a global phase, which is invisible until either is controlled. cp and crz are genuinely different gates. This is one of the most common sources of a circuit that is "right" and produces the wrong answer.

Chapter 4 — Multi-Qubit Programming

4.1 $2^n$ complex amplitudes. At $n = 30$ that is over a billion — and Chapter 11 §11.2 measured the practical simulation limit at 30–35 qubits, which is where advantage claims become unverifiable.

4.5 A product state factorizes: $|\psi\rangle = |a\rangle \otimes |b\rangle$. The Bell state does not, which is the definition of entanglement. Check by computing the reduced density matrix — for a product state it is pure, for an entangled state it is mixed.

4.9 GHZ is maximally entangled and fragile: losing one qubit destroys all correlation. W is robust — losing one qubit leaves the rest entangled. Same entanglement "amount," different structure.

Chapter 5 — Measurement, Shots and Statistics

5.1 $\sigma = \sqrt{p(1-p)/N} \le 1/(2\sqrt{N})$. To halve the error you need four times the shots. This single formula generates every cost model in Parts IV–VII.

5.5 ★ Shot noise on a TVD scales as $\sim 1/\sqrt{N}$. Chapter 27 §27.5 measures GHZ(3) at 1,000 shots: mean TVD 0.01313, max over 40 runs 0.03700. A test with a tolerance of 0.05 is below the floor — it will fail on correct code about half the time, and tightening it further makes it worse rather than stricter. Chapter 27 builds on this.

5.9 Rotate before measuring. To measure $X$, apply $H$ then measure in the computational basis; to measure $Y$, apply $S^\dagger$ then $H$. Each distinct Pauli string needs its own basis, which is why Chapter 36 counts Hamiltonian terms rather than qubits.

Chapter 6 — OpenQASM

6.1 OpenQASM 3 adds real classical control flow — if, for, while, subroutines, and typed classical variables. That is what makes dynamic circuits (Chapter 9) expressible.

6.5 Custom gate definitions survive syntactically; the semantics your tool attached may not. Chapter 18 measured this as a leading cause of round-trip failure.

6.9 ★ A QASM file has no memory of physical qubits. It is a logical circuit. Chapter 39 §39.8 lists the nine fields a reproducible hardware result needs, and the circuit is one of them.


Part II: Qiskit in Depth

Chapter 7 — Qiskit Architecture

7.1 A DAG makes gate commutation and dependency explicit, which is what optimization passes need. A linear instruction list hides which gates could be reordered.

7.5apply_layout rewrites an observable to match a transpiled circuit's physical qubits. Forgetting it silently measures the wrong qubits — no error, just a wrong expectation value.

7.9 Sampler returns measurement outcomes; Estimator returns expectation values and owns term grouping, basis scheduling, and optionally mitigation. Chapter 24 §24.3's commuting-group optimization is a platform feature, and whether it ran is a setting you should know.

Chapter 8 — Building Complex Circuits

8.1 assign_parameters returns a new circuit unless inplace=True. Assigning and discarding the return value is a silent no-op.

8.5 A barrier is a transpiler directive, not a physical operation. It prevents optimization across a point — useful for preserving deliberately-inserted gates, which Chapter 25 needed for its noise slots.

8.9 Entanglement pattern (linear, circular, full) changes the two-qubit gate count and therefore the routing overhead. Chapter 39 measured a circular 14-qubit ansatz spanning 49 to 112 two-qubit gates across transpiler seeds.

Chapter 9 — Dynamic Circuits

9.1 Mid-circuit measurement plus classical feedforward. Without them, teleportation and repeat-until-success cannot be expressed as a single circuit.

9.5 Latency. The classical decision must round-trip through control electronics while the remaining qubits stay coherent, which is why feedforward is limited by $T_2$ and not by wall clock.

9.9 Qubit reuse: measure, reset, and use the qubit again. It trades width for depth, and the reset itself costs time — Chapter 39 measured 1,600–1,848 ns against a 68–184 ns two-qubit gate.

Chapter 10 — Transpilation

10.1 Layout (virtual to physical), routing (SWAP insertion), basis translation, and optimization. Routing is where the gate count grows.

10.5 ★ Level 0 does no optimization — use it when you need specific gates preserved. Chapter 25's noise-injection id gates were being removed at level 1 and above, producing a logical error rate of 0.0000 at every physical error rate, which is impossible.

10.9 seed_transpiler fixes the randomness in layout and routing heuristics. It does not fix the layout across calibration changes, because the cost function the heuristic minimizes depends on error rates that move. Chapter 39 Case Study 39.2 turns on exactly this.

Chapter 11 — Simulation and Noise Models

11.1 Statevector for exact pure states (~30–35 qubits); density matrix for mixed states at roughly half the width; MPS for low-entanglement circuits at 100+; stabilizer for Clifford-only at thousands.

11.5 Gottesman–Knill: Clifford circuits are classically simulable in polynomial time. This is why T gates are the expensive resource — they are precisely what takes you outside the efficiently simulable set, and Chapter 15 measured the cost.

11.9 NoiseModel.from_backend(backend) builds one from calibration data. It captures gate and readout error and misses crosstalk, drift, and correlated errors — so it is optimistic, and Chapter 28 found simulated and hardware fidelity diverging accordingly.

Chapter 12 — Running on Real Hardware

12.1 Write the decision procedure before you see results. Otherwise backend choice becomes a free parameter you tune until the answer looks good, which is not a measurement.

12.5 ★ A preflight check catches the failures that cost a queue wait: circuit width against device width, connectivity the layout needs, duration against $T_1$/$T_2$, and whether the qubits you would get are alive. Chapter 39 measured links with error 1.00 on a real device.

12.9 $T_1$ is energy relaxation, $T_2$ dephasing, and $T_2 \le 2T_1$ always. Chapter 39 measured $T_1$ spanning 15.2 to 483.0 µs on one chip — a factor of 32, which is why per-qubit calibration matters more than the chip average.

Chapter 13 — Error Mitigation

13.1 Mitigation reduces bias in an estimate by spending extra shots; correction fixes the state using extra qubits. Mitigation does not scale — the sampling overhead grows exponentially — and is what NISQ devices can actually do.

13.5 Zero-noise extrapolation amplifies noise deliberately (usually by gate folding $G \to GG^\dagger G$) and extrapolates to the zero-noise limit. It assumes the noise scales the way the folding models, which is the assumption to check.

13.9 ★ Readout mitigation inverts the assignment matrix, which is $2^n \times 2^n$ and becomes intractable quickly; M3 avoids forming it. And mitigation is not free: resilience_level defaults are not "none," so a quoted mitigated value needs its level stated alongside.


Part III: Other Frameworks

Chapter 14 — Google Cirq

14.1 ★ Cirq is big-endian, Qiskit little-endian. |01⟩ means qubit 1 is set in Cirq and qubit 0 is set in Qiskit. Reverse the bitstring when moving counts between them — and note that a Bell state looks identical under both, so the bug hides until you use an asymmetric state.

14.5 A Moment is an explicit set of simultaneous operations. Qiskit has no equivalent: its circuits are instruction lists that the transpiler schedules. Converting Cirq → Qiskit therefore loses the explicit timing, which Chapter 18 measured as the single largest translation loss.

14.9 LineQubit, GridQubit, NamedQubit — qubits are objects with device-relevant identity rather than integer indices. That is why Cirq circuits carry topology naturally and Qiskit needs a coupling map passed alongside.

Chapter 15 — Microsoft Q

15.1 use allocates in a scope and releases automatically — and the qubit must be returned to $|0\rangle$ first. Q# enforces at the language level what other frameworks leave as a convention.

15.5 Adjoint and Controlled are functors: the compiler derives the inverse and controlled versions of an operation automatically. No other framework in this book does this, and it is why Q# is pleasant for algorithm design and awkward for hardware work.

15.9450 physical qubits for a circuit with zero T gates; 2,882 with one. A 6.4× cliff from a single non-Clifford gate, because a T gate requires magic-state distillation and a T factory.

15.13T factories are 93% of a small circuit's physical qubits and 3% of a large one's. The fraction inverts with scale, because factory output is reusable and the algorithm's own logical qubits grow. Quoting either number without the scale is misleading in opposite directions.

15.17 ★★ The cost ranking is the exact reverse of the T-count ranking.

                        tCount   rotationCount   physical qubits   runtime
   (a) Toffoli              7          0              28,616        36.4 us
   (b) 3-controlled X       0         15             410,190       330.0 us
   (c) QFT(4)               0         18             497,310       330.0 us

CLIFFORD_T_BASIS contains rz, so the transpiler is free to stop at arbitrary rotations and never synthesizes them into T gates. Only the Toffoli — whose standard decomposition is literally written in H, CX and T — arrives with a T count at all. The two circuits reporting tCount == 0 are the two expensive ones, because each rz must eventually be synthesized to Clifford+T at roughly 126 T gates apiece (Chapter 19 §19.5 measures that constant), and the estimator prices rotationCount accordingly.

Re-pricing (c) with rotationCount forced to 0 — the mistake of reading only the tCount field — gives 750 physical qubits against the true 497,310, an understatement of 663×. A T count is not a summary of fault-tolerant cost; it is one of two inputs, and the circuits where it reads zero are exactly the ones where it misleads most.

Chapter 16 — PennyLane

16.1 The parameter-shift rule gives exact analytic gradients from two extra circuit evaluations per parameter — not a finite difference. It works because the expectation value is a trigonometric function of each parameter.

16.5qml.grad returns shape-(0,) gradients unless parameters are pennylane.numpy arrays with requires_grad=True. Plain NumPy produces no error and no gradient, which is the worst combination.

16.9 Gradient variance falls exponentially with width — the barren plateau. Chapter 32 measured 1.03e-01 → 1.17e-03 across 2 to 10 qubits, a factor of 88.

Chapter 17 — Amazon Braket

17.1 All-to-all connectivity means no routing overhead: the two-qubit gate count is what you wrote. The trade is speed — trapped-ion gates are ~1,000× slower — and price, which Chapter 39 measured at 28× per shot.

17.5 A verbatim box tells Braket to run the circuit exactly as written, without provider compilation. Necessary when you are benchmarking the device rather than the stack.

17.9 Analog Hamiltonian simulation programs the device by specifying a Hamiltonian rather than a gate sequence — the neutral-atom model. It is not a general-purpose gate machine, and comparing it on gate-model metrics measures the wrong thing.

Chapter 18 — Framework Comparison and Interoperability

18.1 ★ Endianness, scheduling model, and differentiability. Gate names are the easy part and the part everyone focuses on.

18.5 OpenQASM round-trips plain gate sequences reliably. It loses custom-gate semantics, pulse detail, unbound parameters, and — most importantly — transpiler layout. A QASM file is logical; it has no memory of which physical qubits ran it.

18.9 ★ Choose on: what hardware you target, whether you need differentiability, and whether explicit scheduling matters. Not on gate-name aesthetics. The honest finding of Chapter 18 is that the frameworks are more similar than the marketing suggests, and the differences that bite are the three above.

18.13 Because a translation that produces a circuit is not a translation that produces the same circuit. Verify by comparing statevectors or distributions, not by reading the output — Chapter 26 §26.9 builds the tool for this.


Part IV: Implementing Quantum Algorithms

Chapter 19 — Quantum Oracles

19.1 A phase oracle marks states by sign, $|x\rangle \to (-1)^{f(x)}|x\rangle$; a Boolean oracle writes $f(x)$ into an output register. Phase kickback converts the second into the first.

19.526,978 T gates with no ancillas; 55 with them. Ancillas are the trade worth making, and by a factor of nearly 500 at $n = 8$. Uncomputation is what lets you reclaim them without measurement.

19.9 Because the oracle must be built, and building it is where the cost went. Chapter 21 §21.7's point: an algorithm with a proven query-complexity separation says nothing about the cost of the queries.

19.13 Uncomputation reverses the intermediate work so ancillas return to $|0\rangle$ and can be released. Measuring them instead would collapse the superposition you were computing over.

Chapter 20 — First Quantum Algorithms

20.1 Deutsch–Jozsa: one query where classical needs $2^{n-1}+1$ in the worst case. The separation is real and rests on a promise — the function is guaranteed constant or balanced.

20.5 ★ The promise is what makes it easy, and real problems rarely come with one. This is why oracle separations are foundational and not directly applicable, and why Chapter 21 §21.7 matters.

20.9 Interference. Amplitudes for wrong answers cancel and amplitudes for right answers reinforce. Superposition alone buys nothing — a classical probabilistic algorithm also explores many branches.

Chapter 21 — Grover's Algorithm

21.1 $\approx \frac{\pi}{4}\sqrt{N}$ iterations. Fewer under-rotates, more over-rotates and moves away from the answer.

21.5 ★ At $N = 16$: 3 iterations gives success probability 0.9613, 6 gives 0.0204. Doubling the "effort" destroyed the result. Grover is not a technique where more is safer.

21.9 ★ A 20-bit search: 229,944 T gates across 804 iterations. The quadratic speedup is real and the constants are enormous, because each iteration contains a full oracle and diffuser.

21.13Grover does not search a database. It queries an oracle you must already be able to construct. If you have the data in a structure you can query classically, you have already paid the cost Grover assumes away — and Chapter 39's queue and Chapter 15's T-gate overhead sit on top.

Chapter 22 — Quantum Fourier Transform

22.1 $\mathcal{O}(n^2)$ gates against the classical FFT's $\mathcal{O}(N\log N) = \mathcal{O}(n2^n)$ — exponentially fewer operations.

22.5 ★ And it is not an exponential speedup, because the result is in amplitudes you cannot read out. Extracting all $2^n$ of them takes exponentially many measurements. The readout problem is the whole story, and it is the same shape as Chapter 32's input problem at the other end.

22.9 ★ Phase estimation is exact for dyadic phases — $\varphi = 0.5, 0.25, 0.125$ returned with zero error. Non-dyadic phases spread over neighbouring outcomes and need continued fractions.

22.13 ★ At $n = 8$, cutoff 3 gave 97% fidelity for 36% of the rotations. The small controlled rotations contribute least and cost the same, so dropping them is nearly free — one of the cleanest approximations in the book.

Chapter 23 — Shor's Algorithm

23.1 Factoring reduces classically to order finding; only the order finding is quantum. Most of Shor's algorithm is number theory.

23.5 ★ Factoring 15 with $a = 7$, $t = 8$: exactly four outcomes near 25% each, corresponding to $s/r$ for $r = 4$. The measured histogram matches the prediction with no fitting.

23.9 ★ Randomized on two levels: the choice of $a$ (50–86% usable depending on $N$) and the measurement outcome ($s = 0$ always occurs and is always useless). A single run failing is expected behaviour, not a bug.

23.13 Modular exponentiation dominates — it is the bulk of the circuit and the reason resource estimates for RSA-2048 run to millions of physical qubits. The QFT is the cheap part.

Chapter 24 — Variational Algorithms

24.1 ★ VQE works. On H₂ (STO-3G, 0.735 Å, two qubits), a four-parameter ansatz from the Hartree–Fock reference reaches chemical accuracy. The variational method is not the weak link — Chapter 36 measures what is.

24.5 ★ $N \sim (\sigma/\epsilon)^2$. Chemical accuracy needs ~97,657 shots per energy evaluation, multiplied by the number of Hamiltonian terms, by $2p+1$ for the gradient, by the iteration count. This is where Chapter 36's $1.91\times10^{20}$ comes from.

24.9 ★ At $p = 1$, QAOA scores 0.8086 against Goemans–Williamson's 0.8785 — below a polynomial-time classical guarantee from 1994. Chapter 37 runs the full comparison and finds QAOA winning 0 of 10 instances.

24.13 Grouping commuting terms into shared measurement bases. It is a large constant factor (~100×) against an exponent, which is Chapter 36 §36.7's point: every remedy is denominated in the currency of the disease.

24.17 Three barriers: the shot budget ($1/\epsilon^2$), barren plateaus (gradients vanishing with width), and hardware noise. Chapter 36 measured the first binding by a factor of $10^8$ before the others become relevant.


Part V: Quantum Software Engineering

Chapter 25 — Quantum Error Correction in Code

25.1 Three physical qubits per logical qubit, and it corrects any single bit flip. It corrects zero phase flips — $Z$ commutes with the stabilizers, so the syndrome is blind to it by construction.

25.3 Because the decoded logical error is an $X$, and $X|+\rangle = |+\rangle$. The chapter measured 0.0000 logical error at every physical error rate while storing $|+\rangle$ in the phase-flip code, which looked like a spectacular result and was a blind measurement. Store a state the error can move.

25.7 ★ At optimization_level=1 and above the transpiler removes id gates, which is where the noise was being injected — so the measured logical error was 0.0000 even at $p = 0.60$. Use optimization_level=0 and assert the gate count survived. A physically impossible result is the cheapest bug to find; trust it less than a plausible one.

25.11 The blind cells are mirrored between the two codes: what the bit-flip code cannot see, the phase-flip code can, and vice versa. That is the whole motivation for concatenation and, eventually, for CSS codes.

25.15 Below break-even, encoding makes things worse: three physical qubits each failing at $p$ give a logical failure rate above $p$ until $p$ is small enough that two-error events dominate. Measure the crossing rather than assuming it.

Chapter 26 — Debugging Quantum Programs

26.1 Statevector.from_instruction fails on any circuit containing a measurement, because the state is no longer a pure state. Remove measurements, or use save_statevector before them.

26.5 ★ Bisection found nothing on 0 of 100 random states, 4 of 8 basis states, and 11 of 27 structured states. The technique's sensitivity depends entirely on the input state, and a bug invisible from $|000\rangle$ can be glaring from $|1{+}0\rangle$. The answer is not "bisection does not work" — it is that a negative bisection result is not evidence of correctness.

26.9 Operator.from_circuit applies both layout and routing, so it can compare a transpiled circuit to its source. Above ~14 qubits the $2^n \times 2^n$ matrix stops being practical, which is why verify_transpilation raises past OPERATOR_QUBIT_LIMIT rather than quietly taking an hour.

26.13 The seam. Both pieces of work were individually correct; the failure lived in the composition, and neither person's tests covered it. Chapter 36 Case Study 36.1 is the same failure in chemistry.

Chapter 27 — Testing Quantum Programs

27.1 $\sim 1/\sqrt{N}$. Measured on GHZ(3) at 1,000 shots: mean 0.01313, max over 40 runs 0.03700. A TVD tolerance of 0.02 sits between the mean and the max, so it fails on correct code some fraction of runs; anything below the max column fails at least occasionally.

27.3 ★ The chapter first reported a 1.0% false-failure rate from 2 failures in 200 runs. Re-run at 2,000 and 3,000 runs it was 0.150% and 0.100% — off by a factor of about 6.7. Two events is not a rate. This is the first of seven such errors in the book.

27.7 Two error rates, and they trade against each other: the flakiness rate (fails on correct code) and the blindness rate (passes on broken code). Tightening the tolerance lowers one and raises the other. A test suite quoting only one of them is quoting the flattering one.

27.9 h(0) and ry(π/2, 0) produce the same distribution and consume the random stream differently, so seeded runs diverge. Metamorphic tests that compare "equivalent" circuits must either fix the gate sequence or compare distributions rather than samples.

27.13 Cache the transpiled circuit outside the measurement loop. The chapter's example took over ten minutes because it re-transpiled on every iteration — the measurement was of the transpiler, not of the thing under test.

Chapter 28 — Circuit Optimization

28.1 Gate count is a proxy. Fidelity is the thing. A pass can reduce two-qubit gates and increase depth, or vice versa, and only a fidelity measurement settles which mattered.

28.5 ★ The chapter first concluded levels 2 and 3 were identical from two circuits. Widened to five circuits × eight seeds, they differ in 14 of 40 pairs, with level 3 better in 12. The corrected statement is that level 3 usually helps, sometimes does not, and the difference is smaller than seed-to-seed variation.

28.9 approximation_degree=0.9 produced zero two-qubit gates — the pass discarded the entanglement entirely. It is doing exactly what it says; "approximation" is not a synonym for "optimization," and the setting needs a fidelity check attached.

28.13 basis_gates=['h','barrier'] raises in Qiskit 2.5 — a barrier is a directive, not a gate. Pass-manager introspection needs a recursive .tasks flatten, because passes nest.

Chapter 29 — Hardware-Aware Programming

29.1 coupling_map.neighbors() is directed. Treating it as undirected made 29 qubits on a 133-qubit device appear to have no neighbours at all. Union both directions, or use the undirected graph.

29.5 ★ Hardware-aware layout at optimization_level=1 scored 0.9116 against naive optimization_level=3's 0.7720 — +0.1397. Choosing the right qubits beat three levels of transpiler effort on the wrong ones.

29.7 A hand-picked connected chain [7,6,5,4,3,2] scored 0.6790 against the transpiler's choice. Connectivity is necessary and not sufficient — the transpiler was also reading error rates. Re-picking with calibration data gave a chain at 0.9764.

29.11 Because the platform assigns physical qubits at execution time, using calibration that may have refreshed since you submitted. Chapter 39 §39.6 measured the consequence: a 2.03× fidelity spread from the transpiler seed alone.

Chapter 30 — Benchmarking Quantum Hardware

30.1 Randomized benchmarking twirls over the Clifford group, which converts an arbitrary error channel into a depolarizing one. That is what makes the decay a single exponential and the fitted parameter interpretable — and it is also why RB says nothing about non-Clifford errors.

30.5 ★ The same chip supported quoted two-qubit errors from 0.00750 to 0.07205 — a factor of 9.6 — depending on whether you quote the best link, the median, or the mean, and whether you include dead links. quoted_fidelity(dist, statistic, include_dead) takes both arguments with no defaults for exactly this reason.

30.9 The median predicted Chapter 28's measured circuit fidelity to within 12%; the best-link figure did not come close. A device metric is only predictive if its statistic matches how your circuit uses the device.

30.13 Quantum Volume saturates — it is a single number combining width and depth, and two devices with the same QV can behave very differently on your circuit. CLOPS attempts throughput, which Chapter 39 showed is the quantity that actually dominates wall clock.

Chapter 31 — Pulse-Level Programming

31.1 qiskit.pulse was removed in Qiskit 2.0, along with QuantumCircuit.add_calibration, .calibrations, backend.defaults(), instruction_schedule_map, and drive_channel. Any tutorial using them predates the removal.

31.3 rz is a virtual Z: the rotation is applied by shifting the phase of subsequent pulses rather than by playing one. It is exact and takes 0.0 ns, which is why physical single-qubit sequences are $R_z$–$\sqrt{X}$–$R_z$–$\sqrt{X}$–$R_z$ and only the $\sqrt{X}$ pulses cost time.

31.7 ★ Dynamical decoupling measured significantly worse: XX at $-0.0053 \pm 0.0012$, 4.4 standard errors in the wrong direction. The technique is real and helps in the regime it was designed for; on these circuits the added pulses cost more than the idle dephasing they suppressed. A standard technique applied without measurement is an assumption.

31.11 Circuit duration against $\min(T_1, T_2)$. evaluate_dynamical_decoupling returns NOT_EVALUABLE when the circuit has no idle windows long enough for the sequence to matter — a refusal, not a null result.


Part VI: Quantum Machine Learning

Chapter 32 — QML Fundamentals

32.1 Amplitude encoding packs $N$ values into $\log_2 N$ qubits — exponentially compact in qubits and requiring $\mathcal{O}(N)$ gates to prepare. The compression is real and the preparation destroys it. That is the input problem in one line.

32.3 ★ On iris-binary, LogisticRegression, SVC and RandomForest all reach 100% test accuracy, in milliseconds. The 4-qubit, 24-parameter VQC also reaches 100%, in 50.2 s on an exact simulator. A tie on a solved problem is not evidence of anything — pick a dataset the baseline does not already saturate.

32.7 ★ Gradient variance fell from 1.03e-01 to 1.17e-03 across 2 to 10 qubits — a factor of 88. That is a barren plateau, measured rather than cited. Extrapolating, gradients become unresolvable against shot noise well before the qubit counts anyone proposes for useful QML.

32.11 PennyLane's qml.grad returns shape-(0,) gradients unless the parameters are pennylane.numpy arrays with requires_grad=True. Plain NumPy arrays produce no error and no gradient.

32.15 The encoding cost is $N - \log_2 N - 1$ gates against the $\log_2 N$ qubits saved. EncodingCost reports both, because reporting qubits alone is how amplitude encoding gets described as free.

Chapter 33 — Quantum Classifiers

33.1 Data re-uploading interleaves data encoding with trainable layers, so a single qubit becomes a universal function approximator (Pérez-Salinas et al.). Depth substitutes for width.

33.5 ★ On one split, the quantum model appeared to beat logistic regression. Across ten splits the gap collapsed to +0.0202 ± 0.0170 — not significant. And kNN beat the quantum model by +0.0626 ± 0.0067, which is significant, at nine standard errors. The same experiment produced one gap that survives its uncertainty and one that does not.

33.927.8 QPU hours per million predictions at 1,000 shots, and 277.8 at 10,000. Inference, not training, is where a deployed quantum model would spend its budget — and it is the number almost no QML paper reports.

33.13 Looping sample-by-sample through a QNode timed out at ten minutes. PennyLane broadcasts over a leading batch axis; batched, the same evaluation took seconds — roughly 100× faster.

33.17 compare_models returns INSUFFICIENT_REPLICATES below MIN_SPLITS = 5. That is a different answer from "no difference," and conflating them is exactly how 33.5's first version happened.

Chapter 34 — Quantum Kernels

34.1 Unit diagonal ($K(x,x) = 1$), symmetric, and positive semidefinite. A matrix failing any of these is not a kernel, and an SVM given one will train to something meaningless rather than error.

34.5 ★ The chapter predicted that concentration would cause memorization and measured test accuracy rising, 0.7778 → 0.8889. The root cause: concentration is driven by feature dimension, not qubit count, so adding qubits at fixed dimension did not produce the predicted effect. Both measurements are in the chapter, because the failed prediction is the more instructive one.

34.9 ★ Feature-map tuning moved accuracy from 0.6364 to 0.8500a larger swing than quantum-versus-classical anywhere in Part VI. A comparison that varies the feature map while claiming to compare methods is measuring hyperparameters.

34.13 $n^2$ — every pair needs a circuit evaluation. That is what convex training cost: Chapter 33's variational model trains in time linear in dataset size and has a non-convex landscape; the kernel has a unique optimum and a quadratic bill.

34.17 Across ten splits: quantum kernel 0.8313 ± 0.0381, SVC(rbf) 0.8889 (kNN, a different model class, scores 0.8970). The classical kernel wins, on the same solver, with the same data, differing only in the kernel function.

Chapter 35 — Hybrid Architectures

35.1 When the data is already a quantum state — from a sensor, an experiment, or another quantum computer — there is nothing to encode. Chapter 32's input problem disappears entirely, which is why this is the surviving case for QML.

35.5 ★ The first comparison gave direct estimation the same shots per observable, which silently handed it 17× the total budget. At equal total budget, classical shadows win by 1.5–1.8×. The correction inverted the conclusion, and it is the same error Chapter 37 §37.5 warns about when comparing two randomized algorithms.

35.9SVC(rbf) on the same states' measurement probabilities scored 0.7857 against the quantum model's 0.6429. Even on quantum data, a classical model reading the measurement outcomes won.

35.13 Below ~32 qubits the state is classically representable, so quantum_data_verdict returns CLASSICALLY_CHECKABLE rather than an advantage claim — and names the state's size in reals. A result you can verify classically is not evidence of quantum advantage; it is evidence the code works.

35.17 Shadows are ~2.5× less accurate per observable and win on total budget because they estimate many observables from the same measurements. The advantage is in the $\sqrt{}$ of the observable count, not in per-observable precision — which is why the fair comparison had to fix the budget, not the accuracy.


Part VII: Applications and Career

Chapter 36 — Quantum Chemistry with VQE

36.1 18 qubits. One qubit per spin orbital, so twice the spatial orbitals.

36.5 ★ "14 qubits, so BeH₂ or H₂O — same size" is wrong. Both need 14 qubits and their Hamiltonians differ by 420 terms (666 vs 1,086), because the electron count decides how many four-index integrals survive. Device capability is quoted in qubits; the shot bill is denominated in terms. A device sized in qubits is not a device sized for a molecule.

36.9 Both mappings give 631 terms for LiH. Bravyi–Kitaev reduces Pauli weight — mean 6.16 → 5.62, max 12 → 10 — which sets measurement-circuit depth per term. The improvement is modest at 12 qubits because the $\mathcal{O}(n)$ versus $\mathcal{O}(\log n)$ separation needs more qubits to show.

36.13 The Pauli principle. Two orbitals is four spin orbitals, which hold at most four electrons.

36.16 The strongest supportable claim is: "within a (6e,6o) active space, VQE converged to within X of that space's exact answer." Nothing about the molecule follows, because the paper never measured the truncation error. That is not a small omission — Chapter 36 measured one at 9,870,104× the VQE error.

36.19 ★ The ratio was 9,870,104. Running VQE with 20 optimizer steps instead of 120 makes the VQE error larger and the ratio smaller — and the conclusion is unchanged, because the active-space error is seven orders of magnitude away. A worse optimizer does not rescue a wrong Hamiltonian.

36.24 Below ~10 orbitals the answer is exactly computable classically in seconds, so a quantum result is a demonstration rather than a computation. Above ~20, full CI is out of reach and CCSD(T) is the method anyone would actually run — so it is the baseline that matters.

36.28 At 50 orbitals VQE needs $1.91\times10^{20}$ shots — 6.06 × 10⁸ QPU-years. Every mitigation in the book stacked (grouping 100×, shadows 60×, ADAPT 10×, low-rank 10×) gives ~6 × 10⁵×, leaving ~10³ QPU-years. Four orders of magnitude of remedy against eight of deficit.

Chapter 37 — Quantum Optimization with QAOA

37.1 7.5/15 = 0.5 of the edges; 7.5/13 = 0.577 of the optimum. A paper should report the ratio to the optimum and say so explicitly — and ratio_denominator raises without an explicit "edges" or "optimum" because these get swapped constantly.

37.7 $2p$ — one $\gamma$ and one $\beta$ per layer. Far fewer than any Part VI ansatz, which is the design's real virtue.

37.13 ★ QAOA at $p=4$ contains $p=3$: set the two extra angles to zero and you recover it exactly. So the $p=4$ optimum is at least the $p=3$ optimum, always. A measured regression is therefore a statement about the optimizer, not the ansatz — a different claim needing different evidence.

37.14 ★ Drawing one value from each of the measured per-seed lists, $p=4$ appears worse roughly a quarter of the time. That is the probability the book's original single-seed table was going to mislead, and it did.

37.19 Because QAOA's sample and GW's rounding are the same kind of thing — both are randomized algorithms producing a distribution. Giving QAOA many samples and GW one is Chapter 35 §35.5's error with a graph attached.

37.21 The mean $E[\text{cut}]/\text{OPT}$ of 0.891 describes the state QAOA prepared; the single sample is the answer a user receives. Instance 9 had a mean of 0.922 and returned a cut of 9 against an optimum of 13. A distribution with a good mean still returns bad individual answers.

37.26 None. Returning 1.0 would assert a bound that does not exist, and None is the honest representation of "no certificate." Nothing in a QAOA output distinguishes a cut of 9 from an optimal 13.

Chapter 38 — Quantum Cryptography and BB84

38.3 Half the time Eve guesses Alice's basis and learns the bit with no trace. Half the time she guesses wrong, collapses the state into her basis, and the forwarded photon is uncorrelated with Alice's bit — so Bob is wrong half of those. $\frac12 \times \frac12 = 25\%$. Measured: 0.2398.

38.9 Error correction leaks information over the public channel (one $h_2(Q)$); privacy amplification must then remove what an eavesdropper could know (the second). Hence $r = 1 - 2h_2(Q)$.

38.11 It is insecure by definition, and the protocol is not broken. All error must be attributed to Eve because nothing distinguishes her from a dusty connector — so a 12% intrinsic QBER means nobody can prove she is absent, not that she is present.

38.1437 test bits at 95% confidence. At 99% it is roughly 65 — and every test bit is announced publicly and discarded, so detection is bought out of key material.

38.16 Because at $f = 0.30$ the QBER is genuinely below the abort threshold. No sample size distinguishes a distribution from itself. The protocol correctly proceeds, and privacy amplification shortens the key by what an adversary at that QBER could know.

38.20 ★ Eve runs BB84 with Alice pretending to be Bob, and separately with Bob pretending to be Alice. Both links are physically pristine and both parties measure a clean QBER. No-cloning has nothing to say, because nothing was cloned. QKD consumes authentication; it does not create it.

38.25 No-cloning forbids copying a photon, so there is no amplifier and no repeater without quantum memory. The theorem that provides the security imposes the range limit — measured at 240.4 km.

Chapter 39 — Quantum Cloud Platforms

39.2 It is a virtual Z, applied as a phase shift on subsequent pulses rather than as a played waveform. Chapter 31 measured it at 0.0 ns.

39.7 A 43.20 ms job at a 120-second queue: utilization $\approx 3.6\times10^{-4}$, wall clock $\approx 2,780\times$ device time.

39.13 Because the circuit duration is the conversion factor between a per-shot and a per-minute price. Without it the two models are not comparable, and Chapter 39 measured the gap at 149× and 3,718× for the same job.

39.17 The circuit duration, the shot count, and the task count. A per-shot model charges the same for a 1.69 µs Bell circuit and a 10.55 µs QFT; a per-minute model charges 6× more for the second.

39.24 ★ A 4-qubit chain fits the coupling map without any routing, so every transpiler seed finds the same layout and the measured variance is exactly zero. A team testing there concludes the seed does not matter — a true measurement of a false general claim. At 14 qubits the same test gives 2.03×.

39.29 Because four of the fields that determine the result — job ID, execution timestamp, calibration snapshot, physical qubit assignment — come from the provider at execution time and are not in your source. A pinned environment and a fixed seed pin the client side of a computation whose variance lives on the server side.

39.34 ★ Chapters 27, 28, 33, 34, 37, and 38 were all too few samples. Chapter 39's had 24 samples and the wrong system. A measurement can be too small in more than one dimension, and sample size is only the most obvious one.

Chapter 40 — The Quantum Programming Career

40.2 Zero. Five accuracy comparisons gave one exact tie and four classical wins; Chapter 37's ten MaxCut instances gave QAOA 0 wins, GW 6, and 4 ties.

40.8 Because nobody runs full CI past ~20 orbitals — it is exponential. Beating it at scale is impossible to demonstrate and irrelevant if you could: the method a chemist would actually run is CCSD(T). This is Chapter 21 §21.7's lesson with a molecule attached.

40.9 A standard error of exactly zero means the uncertainty was never estimated, not that it is absent. Returning True there would be the book's single-sample error with extra steps.

40.11 audit_claim returns failures because a claim that cannot name its baseline is not fractionally correct — it is unevaluable. Case Study 40.2 supports this: Chapter 36 passing 7/8 has a specific, nameable, fixable gap; a vendor claim passing 1/8 cannot be evaluated at all, and averaging those would be the last instance of the error the book is about.

40.16 Largest: control software and compiler engineering. Smallest: algorithm theory — the role people imagine when they hear "quantum job."

40.28 It protects against a capstone written from memory. If §40.3 quotes a number that is not in the chapter that measured it, the test fails. It would break if a chapter were edited to change a measured value without updating the summary — which is exactly the failure it exists to catch.

40.29 More. A checklist that never fails its author's own work is a checklist that is not being applied. The value is that the failures are specific: "Chapter 36 needs more geometries" and "Chapter 39's queue is assumed, not measured" are actionable, where "approximately trustworthy" is not.