Part IV · Learning with Amplitudes · Chapter 16
Training Quantum Models
Freeze nothing: make the circuit's gates trainable and learn them end-to-end. The gradient is exact and beautiful — and then, at scale, a wall appears that no amount of cleverness fully removes.
Sources: Schuld & Petruccione, Chs. 7–8 · McClean et al. (2018) · Cerezo et al. (2021)
Chapter 15 fixed the circuit and only chose a kernel. The other road — the one that looks most like a neural network — makes the gates themselves adjustable parameters and trains them by gradient descent, exactly as in Chapter 14. Two things make this story worth telling honestly. The gradient of a quantum circuit turns out to be exactly computable from two runs of the same circuit — the parameter-shift rule, one of the field's most elegant results. And then the barren-plateau problem shows that this beautiful gradient becomes exponentially small as the machine grows, which is the single most important cautionary fact in quantum machine learning. The plateau theorem rests on a precise notion of what a “random circuit” is — the Haar measure, and its finite shadows, unitary 2-designs — so this chapter defines both, builds a sampler the lab certifies to be Haar rather than merely asserting it, and then measures the plateau against the theorem's own closed-form prediction.
What this chapter covers
- 16.1The variational classifier. Feature-map encode, a trainable ansatz U(θ), measure an observable → a prediction to train.
- 16.2The parameter-shift rule. An exact gradient of a quantum circuit from two shifted evaluations — no finite differences.
- 16.3Training it. Gradient descent on the circuit's angles; the loss falls and the classifier learns.
- 16.4Haar and 2-designs. What 'uniformly random unitary' means, what a t-design is, and a wrong sampler that covers all of SU(2) yet fails the second moment.
- 16.5Barren plateaus. For 2-design ansätze the gradient variance vanishes exponentially — here in closed form: one bit per qubit.
- 16.6Fighting the plateau. Local cost functions (Cerezo et al.), structured ansätze, warm starts — partial, honest remedies.
- 16.7The Lab. A VQC trained by parameter-shift, a Monte-Carlo Haar certificate, and a measured plateau graded against the 2-design closed form.
16.1The variational quantum classifier
F · FormalismC · ConceptsA variational quantum classifier is three stages. First, encode the data with a feature map (Chapter 15). Second, apply a trainable ansatz — layers of single-qubit rotations and entangling gates whose angles are the model parameters. Third, measure an observable (say on one qubit) to read out a prediction . Training means adjusting to minimize a loss over the data, exactly the gradient-descent loop of Chapter 14 — only now the model is a quantum circuit.
16.2The parameter-shift rule
F · FormalismTo train by gradient descent we need . A finite difference would work but is noisy and inexact. The parameter-shift rule gives the gradient exactly. For a gate with (any Pauli rotation), the derivative of an expectation value is a rescaled difference of the same circuit evaluated at two shifted angles:
This is not an approximation — the shift is a full , and (16.1) holds identically for any , because a single Pauli-rotation angle enters every expectation value as a pure sinusoid , and two evaluations a half-period apart reconstruct a sinusoid's derivative exactly. The gradient of a circuit is computed by running the circuit, twice per parameter — hardware can do it directly. The lab verifies (16.1) against a central finite difference on the real training loss: the two gradients agree to 1.5e-9 (referee tolerance 3.0e-9), and the residual is the finite difference's own truncation error, not the shift rule's.
16.3Training it
C · ConceptsP · PracticeWith an exact gradient in hand, training is ordinary gradient descent: . On a learnable dataset the loss falls and the classifier reaches high accuracy — scrub the run:
So far this looks exactly like classical machine learning with a fancier model. The trouble appears only when we ask what happens as the model grows — and to even state that result precisely, we need to say what “a random circuit” means.
16.4Haar randomness and unitary 2-designs
F · FormalismC · ConceptsThe Haar measure on a compact group of unitaries is the unique probability measure invariant under multiplication by any fixed group element: if is Haar-distributed, so are and for every fixed . It is the only meaning of “uniformly random unitary,” the exact analogue of the uniform distribution on a circle. Sampling from it exactly is easy for one qubit and exponentially expensive for many — which is why the field works with finite stand-ins. An ensemble of unitaries is a unitary -design when it reproduces the Haar average of every polynomial of degree at most in the entries of and degree at most in their conjugates:
i.e. its first moments are exactly Haar's, even though the ensemble itself can be a small finite set. The -qubit Pauli group is a 1-design (it matches Haar's first moment but not the second); the Clifford group is a 2-design. A 2-design is precisely the amount of randomness that second-moment quantities — variances, purities, and, crucially, gradient variances — cannot tell apart from Haar.
The distinction has teeth, and the sharpest way to feel them is a mistake this book's own lab shipped before its audit. Take the general single-qubit rotation in ZYZ Euler form, , and draw all three angles uniformly. Every element of can be produced this way — the ensemble covers the whole group — and its first moment is Haar's: the amplitude averages to . But covering a group is not sampling it uniformly. Haar measure on in these coordinates is — the same that makes the poles of a sphere carry less area than its equator — so the middle angle must be drawn with uniform on , not uniform. The second moments differ:
Uniform- sampling is a 1-design and not a 2-design: it over-weights rotations near the poles, piling up near 0 and 1, where Haar spreads it flat:
The fix is one line — draw with , which makes exactly uniform — and the lab refuses to take it on faith. A Monte-Carlo referee over 400,000 sampled blocks demands within its own statistical error (measured: 0.333087, off by 0.52σ); a second referee checks the frame potential , which obeys for every ensemble with equality if and only if it is an exact 2-design (measured: 1.9789, off by 3.01σ). Re-running the lab with the uniform- sampler makes both referees fail loudly — the fourth moment lands on 3/8, more than 70σ away — while the 1-design referee still passes, which is the whole distinction of this section compressed into a scoreboard.
1/// The three Euler angles of a HAAR-RANDOM SU(2) rotation R_Z(c) R_Y(b) R_Z(a).2///3/// Haar measure on SU(2) in ZYZ Euler angles is dμ ∝ sin(b) db da dc, so the4/// OUTER angles are uniform (a, c ~ U[0, 4π), the full 4π period of a spin-½5/// rotation) but the MIDDLE one is not: cos b must be uniform on [-1, 1].6/// Inverting that CDF gives b = 2·arccos(√u) with u ~ U[0, 1), which is exactly7/// the statement that |U_00|² = cos²(b/2) = u is uniform on [0, 1] — the Haar8/// distribution of a single amplitude of a random qubit rotation.9///10/// Sampling b uniformly instead yields E|U_00|⁴ = 3/8 rather than Haar's 1/3:11/// a 1-design, NOT the 2-design McClean et al. assume. Referees 6-8 certify the12/// difference; see the header for the falsification run.13fn haar_su2_euler(rng: &mut StdRng) -> [f64; 3] {14 let a = rng.gen_range(0.0..(4.0 * PI));15 let u: f64 = rng.gen_range(0.0..1.0);16 let b = 2.0 * u.sqrt().acos(); // cos b uniform on [-1, 1]17 let c = rng.gen_range(0.0..(4.0 * PI));18 [a, b, c]19}
16.5Barren plateaus
F · FormalismC · ConceptsHere is the wall. McClean et al. (2018) proved that when the pieces of a random parameterized circuit on either side of the differentiated gate match Haar's second moments — the 2-design hypothesis of §16.4, which random hardware-efficient ansätze approach at depth growing linearly in (Brandão, Harrow & Horodecki 2016) — the gradient of the cost has mean zero and a variance that vanishes exponentially in the qubit count. For our global parity cost the Haar averages can be carried out in closed form (the lab's header does it with the two-copy twirl), and with :
Not a vague “exponentially small” — one bit of gradient variance per qubit, prefactor included. The expected gradient is zero and its fluctuations are exponentially tiny, so the cost landscape is an almost perfectly flat barren plateau: everywhere you stand, the slope is indistinguishable from zero to any realistic number of measurement shots. Gradient descent has nothing to descend. This is not a bug in the optimizer — it is a property of the geometry of large random circuits, and it is the central obstacle to scaling variational quantum learning. The lab measures it directly: the fitted decay over is 2^(−0.976·n), against the closed form's 2^(−0.985·n) over the same range, with R² = 0.9997.
cargo run --release in Rust-QML/ch16-vqc)One honest footnote from the audit that fixed the sampler: with the wrong (uniform-) single-qubit blocks, the measured plateau barely moves. At depth the circuit as a whole still scrambles into an approximate global 2-design, because the blocks remain a universal gate set — the 2-design hypothesis is about the assembled circuit, and deep composition repairs a biased ingredient. What the wrong sampler actually broke was the claim: the lab asserted its blocks were Haar when they were provably not, and no referee was watching. The certificate of §16.4 exists so that the theorem's hypothesis is measured, not narrated.
16.6Fighting the plateau
F · FormalismThe plateau is not always fatal, and the escapes are instructive — each one works by breaking a hypothesis of the theorem. Local cost functions: Cerezo et al. (2021, Nature Communications) sharpened the picture along an axis McClean et al. never drew — the choice of observable. For a global cost like , whose operator touches every qubit, the plateau strikes even shallow circuits; but for a local cost — a sum of few-qubit observables — gradients shrink at worst polynomially as long as the depth stays . The differentiated gate then only needs to fight the randomness inside its own small light cone, not the whole exponential Hilbert space. Shallow or problem-structured ansätze — ones that encode the symmetry of the task rather than generic randomness — stay far from the 2-design regime of §16.4, so the theorem's hypothesis simply never applies to them. Good initialization (identity-block or warm-start strategies, which start the circuit near the identity instead of deep in scrambled territory) and layerwise training help for the same reason. But none is a general cure: the honest statement is that trainability at scale is an open problem, and any claimed quantum-learning advantage must show it survives the plateau.
The lab has four instruments, each with referees that would fail loudly if the physics were wrong. The zeroth is the simulator itself: every circuit is run twice, once on the in-place bit-mask simulator and once through dense Kronecker products of textbook gate matrices — two code paths that share nothing and must agree on every amplitude. The first trains the variational classifier with the exact parameter-shift gradient and checks it against a finite difference:
1/// EXACT loss gradient by the parameter-shift rule. For each parameter,2/// ∂L/∂θ_k = (2/N) Σ_i (p_i − y_i) · ∂p_i/∂θ_k,3/// ∂p_i/∂θ_k = ½[ p_i(θ + π/2 e_k) − p_i(θ − π/2 e_k) ].4/// Every shifted evaluation is an ordinary circuit run — no step size.5fn param_shift_grad(data: &[([f64; 2], f64)], theta: &[f64]) -> Vec<f64> {6 let n = theta.len();7 let mut t = theta.to_vec();8 let mut g = vec![0.0; n];9 // Cache residuals (p_i − y_i) at the current θ.10 let res: Vec<f64> = data.iter().map(|(x, y)| predict(x, theta) - y).collect();11 for k in 0..n {12 let orig = t[k];13 let mut acc = 0.0;14 t[k] = orig + FRAC_PI_2;15 let plus: Vec<f64> = data.iter().map(|(x, _)| predict(x, &t)).collect();16 t[k] = orig - FRAC_PI_2;17 let minus: Vec<f64> = data.iter().map(|(x, _)| predict(x, &t)).collect();18 t[k] = orig;19 for i in 0..data.len() {20 let dp = 0.5 * (plus[i] - minus[i]);21 acc += 2.0 * res[i] * dp;22 }23 g[k] = acc / data.len() as f64;24 }25 g26}
The second is the Haar certificate of §16.4: Monte-Carlo moments and the frame potential of the single-qubit block ensemble, graded in units of their own statistical error. The third samples random deep circuits at growing qubit counts and measures the gradient variance — the plateau, quantified and compared point by point against the 2-design closed form (16.4):
1/// The EXACT 2-design prediction for the gradient variance of the global parity2/// cost on n qubits: Var = d²/(2(d²−1)(d+1)) with d = 2^n. Derived in the3/// header from the two-copy Haar twirl; ≈ 2^{-(n+1)} for large n.4fn var_2design(n: usize) -> f64 {5 let d = (1u64 << n) as f64;6 d * d / (2.0 * (d * d - 1.0) * (d + 1.0))7}
1for n in 3..=11usize {2 let l = 2 * n; // depth scales with the qubit count: n layers EACH SIDE3 // …4 let diff = (l / 2) * n * 3 + 1;5 let mut grads = Vec::with_capacity(samples);6 for _ in 0..samples {7 let angles = haar_angles(l * n, &mut brng); // Haar-random SU(2) blocks8 let cp = random_cost(&angles, n, l, diff, FRAC_PI_2);9 let cm = random_cost(&angles, n, l, diff, -FRAC_PI_2);10 grads.push(0.5 * (cp - cm)); // exact parameter-shift gradient11 }12 let sn = samples as f64;13 let mean: f64 = grads.iter().sum::<f64>() / sn;14 let variance: f64 = grads.iter().map(|g| (g - mean).powi(2)).sum::<f64>() / sn;15 // …16 }
14 referees gate the chapter's claims: the simulator-vs-dense agreement and unitarity of the deepest circuit; the exact-gradient claim (parameter-shift equals finite difference to 3.0e-9, achieved 1.5e-9); training success on held-out data; the three Haar/2-design certificates; and the plateau itself — variance matching (16.4) at the largest , the fitted decay rate matching the closed form's, a zero-mean gradient at every size, a steep negative log-variance slope with near 1, and an exponentially large variance ratio across the qubit range (measured 221× from to ). All the numbers above are read live from the lab's JSON. Run it with cargo run --release in Rust-QML/ch16-vqc.
16.8Exercises
1. (F, hard) Derive the parameter-shift rule (16.1) for a gate with . (Hint: show is of the form .)
2. (F) Verify both halves of (16.3): with uniform on , compute directly; for Haar, use the fact that is uniform on . Then show the density of under uniform is the arcsine law of Figure 16.2.
3. (C) From the plateau chart, read off the decay rate and estimate the gradient variance at qubits using (16.4). How many measurement shots would you need to resolve such a gradient?
4. (F) Explain why a global cost function (like ) plateaus even for shallow circuits while a local one does not (Cerezo et al. 2021). What role does the light cone of the differentiated gate play?
5. (P) Modify the lab to use a local cost (measure on one qubit) with a shallow constant-depth ansatz. Show the variance no longer decays exponentially.
6. (P, hard) Initialize the ansatz as a sequence of identity blocks (each layer's angles summing to the identity) and show the initial gradient is large — a warm start that defers the plateau. (The lab's referee falsification run did a crude version: scaling every Haar angle by 0.05 collapsed the variance ratio from hundreds to single digits.)
The bridge → Chapter 17: The Honest Scorecard
Where you stand. You can build and train a quantum model end-to-end with the exact parameter-shift gradient, certify a random-circuit ensemble against Haar's moments instead of taking randomness on faith — and you have measured the barren plateau, one bit of gradient variance per qubit, against the 2-design theorem's own closed form.
The open question. Barren plateaus are one blow to quantum-learning hype; dequantization is the other. So where does a real, defensible quantum advantage in learning actually live — and how do we tell honest wins from claims a classical computer quietly matches?
What comes next. The capstone: dequantization (classical algorithms that erased proposed speedups), quantum data (where advantage is on firmer ground), and tensor networks — the classical shadow of low-entanglement states that both powers simulation and bounds where quantum learning can win. We end with an honest advantage scorecard.