QuantumCore

Hands-on lab · 1 step

Shot-noise variance of gradient estimators

Compare the two gradient estimators available on quantum hardware for f(θ)=⟨Z⟩=cos⁡θf(\theta)=\langle Z\rangle=\cos\theta of the state RY(θ)∣0⟩R_Y(\theta)\lvert0\rangle: the central finite difference with step h=0.01h=0.01 and the parameter-shift rule. Both use two circuit evaluations of N=1000N=1000 shots; you compute the exact shot-noise variance of each and see a factor h−2=104h^{-2}=10^4 between them.

0/1 step passedBest score 0/100

Step 1: Variance of the FD and parameter-shift estimators

The one-qubit circuit RY(θ)∣0⟩R_Y(\theta)\lvert0\rangle with RY(θ)=e−iθY/2R_Y(\theta)=e^{-i\theta Y/2} is measured in the computational basis, and each shot returns z=+1z=+1 (outcome 00) or z=−1z=-1 (outcome 11). The model output is

f(θ)=⟨Z⟩=cos⁡θ.f(\theta)=\langle Z\rangle=\cos\theta .

An evaluation f^(φ)\hat f(\varphi) runs the circuit at angle φ\varphi for N=1000N=1000 fresh shots and returns the mean of the NN outcomes; different evaluations use independent shots. Consider the two gradient estimators

g^FD=f^(θ+h)−f^(θ−h)2h,g^PSR=12[f^(θ+π2)−f^(θ−π2)].\hat g_{\mathrm{FD}}=\frac{\hat f(\theta+h)-\hat f(\theta-h)}{2h},\qquad\hat g_{\mathrm{PSR}}=\frac12\Big[\hat f\big(\theta+\tfrac\pi2\big)-\hat f\big(\theta-\tfrac\pi2\big)\Big].

At θ=π/4\theta=\pi/4 and N=1000N=1000, compute

(a) the variance Var[g^FD]\mathrm{Var}[\hat g_{\mathrm{FD}}] of the central finite-difference estimator with h=0.01h=0.01;

(b) the variance Var[g^PSR]\mathrm{Var}[\hat g_{\mathrm{PSR}}] of the parameter-shift estimator.

Enter two real numbers in this order. Each value is graded with relative tolerance 10−310^{-3} (plus an absolute 10−710^{-7}). You may type decimals such as 2.5e-4 or exact expressions such as 1/(40.01^21000); an expression must be correct to within 10−610^{-6}.

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.