Barren Plateau Detection and Analysis
Known limitation (October 2026): As built (cost ⟨Z₀⟩ on one qubit, 3 layers), this demo shows no barren plateau: the call under Running the Circuit gives gradient variances of 0.11 to 0.19 from 2 to 6 qubits, a decay exponent α = 0.15, and
barren_plateau_detected = False. It still shows how to estimate gradient variance with the parameter-shift rule and fit α, and exercise 4 (a global cost) does show exponential decay (α ≈ 1.0 in our check). A corrected version is planned.
What You'll Learn:
- Why gradient variance vanishes exponentially with qubit count in deep random circuits
- How the parameter-shift rule computes exact quantum gradients without finite differences
- How to fit and interpret the exponential decay exponent α
- What mitigation strategies exist: shallow circuits, local costs, structured initialization
Level: Advanced | Time: 30 minutes | Qubits: Variable (2-6) | Framework: Cirq
Prerequisites
- Hardware-Efficient Ansatz — the circuit structure being analyzed
- H2 Ground State — VQE optimization (where barren plateaus matter)
The Idea
Variational quantum algorithms work by adjusting circuit parameters to minimize a cost function. But there's a fundamental problem: for deep random circuits, the cost landscape becomes exponentially flat as the system grows. The variance of the gradient shrinks as about 2^(-n), so typical gradients become exponentially small. Estimating them then takes exponentially many measurement shots, which makes training impractical at scale, and gradient-free optimizers suffer in the same way (Arrasmith et al. 2021).
Imagine optimizing a function on a vast plateau where the height differences are smaller than your measurement precision. No matter how sophisticated your optimizer, it can't find the downhill direction. That's a barren plateau.
This circuit doesn't solve a problem — it diagnoses one. By measuring how gradient variance scales with qubit count, you can determine whether your ansatz will be trainable before wasting hours of quantum computing time.
How It Works
Step 1: Build the Ansatz
A standard hardware-efficient ansatz with L layers:
CODELayer 1..L: ┌────────┐┌────────┐ q_0: ┤ RY(θ₀) ├┤ RZ(θ₁) ├──●─────── ├────────┤├────────┤┌─┴─┐ q_1: ┤ RY(θ₂) ├┤ RZ(θ₃) ├┤ X ├──●── ├────────┤├────────┤└───┘┌─┴─┐ q_2: ┤ RY(θ₄) ├┤ RZ(θ₅) ├─────┤ X ├ └────────┘└────────┘ └───┘
Parameters per layer: 2n (one RY + one RZ per qubit). Total: 2nL.
Step 2: Compute Gradients via Parameter-Shift
For each random initialization θ, compute the gradient of ⟨Z₀⟩ w.r.t. θ₀:
∂⟨Z₀⟩/∂θ₀ = (⟨Z₀⟩_{θ₀+π/2} - ⟨Z₀⟩_{θ₀-π/2}) / 2
This requires two circuit evaluations — no finite differences, no approximation.
Step 3: Collect Statistics
Repeat for many random parameter sets (50-100 samples). Compute:
- Mean gradient: should be ~0 (random circuits are symmetric)
- Gradient variance: measures landscape "non-flatness"
Step 4: Fit Exponential Decay
Plot log(Var) vs. qubit count n. If the relationship is linear:
log(Var) = -α · n · log(2) + c
then α is the decay exponent. Barren plateau = α > 0.5.
The Math
Why Gradients Vanish
For deep circuits that behave like random unitaries (McClean et al. 2018), the gradient variance of any Pauli-string cost O shrinks as about 2^(-n), whether the cost is local or global:
Var[∂⟨O⟩/∂θ_k] ∝ 2^(-n) (deep, random-like circuits)
For shallow circuits (depth O(log n)), Cerezo et al. (2021) showed that it depends on the cost:
- Local cost (e.g., Z₀): gradients vanish at worst polynomially in n, so the circuit stays trainable
- Global cost (e.g., Z₀Z₁...Z_{n-1}): gradients still vanish exponentially, even for shallow circuits
This demo's default (cost Z₀, 3 layers) is the shallow, local case, which is why its gradient variance does not decay with n (see Expected Output).
Parameter-Shift Rule
For a gate U(θ) = exp(-iθG/2) where G has eigenvalues ±1:
∂⟨ψ(θ)|O|ψ(θ)⟩/∂θ = (⟨ψ(θ+π/2)|O|ψ(θ+π/2)⟩ - ⟨ψ(θ-π/2)|O|ψ(θ-π/2)⟩) / 2
This is exact — no truncation error. Works on real hardware with finite shots.
Decay Exponent Fitting
Given variance measurements Var(n) for n = 2, 3, ..., N:
log(Var(n)) ≈ -α · n · log(2) + c
Linear regression on (n, log(Var)) gives slope = -α · log(2), so α = -slope / log(2).
Expected Output
From the call under Running the Circuit (run_circuit(max_qubits=6, n_layers=3, n_samples=50), which is deterministic):
| Qubits | Gradient Variance | Interpretation |
|---|---|---|
| 2 | 0.194 | Trainable |
| 3 | 0.146 | Trainable |
| 4 | 0.194 | Trainable |
| 5 | 0.171 | Trainable |
| 6 | 0.108 | Trainable |
Decay exponent α = 0.15, so barren_plateau_detected is False. The variance does not shrink with n because the differentiated angle θ₀ and the cost Z₀ both sit on qubit 0, and with 3 layers of a nearest-neighbour CNOT ladder the gradient depends on only a few qubits near qubit 0 (with 300 samples per point it stayed between about 0.15 and 0.20 from 2 to 9 qubits). This is the local-cost, shallow-depth case in which Cerezo et al. (2021) prove gradients do not vanish exponentially. To see a barren plateau, use a global cost such as Z₀Z₁...Z_{n-1} (α ≈ 1.0 in our check, exercise 4) or let the depth grow with n (n_layers = n gave α ≈ 0.7).
Running the Circuit
PYTHONfrom circuit import run_circuit, verify_barren_plateau # Analyze gradient scaling result = run_circuit(max_qubits=6, n_layers=3, n_samples=50) for n_q, data in sorted(result['qubit_analysis'].items()): print(f"{n_q} qubits: Var = {data['variance']:.6f}") print(f"Decay exponent α: {result['decay_exponent']:.3f}") print(f"Barren plateau: {result['barren_plateau_detected']}") # Verification v = verify_barren_plateau() for check in v["checks"]: status = "PASS" if check["passed"] else "FAIL" print(f"[{status}] {check['name']}: {check['detail']}")
Try It Yourself
-
Vary depth: Run with
n_layers=1vsn_layers=5. Does the decay exponent α increase with depth? (It should — deeper circuits have worse barren plateaus.) -
Identity initialization: Modify
create_deep_circuitto initialize all parameters near 0 (instead of random). Does the gradient variance at n=6 improve? -
Entanglement structure: Replace the CNOT ladder with a circular pattern (add CNOT from last to first qubit). Does this change the barren plateau behavior?
-
Global vs local observable: Replace Z₀ with Z₀Z₁Z₂...Z_{n-1} (global parity). Is the decay exponent larger? (It should be — global costs have worse barren plateaus.)
-
Sample size sensitivity: Run with n_samples=10 vs n_samples=200. How much does the variance estimate fluctuate?
What's Next
- Hardware-Efficient Ansatz — the ansatz being analyzed here
- Expressibility — measures how well an ansatz covers the Hilbert space
- UCCSD Ansatz — chemistry-inspired ansatz that may avoid barren plateaus
Mitigation Strategies
| Strategy | How it helps | Trade-off |
|---|---|---|
| Shallow circuits | Fewer layers → larger gradients | Less expressibility |
| Local cost functions | Z₀ instead of global O | May not capture full problem |
| Layer-wise training | Train one layer at a time | More optimization steps |
| Identity initialization | Start near identity → large initial gradients | May bias the search |
| Correlated parameters | Share params across qubits | Reduced ansatz flexibility |
Applications
| Domain | Use case |
|---|---|
| VQE debugging | Check if your ansatz is trainable before running expensive chemistry |
| Ansatz design | Compare candidate ansatze for trainability |
| Hardware planning | Estimate maximum useful qubit count for a given circuit depth |
| Theory validation | Verify barren plateau bounds from analytical predictions |
References
- McClean, J.R. et al. (2018). "Barren plateaus in quantum neural network training landscapes." Nature Communications 9, 4812. DOI: 10.1038/s41467-018-07090-4
- Cerezo, M. et al. (2021). "Cost function dependent barren plateaus in shallow parametrized quantum circuits." Nature Communications 12, 1791. DOI: 10.1038/s41467-021-21728-w
- Pesah, A. et al. (2021). "Absence of Barren Plateaus in Quantum Convolutional Neural Networks." Physical Review X 11, 041011. DOI: 10.1103/PhysRevX.11.041011
- Arrasmith, A. et al. (2021). "Effect of barren plateaus on gradient-free optimization." Quantum 5, 558. DOI: 10.22331/q-2021-10-05-558