Skip to content

Lesson 29: Quantum Neural Networks, the Parameter-Shift Rule and Barren Plateaus

29.1 Learning Outcomes

By the end of this hour a student will be able to:

  1. Define a quantum neural network and compare it structurally with a classical network.
  2. Derive and apply the parameter-shift rule for analytic gradients.
  3. Explain why finite differences fail on quantum hardware.
  4. State the barren-plateau theorem and compute the shot cost it implies.
  5. List and evaluate the standard mitigation strategies.

29.2 Quantum Neural Networks

Definition. A QNN is a parameterised quantum circuit trained by gradient descent so that measurement outcomes approximate a target function.

Structural comparison with a classical network

Classical NN QNN
Layer = affine map \(W\vec x + \vec b\) Layer = unitary \(U(\vec\theta)\)
Non-linearity from the activation function \(\sigma\) Non-linearity from measurement (and from encoding)
Backpropagation stores intermediate activations Cannot — measuring destroys the state
Gradient by reverse-mode autodiff, \(O(1)\) overhead Gradient by parameter shift, \(O(P)\) circuits
Width = number of neurons Width = number of qubits (feature space \(2^n\))
Universal approximator (Cybenko) Truncated Fourier series (Schuld et al., L26)

The most important structural difference. Backpropagation is impossible: you cannot read out intermediate states without collapsing them. This is why quantum gradients cost \(O(P)\) circuit evaluations rather than the \(O(1)\) overhead of classical autodiff, and it is the deepest practical obstacle to scaling QNNs.

Where non-linearity comes from

A quantum circuit is linear in the state. Non-linearity in \(f_{\vec\theta}(\vec x)\) enters at two places:

  1. Encoding. \(\vec x \mapsto |\phi(\vec x)\rangle\) is non-linear (e.g. \(x\mapsto\cos\frac{x}{2}\)).
  2. Measurement. \(|\psi\rangle\mapsto\langle\psi|M|\psi\rangle\) is quadratic in the amplitudes.

Some architectures add explicit non-linearity via mid-circuit measurement and feed-forward, or by discarding (tracing out) qubits — the latter is how QCNN pooling works (L30).

29.3 The Parameter-Shift Rule

Why finite differences fail

The naive estimator

\[ \frac{\partial f}{\partial\theta} \approx \frac{f(\theta+h) - f(\theta-h)}{2h} \]

has two error sources:

\[ \text{truncation } O(h^2) \qquad\text{and}\qquad \text{shot noise } O\!\left(\frac{\sigma}{h\sqrt S}\right) . \]

Small \(h\) reduces truncation but amplifies shot noise by \(1/h\). Minimising the total gives \(h^{*} \sim (\sigma/\sqrt S)^{1/3}\), and even at the optimum the error is \(O(S^{-1/3})\) — much worse than the \(O(S^{-1/2})\) achievable with an exact method. On hardware, finite differences are unusable.

The rule

Theorem (Parameter-shift rule). Let a gate be \(U(\theta) = e^{-i\theta G/2}\) with a generator \(G\) having exactly two eigenvalues \(\pm1\) (so \(G^2 = I\) — true for \(X, Y, Z\), hence for \(R_x, R_y, R_z\)). Then

\[ \boxed{\ \frac{\partial f}{\partial\theta} = \frac{1}{2}\left[f\!\left(\theta + \frac{\pi}{2}\right) - f\!\left(\theta - \frac{\pi}{2}\right)\right]\ } \]

This is exact, not an approximation. The same circuit is run at two shifted parameter values.

Proof

Write \(f(\theta) = \langle\psi_0|U^\dagger(\theta)\,M\,U(\theta)|\psi_0\rangle\) with \(U(\theta) = e^{-i\theta G/2}\).

Since \(G^2 = I\) (L04):

\[ U(\theta) = \cos\tfrac{\theta}{2}\,I - i\sin\tfrac{\theta}{2}\,G . \]

Substituting and expanding,

\[ f(\theta) = \cos^{2}\tfrac{\theta}{2}\,\langle M\rangle_0 + \sin^{2}\tfrac{\theta}{2}\,\langle GMG\rangle_0 + i\cos\tfrac{\theta}{2}\sin\tfrac{\theta}{2}\,\langle [M, G]\rangle_0 \]

