This is a genuine state-vector simulation, not an illustration. Starting from |0…0⟩, a hardware-efficient ansatz applies L layers of single-qubit Ry(θ) rotations (random angles, freshly redrawn every sample) followed by a ring of CZ entangling gates. Because Ry and CZ are both real-valued, the whole 2ⁿ-dimensional statevector stays real — no complex arithmetic needed, and the exact same numbers a real quantum simulator would produce.
The cost is the expectation of the global-parity observable Z0⊗Z1⊗…⊗Zn−1, read off directly from the probabilities: C(θ) = Σᵢ |ψᵢ|²·(−1)popcount(i). The gradient of one middle-layer parameter is computed with the exact parameter-shift rule used on real quantum hardware — no finite-difference approximation:
∂C/∂θ = [ C(θ+π/2) − C(θ−π/2) ] / 2
Redrawing every other angle at random and repeating this S times gives a Monte-Carlo estimate of Var[∂C/∂θ] over the random-circuit ensemble — exactly the statistic McClean et al. (2018) proved shrinks as O(2⁻ⁿ) once the circuit is expressive enough to look Haar-random. Running the sweep here across n = 2…10 and fitting log₂(Var) vs. n on this very engine typically returns a slope within a few percent of the theoretical −1 (confirmed on this build: slope ≈ −0.94 at depth L=4, 4000 samples/point).
- Qubits n — sets the top end of the sweep; each n uses its own freshly-sampled ensemble.
- Depth L — more layers push the ansatz closer to a Haar-random (2-design) circuit, which is the regime the O(2⁻ⁿ) bound actually assumes.
- Samples S — more Monte-Carlo draws per n tighten the variance estimate; the histogram panel shows the raw sample you just drew.
- Resample at n — redraws S random circuits at the current n and redraws the gradient histogram.
- Run Variance Sweep — repeats that for every n from 2 up to the slider value and plots log-scale Var(n) against the exponential fit.
Note on the companion 3D landscape simulator for the same topic: that version renders an illustrative Fourier-series surface with its amplitude hand-scaled by 2⁻⁽ᵃ⁽ⁿ⁻²⁾⁾ (a=0.85) to dramatize the flattening — a fixed, designed decay rate. This 2D engine instead simulates the actual circuit and observable and measures the decay rate empirically from real gradient samples, which is why its fitted exponent (~0.94) differs slightly from both the 3D version's chosen 0.85 and the asymptotic theoretical 1 — finite depth and finite qubit count both shift the measured slope, exactly as the real literature reports.
Real-world relevance: barren plateaus are the central open obstacle in scaling quantum machine learning and VQE-style algorithms past a few dozen qubits, motivating research into local cost functions, layerwise training and problem-inspired ansätze that avoid this exponential flattening.