QuantumCore

Hands-on lab · 2 steps

Global versus local costs on a barren plateau

Quantify the barren plateau of the exactly solvable product model V(θ)=⨂jRX(θj)V(\theta)=\bigotimes_jR_X(\theta_j) on ∣0⋯0⟩\lvert0\cdots0\rangle. First compute the exact gradient variances of the global cost CG=1−∏jcos⁡2θj2C_G=1-\prod_j\cos^2\frac{\theta_j}2 and the local cost CL=1−1n∑jcos⁡2θj2C_L=1-\frac1n\sum_j\cos^2\frac{\theta_j}2 at n=6n=6; then estimate them by Monte Carlo from a black-box cost function, using the parameter-shift rule with exactly two circuit evaluations per random parameter vector.

0/2 steps passedBest score 0/100

Step 1: Exact gradient variances at n = 6

The product ansatz V(θ)=RX(θ1)⊗⋯⊗RX(θn)V(\theta)=R_X(\theta_1)\otimes\cdots\otimes R_X(\theta_n) with RX(θ)=e−iθX/2R_X(\theta)=e^{-i\theta X/2} acts on ∣0⋯0⟩\lvert0\cdots0\rangle, and the angles θ1,…,θn\theta_1,\dots,\theta_n are independent and uniform on [0,2π)[0,2\pi). The two costs are

CG(θ)=1−∏j=1ncos⁡2θj2,CL(θ)=1−1n∑j=1ncos⁡2θj2.C_G(\theta)=1-\prod_{j=1}^n\cos^2\frac{\theta_j}2,\qquad C_L(\theta)=1-\frac1n\sum_{j=1}^n\cos^2\frac{\theta_j}2 .

For n=6n=6 give

(a) Var[∂θ1CG]\mathrm{Var}[\partial_{\theta_1}C_G], the variance of the derivative of the global cost with respect to θ1\theta_1;

(b) Var[∂θ1CL]\mathrm{Var}[\partial_{\theta_1}C_L], the same for the local cost.

Enter two real numbers in this order. A decimal answer is accepted within a relative error of 1 %1\,\% (plus an absolute 10−710^{-7}); an exact expression such as (1/8)*(3/8)^5 or 1/288 must be correct to within 10−1210^{-12}.

Enter exact expressions or decimals, e.g. 1/sqrt(2), pi/3. Values must be real.

enter a value
enter a value
Fill every field with a valid expression.

Step 2: Monte-Carlo gradient variance from a black-box cost

Complete the TypeScript function

gradientVariance(evaluate: (params: number[]) => number, n: number, samples: number, seed: number): number

What evaluate does. evaluate(p) runs the product circuit RX(p1)⊗⋯⊗RX(pn)R_X(p_1)\otimes\cdots\otimes R_X(p_n) on ∣0⋯0⟩\lvert0\cdots0\rangle and returns the exact cost C(p)C(p), which is either CGC_G or CLC_L of the previous step (the tests use both; your code does not need to know which). p must be an array of exactly nn finite numbers; p[j-1] is the angle θj\theta_j of qubit j−1j-1. Internally the cost is the expectation value of a Pauli operator whose all-identity term carries the constant: CG=(1−2−n) I−2−n∑S≠∅ZSC_G=(1-2^{-n})\,I-2^{-n}\sum_{S\neq\emptyset}Z_S and CL=12I−12n∑jZjC_L=\frac12I-\frac1{2n}\sum_jZ_j. Every call is counted, as each would be one circuit execution on hardware.

What to compute. Create rng = mulberry32(seed) (import it with import { mulberry32 } from 'quantumcore';). For s=1,…,Ss=1,\dots,S with S=S= samples:

  1. draw a fresh parameter vector θj=2π⋅\theta_j=2\pi\cdotrng() for j=1,…,nj=1,\dots,n, in this order;
  2. compute gs=∂θ1C(θ)g_s=\partial_{\theta_1}C(\theta) with the parameter-shift rule gs=12[C(θ+π2e1)−C(θ−π2e1)]g_s=\frac12\big[C(\theta+\frac\pi2e_1)-C(\theta-\frac\pi2e_1)\big], where only the first entry is shifted: exactly two calls of evaluate per sample, 2S2S in total.

Return the unbiased sample variance 1S−1∑s=1S(gs−gˉ)2\frac1{S-1}\sum_{s=1}^S(g_s-\bar g)^2 with gˉ=1S∑sgs\bar g=\frac1S\sum_sg_s.

Tests. Each test calls gradientVariance(evaluate, n, 4000, seed). The values check compares your result with the exact variance from the lesson, 18(38)n−1\frac18\big(\frac38\big)^{n-1} (global) or 18n2\frac1{8n^2} (local), with a relative tolerance of 25 %25\,\%. The calls check runs the same problems again (tests calls-…) and also requires exactly 2S=80002S=8000 calls.

  • global-n2 (visible): CGC_G on n=2n=2 qubits, seed 11, exact value 18⋅38=0.046875\frac18\cdot\frac38=0.046875.
  • local-n2, global-n4, local-n4 (hidden): CLC_L on 22 qubits, CGC_G on 44 qubits and CLC_L on 44 qubits. Only their arguments are sent to your browser.

Why 25 %25\,\%. A Monte-Carlo variance is itself random. Because E[g]=0\mathbb E[g]=0, the relative standard error of the sample variance is (κ−1)/S\sqrt{(\kappa-1)/S} with κ=E[g4]/E[g2]2\kappa=\mathbb E[g^4]/\mathbb E[g^2]^2. For the global cost κ=32(3518)n−1\kappa=\frac32\big(\frac{35}{18}\big)^{n-1}, which is 11.011.0 at n=4n=4: the heavy tail of ∏jcos⁡2θj2\prod_j\cos^2\frac{\theta_j}2 (rare samples where every factor is close to 11) makes the estimate noisy, about 5 %5\,\% at S=4000S=4000. The tolerance is five such standard errors; a missing factor 12\frac12 in the shift rule is off by 300 %300\,\%.

TypeScript: export gradientVariance, gradientVariance · 8 tests · imports: quantumcore, quantumcore/qml
Run the tests first; the results of your latest run are submitted.