where \(\langle\cdot\rangle_0 = \langle\psi_0|\cdot|\psi_0\rangle\). Using the double-angle identities \(\cos^2\frac{\theta}{2} = \frac{1+\cos\theta}{2}\), \(\sin^2\frac{\theta}{2}=\frac{1-\cos\theta}{2}\), \(2\cos\frac{\theta}{2}\sin\frac{\theta}{2} = \sin\theta\):

\[ f(\theta) = \underbrace{\frac{\langle M\rangle_0 + \langle GMG\rangle_0}{2}}_{A} + \underbrace{\frac{\langle M\rangle_0 - \langle GMG\rangle_0}{2}}_{B}\cos\theta + \underbrace{\frac{i}{2}\langle[M,G]\rangle_0}_{C}\sin\theta \]
\[ \boxed{\ f(\theta) = A + B\cos\theta + C\sin\theta\ } \]

\(f\) is exactly a sinusoid in \(\theta\) — a single Fourier mode. Differentiating:

\[ f'(\theta) = -B\sin\theta + C\cos\theta . \]

Now evaluate the shifted values:

\[ f\!\left(\theta+\tfrac{\pi}{2}\right) = A + B\cos\!\left(\theta+\tfrac\pi2\right) + C\sin\!\left(\theta+\tfrac\pi2\right) = A - B\sin\theta + C\cos\theta \]
\[ f\!\left(\theta-\tfrac{\pi}{2}\right) = A + B\sin\theta - C\cos\theta \]

Subtracting:

\[ f\!\left(\theta+\tfrac\pi2\right) - f\!\left(\theta-\tfrac\pi2\right) = -2B\sin\theta + 2C\cos\theta = 2f'(\theta) \ \checkmark \qquad\blacksquare \]

Cost

For \(P\) parameters, a full gradient needs

\[ 2P \ \text{circuit evaluations} . \]

Contrast classical backpropagation: \(O(1)\) times the forward-pass cost, independent of \(P\). For \(P = 1000\), one quantum gradient step costs 2000 circuits. This is the single strongest argument for using SPSA on hardware (L28).

Generalisation. For generators with more than two eigenvalues (e.g. controlled rotations, or \(e^{-i\theta H}\) for a multi-term \(H\)), the four-term shift rule or the stochastic parameter-shift rule applies; the sinusoid becomes a sum of a few frequencies and correspondingly more shifts are needed.

29.4 Barren Plateaus

The theorem

Theorem (McClean, Boixo, Smelyanskiy, Babbush, Neven, 2018). For a random parameterised circuit whose ansatz forms an approximate unitary 2-design (which deep hardware-efficient ansätze do), the cost gradient satisfies

\[ \mathbb{E}\left[\frac{\partial L}{\partial\theta_k}\right] = 0, \qquad \mathrm{Var}\left[\frac{\partial L}{\partial\theta_k}\right] \in O\!\left(\frac{1}{2^{n}}\right) . \]

The gradient is exponentially small in the number of qubits, everywhere except an exponentially small region.

Why this is fatal

To estimate a gradient of magnitude \(g\) you need shot noise below \(g\):

\[ \frac{1}{\sqrt S} \lesssim g \sim 2^{-n/2} \qquad\Longrightarrow\qquad \boxed{\ S = O\!\left(2^{n}\right)\ \text{shots}\ } \]

The measurement cost is exponential in the qubit count, which destroys any quantum advantage. It is not that the optimiser gets stuck in a bad local minimum — the landscape is flat, so the optimiser cannot even tell which way is downhill.

Numerically:

\(n\) Typical \(\lVert\nabla L\rVert\) Shots needed
4 \(6\times10^{-2}\) \(\sim3\times10^{2}\)
10 \(3\times10^{-2}\) \(\sim10^{3}\)
20 \(10^{-3}\) \(\sim10^{6}\)
50 \(3\times10^{-8}\) \(\sim10^{15}\)

At 50 qubits, one gradient component would take over 3 years at 10 kHz.

The four causes

Cause Mechanism
Circuit depth / expressivity deep random circuits approach 2-designs
Global cost functions \(\langle Z^{\otimes n}\rangle\) has exponentially vanishing gradients even at depth \(O(1)\)
Entanglement too much entanglement with the "rest" of the register concentrates observables
Noise hardware noise induces noise-induced barren plateaus, which grow with depth and cannot be fixed by clever initialisation

Mitigations

Strategy Idea Effectiveness
Local cost functions use \(\langle Z_0\rangle\) instead of \(\langle Z^{\otimes n}\rangle\) strong — Cerezo et al. proved gradients vanish only polynomially for \(O(\log n)\)-depth circuits
Shallow, structured ansätze QCNN, QAOA, UCCSD, hamiltonian variational ansatz strong — QCNN provably has no barren plateau
Identity-block initialisation initialise pairs of blocks as \(V V^\dagger = I\) moderate — helps at the start, may drift
Layerwise training train layer 1, freeze, add layer 2, … moderate
Correlated / symmetric parameters tie parameters, reducing the effective dimension moderate
Warm starts initialise from a classical solution problem-dependent
Error mitigation reduces noise-induced plateaus partial

The state of the field, honestly stated. Barren plateaus are the central obstacle to variational QML at scale. Kim/Cerezo and others (2023–24) went further: they showed that many ansätze designed to avoid barren plateaus are, for that very reason, classically simulable — because the structure that keeps gradients large also keeps the state in a small, tractable subspace. This "no free lunch" tension is unresolved and is currently the most important open question in variational quantum algorithms. Students should know it.

29.5 Solved Problems

Problem 1 — Parameter-shift computation

For \(f(\theta) = \langle 0|R_y^\dagger(\theta)ZR_y(\theta)|0\rangle\), compute \(f(\theta)\) analytically, then verify the parameter-shift rule at \(\theta = \pi/3\).

Solution.

\[ R_y(\theta)|0\rangle = \cos\tfrac{\theta}{2}|0\rangle + \sin\tfrac{\theta}{2}|1\rangle \]
\[ f(\theta) = \langle Z\rangle = \cos^{2}\tfrac{\theta}{2} - \sin^{2}\tfrac{\theta}{2} = \cos\theta \]

(Confirming the general form \(f = A + B\cos\theta + C\sin\theta\) with \(A = C = 0\), \(B = 1\).)

Exact derivative. \(f'(\theta) = -\sin\theta\), so at \(\theta = \pi/3\):

\[ f'(\pi/3) = -\sin(\pi/3) = -\frac{\sqrt3}{2} = \mathbf{-0.86603} \]

Parameter shift.

\[ f\!\left(\tfrac{\pi}{3}+\tfrac{\pi}{2}\right) = \cos\!\left(\tfrac{5\pi}{6}\right) = -\frac{\sqrt3}{2} = -0.86603 \]
\[ f\!\left(\tfrac{\pi}{3}-\tfrac{\pi}{2}\right) = \cos\!\left(-\tfrac{\pi}{6}\right) = \frac{\sqrt3}{2} = +0.86603 \]
\[ \frac{\partial f}{\partial\theta} = \frac{1}{2}\big[-0.86603 - 0.86603\big] = \mathbf{-0.86603} \ \checkmark \]

Exact agreement, using only two evaluations of the same circuit at shifted parameters.

Compare finite differences with \(h = 0.01\):

\[ \frac{\cos(\pi/3 + 0.01) - \cos(\pi/3 - 0.01)}{0.02} = \frac{0.49131 - 0.50864}{0.02} = -0.86601 \]

Accurate here — but only because this was computed exactly. With 1024 shots, each \(f\) value carries error \(\approx0.03\), so the finite-difference estimate has error \(\approx \frac{2\times0.03}{0.02} = 3.0\) — completely swamping the true value of \(-0.87\). The parameter-shift estimate has error \(\approx\frac{2\times0.03}{2} = 0.03\), a 100× improvement.

Problem 2 — Cost of a full gradient

A QNN has 6 qubits, 4 layers, 2 rotations per qubit per layer. Compute the parameters, circuit evaluations per gradient, and total shots for 100 Adam steps on 50 training samples at 1024 shots.

Solution.

Parameters.

\[ P = 4\ \text{layers}\times 6\ \text{qubits}\times 2 = \mathbf{48} \]

Circuits per gradient (per training sample):

\[ 2P = 96 \]

Per optimisation step (full batch of 50):

\[ 96\times50 = 4800\ \text{circuits} \Rightarrow 4800\times1024 = 4.92\times10^{6}\ \text{shots} \]

For 100 steps:

\[ 4.92\times10^{8}\ \text{shots} \]

Time at 5000 shots/s:

\[ \frac{4.92\times10^{8}}{5000} = 98{,}400\ \mathrm{s} = \mathbf{27.3\ \text{hours}} \]

With SPSA instead (2 evaluations per step):

\[ 2\times50\times1024\times100 = 1.02\times10^{7}\ \text{shots} = \mathbf{34\ \text{minutes}} \]
\[ \boxed{\ \text{SPSA is } 48\times \text{ cheaper — exactly the factor } P.\ } \]

Problem 3 — Quantifying a barren plateau

A 20-qubit random hardware-efficient ansatz has gradient variance \(\mathrm{Var} = 2^{-20}\). How many shots are needed to resolve a gradient component with signal-to-noise ratio 3? Compare with 8 qubits.

Solution.

At 20 qubits.

\[ \sigma_{\text{grad}} = \sqrt{2^{-20}} = 2^{-10} = 9.77\times10^{-4} \]

This is the typical magnitude of a gradient component. Shot noise in an expectation value is \(\frac{1}{\sqrt S}\) (for an observable with unit variance), and the parameter-shift estimator has noise \(\approx\frac{1}{\sqrt S}\) as well (the factor \(\frac12\) and two terms roughly cancel).

Require SNR \(= 3\):

\[ \frac{9.77\times10^{-4}}{1/\sqrt S} \ge 3 \ \Longrightarrow\ \sqrt S \ge \frac{3}{9.77\times10^{-4}} = 3071 \ \Longrightarrow\ \boxed{S \ge 9.4\times10^{6}} \]

Per gradient component. With \(P = 100\) parameters and 2 circuits each:

\[ 100\times2\times9.4\times10^{6} = 1.9\times10^{9}\ \text{shots per step} \]

At 5000 shots/s: 4.4 days for a single gradient step.

At 8 qubits.

\[ \sigma = 2^{-4} = 0.0625, \qquad S \ge \left(\frac{3}{0.0625}\right)^{2} = 2304 \ \text{shots} \]

Comparison.

\[ \frac{9.4\times10^{6}}{2304} = \mathbf{4080\times} \ \text{more expensive at 20 qubits than at 8.} \]

This is exactly \(2^{12} = 2^{20-8}\) ✓ — the exponential scaling made concrete.

The conclusion for practice. Deep unstructured VQAs are trainable at \(n\lesssim 12\) and become hopeless well before \(n = 30\). Any claim of a scalable variational algorithm must explain how it avoids this.

Problem 4 — Local versus global cost functions

Compare \(\langle Z^{\otimes n}\rangle\) and \(\langle Z_0\rangle\) as cost functions for a shallow \(O(\log n)\)-depth ansatz. Which is trainable, and why?

Solution.

Global cost \(C_G = 1 - \langle\psi|Z^{\otimes n}|\psi\rangle\).

The observable acts non-trivially on all \(n\) qubits. Even for constant-depth circuits, the expectation value of an \(n\)-body observable over a random state concentrates:

\[ \mathrm{Var}\left[\partial_k C_G\right] \in O\!\left(2^{-n}\right) \]
\[ \Rightarrow \textbf{barren plateau at any depth.} \]

Intuition: to move \(\langle Z^{\otimes n}\rangle\) you must coherently align \(n\) qubits at once, and a small parameter change affects that \(n\)-body correlator only at order \(2^{-n}\).

Local cost \(C_L = 1 - \frac{1}{n}\sum_{j=1}^{n}\langle\psi|Z_j|\psi\rangle\).

Each term acts on one qubit. Cerezo et al. (2021) proved that for an ansatz of depth \(O(\log n)\),

\[ \mathrm{Var}\left[\partial_k C_L\right] \in \Omega\!\left(\frac{1}{\mathrm{poly}(n)}\right) \]
\[ \Rightarrow \textbf{trainable — the gradient vanishes only polynomially.} \]

Intuition: by the lightcone argument, a single-qubit observable in a shallow circuit is affected only by gates inside its causal cone, which contains \(O(\mathrm{polylog}\,n)\) gates — an effectively small system, immune to \(2^{-n}\) concentration.

Numerical illustration at \(n = 20\), depth \(= \log_2 20 \approx 4\):

Cost \(\mathrm{Var}[\partial C]\) Shots for SNR 3
Global \(\sim 10^{-6}\) \(\sim10^{7}\)
Local \(\sim 10^{-2}\) \(\sim10^{2}\)

A five-order-of-magnitude difference from changing one line of code.

\[ \boxed{\ \textbf{Always use local cost functions.}\ } \]

If the problem genuinely demands a global quantity (e.g. state fidelity), use the "local-to-global" trick: train with the local cost first, then switch to the global one for fine-tuning once you are near the solution.

Problem 5 — Diagnosing a stalled training run

A VQC with 12 qubits and 8 layers shows a loss that decreases from 0.50 to 0.497 in 500 iterations, then flatlines. Diagnose the cause and give a concrete remediation plan.

Solution.

Diagnosis: barren plateau, not a local minimum. Three pieces of evidence:

  1. Loss barely moved (0.003 over 500 steps) — a local minimum would show fast initial descent then flattening; a plateau is flat from the start.
  2. 12 qubits × 8 layers = 192 parameters with a random hardware-efficient ansatz — deep enough to approximate a 2-design.
  3. Loss ≈ 0.5 = the random-guessing value for balanced binary classification. The model has learned nothing at all.

Confirmatory test. Sample the gradient norm at 20 random parameter settings and check whether

\[ \mathrm{Var}[\partial_k L] \approx 2^{-12} = 2.4\times10^{-4} . \]

If yes, it is a barren plateau; if the variance is large but the optimiser is oscillating, it is a learning-rate or noise problem instead.

Remediation plan, in priority order.

  1. Switch to a local cost function — from \(\langle Z^{\otimes12}\rangle\) to \(\frac{1}{12}\sum_j\langle Z_j\rangle\) or just \(\langle Z_0\rangle\). Highest impact, one line of code.
  2. Cut the depth from 8 layers to 2–3, reducing \(P\) from 192 to ~60. Add depth back only if the model underfits.
  3. Adopt a structured ansatz — a QCNN (L30) on 12 qubits has provably non-vanishing gradients and uses \(O(\log n)\) depth.
  4. Identity-block initialisation — initialise so the circuit starts near identity, where the landscape is not yet flat.
  5. Layerwise training — train 2 layers to convergence, freeze them, add 2 more.
  6. Reduce qubit count — if only 6 features matter, use 6 qubits; the plateau scales as \(2^{-n}\), so halving \(n\) improves gradients by \(2^{6} = 64\times\).
  7. Increase shots — a last resort. This does not fix the plateau, only lets you see through it, and the cost is exponential.

Expected outcome. Steps 1–3 together typically restore training. If the loss still refuses to move below 0.5, the problem is not the plateau but the model class: check that the encoding gives the required Fourier frequencies (L26, Problem 4) and that a classical baseline can separate the data at all.

29.6 Practice Problems

  1. Apply the parameter-shift rule to \(f(\theta)=\cos\theta\) at \(\theta = 0\). [Ans: 0]
  2. Prove \(f(\theta) = A + B\cos\theta + C\sin\theta\) for any single \(R_y(\theta)\) gate.
  3. Compute the circuits per gradient for \(P = 250\). [Ans: 500]
  4. At \(n=16\), what shots give SNR 2 if \(\sigma_{\text{grad}} = 2^{-8}\)? [Ans: \(\approx2.6\times10^{5}\)]
  5. Why is backpropagation impossible on a quantum computer?
  6. Name three causes of barren plateaus and one mitigation for each.
  7. Explain the trade-off between avoiding barren plateaus and retaining quantum advantage.

29.7 Summary

  • A QNN is a PQC trained by gradient descent; non-linearity comes from the encoding and from measurement, not from the gates.
  • Backpropagation is impossible (measurement destroys intermediate states), so gradients cost \(O(P)\) circuits rather than \(O(1)\).
  • Parameter-shift rule: \(\partial_\theta f = \frac12\big[f(\theta+\frac\pi2) - f(\theta-\frac\pi2)\big]\) — exact, because \(f(\theta) = A + B\cos\theta + C\sin\theta\) for any \(R_x/R_y/R_z\) parameter. Requires \(2P\) circuits.
  • Finite differences fail on hardware: error \(O(S^{-1/3})\) versus \(O(S^{-1/2})\), and shot noise is amplified by \(1/h\).
  • Barren plateaus: for 2-design ansätze, \(\mathrm{Var}[\partial L] = O(2^{-n})\), requiring \(O(2^{n})\) shots. The landscape is flat, not merely rugged.
  • Causes: depth/expressivity, global cost functions, excess entanglement, hardware noise.
  • Mitigations: local costs (strongest — restores polynomial scaling for \(O(\log n)\) depth), structured ansätze (QCNN, QAOA), identity-block initialisation, layerwise training.
  • Open tension: ansätze that provably avoid barren plateaus tend to be classically simulable — currently the central unresolved question in variational quantum algorithms.

Next lesson: L30 — Quantum convolutional neural networks.

Practise now: unit3-qml-lab.html → Gradient Lab: compare parameter-shift and finite-difference estimates under shot noise, and plot gradient variance against qubit count to see the plateau appear.