Parameter-Shift Rules and Quantum Gradients

Every variational quantum algorithm is a classical optimizer wrapped around a quantum expectation value. The optimizer wants to walk downhill on a cost f(θ)=⟨0∣U†(θ)HU(θ)∣0⟩f(\boldsymbol\theta)=\langle 0|U^\dagger(\boldsymbol\theta)HU(\boldsymbol\theta)|0\rangle, and to walk downhill it needs the gradient ∂f/∂θj\partial f/\partial\theta_j. But there is no wavefunction on the desk to differentiate: the state lives on quantum hardware, and all a measurement returns is an expectation value, sampled with shot noise. The obvious workaround — a finite difference [f(θ+ϵ)−f(θ−ϵ)]/2ϵ[f(\theta+\epsilon)-f(\theta-\epsilon)]/2\epsilon — is a trap. Its truncation bias falls as ϵ2\epsilon^2, so you want ϵ\epsilon small; but its statistical error grows as 1/ϵ1/\epsilon, so you want ϵ\epsilon large. Under shot noise there is no good ϵ\epsilon, only a least-bad one, and the derivative you extract is always a little wrong. The parameter-shift rule cuts this knot. It rests on a structural fact that has no classical analogue: a single circuit angle does not enter ff arbitrarily. Each parameter drives a unitary e−iθG/2e^{-i\theta G/2}, and when the Hermitian generator GG has just two eigenvalues ±1\pm 1 — every single-qubit Pauli rotation qualifies — the cost is a pure sinusoid, f(θ)=A+Bcos⁡θ+Csin⁡θf(\theta)=A+B\cos\theta+C\sin\theta. The exact slope of a sinusoid is another sinusoid a quarter-period out of phase, so two evaluations shifted by a macroscopic π/2\pi/2 return the derivative exactly, with no small-ϵ\epsilon limit and no truncation remainder. From this one observation follow the two-term formula, its gap-dependent and multi-frequency generalizations, the ancilla form for arbitrary generators, and the shot-noise cost that ties the rule to Cost-Function and Measurement Estimation and to the Barren Plateaus that make gradients vanish.

Key takeaways
  • The parameter-shift rule returns the exact derivative of an expectation value f(θ)=⟨ψ(θ)∣H∣ψ(θ)⟩f(\theta)=\langle\psi(\theta)|H|\psi(\theta)\rangle as a difference of the same circuit run at two shifted angles — not a finite-difference approximation.
  • For a gate e−iθG/2e^{-i\theta G/2} whose generator has eigenvalues ±1\pm 1, ∂θf=12[f(θ+π2)−f(θ−π2)]\partial_\theta f=\tfrac12[f(\theta+\tfrac\pi2)-f(\theta-\tfrac\pi2)] — valid at the macroscopic shift π/2\pi/2 with zero truncation bias.
  • It works because such a parameter makes f(θ)f(\theta) a unit-frequency sinusoid, and two samples a quarter-period apart pin down a sinusoid's slope exactly.
  • A two-eigenvalue generator of gap 2r2r gives ∂θf=r2[f(θ+π2r)−f(θ−π2r)]\partial_\theta f=\tfrac r2[f(\theta+\tfrac{\pi}{2r})-f(\theta-\tfrac{\pi}{2r})]; richer spectra need the generalized 2K2K-term rule or an ancilla.
  • Gradients are unbiased, but each component costs two circuit evaluations and its variance is pure shot noise — which barren plateaus drive to O(2−n)O(2^{-n}).
  • Against finite differences the rule wins on accuracy, not speed: it removes the bias–variance tradeoff at a fixed cost of 2p2p circuit families for pp parameters.
  • Key idea: because a single parameter enters a quantum cost as f(θ)=A+Bcos⁡θ+Csin⁡θf(\theta)=A+B\cos\theta+C\sin\theta when its generator has eigenvalues ±1\pm1, its derivative is exactly 12[f(θ+π2)−f(θ−π2)]\tfrac12[f(\theta+\tfrac\pi2)-f(\theta-\tfrac\pi2)] — a finite difference of macroscopically shifted evaluations with zero discretization error.

Where this lives today

The parameter-shift rule is the differentiation backend of the variational-quantum software stack. When you call `qml.grad` in PennyLane or attach a gradient to a Qiskit `EstimatorQNN`, the framework builds the shifted circuits, dispatches them to simulator or hardware, and assembles the gradient by equations (3)–(5); the same tape composes with classical autodiff, so a variational classifier trains end-to-end by backpropagation through the measurement layer. On real devices, VQE runs for small molecules — H2_2, LiH, BeH2_2 on IBM, Google and trapped-ion processors — use shift-rule gradients to drive L-BFGS and Adam toward ground-state energies, and QAOA differentiates its cost and mixer angles the same way. It is also the measurement stick for the field's central obstruction: because the estimator's variance is exactly shot noise while barren plateaus drive the true gradient variance to O(2−n)O(2^{-n}), one can say precisely when signal drops beneath noise, motivating local cost functions, structured ansätze, and identity-block initializations. Active work pushes on shot-frugal estimators, pulse-level shift rules where hardware sets the generator spectrum, and quantum natural gradient, where the same shifted circuits supply the Fubini–Study metric that reshapes the descent direction.

The physical picture

A quantum cost is never an arbitrary function of a gate angle. Turning the knob on a rotation e−iθG/2e^{-i\theta G/2} sweeps the output state around a great circle, and any fixed observable traces a smooth periodic curve as it goes. For the workhorse case — a generator with eigenvalues ±1\pm1, which is every single Pauli rotation — that curve is a single sine wave, and a sine wave carries its own derivative in its shape: the slope of sin⁡θ\sin\theta is cos⁡θ\cos\theta, the same wave shifted a quarter-period. So "measure the curve a quarter-period to each side and halve the difference" literally reads the tangent off the function — no infinitesimal, no Taylor remainder, no step size to tune. The first figure makes this concrete for f(θ)=cos⁡θf(\theta)=\cos\theta: the chord joining the two ±π/2\pm\pi/2 evaluations has exactly the slope of the tangent at the centre.

Figure
One angle enters a two-eigenvalue-generator cost as a pure sinusoid f(θ) = cos θ, and its slope at θ₀ = π/3 is read off from two macroscopic evaluations at θ₀ ± π/2: half their difference is exactly the tangent slope −0.866, with no infinitesimal limit
A ±1-generator cost is one sine wave — its slope is two shifts away, exactly θ f(θ) +1 −1 0 π/2 π 3π/2 2π f(θ₀−π/2)=+0.866 θ₀=π/3 f(θ₀+π/2)=−0.866 tangent slope = ½[f(θ₀+π/2) − f(θ₀−π/2)] = −0.866 = f′(θ₀)

Contrast a classical finite difference, where you must send ϵ→0\epsilon\to0 to kill the bias, but a small ϵ\epsilon divides two noisy, nearly-equal numbers by a tiny denominator and amplifies the shot noise without bound. The quantum structure lets you use a large shift that is statistically benign, because the exactness comes from the functional form of ff, not from smallness. The gradient component is itself an observable — you run the same ansatz with one angle nudged by π/2\pi/2 — which is why the rule is hardware-friendly: no extra qubits, no controlled operations. The second figure shows the payoff: the finite-difference error is a U-shaped compromise, while the shift rule sits flat at the noise floor with zero bias.

Figure
Error of one gradient component versus step size, with observable variance σ = 1 and N = 1000 shots per evaluation: the finite-difference RMS error is a U-curve bottoming near 0.057 at step ≈ 0.48 where its bias ∝ s² meets its noise ∝ 1/s, while the parameter-shift rule is flat at the shot-noise floor 0.022 with no bias to trade
The punchline: finite difference trades bias against noise; the shift rule pays neither 0.01 0.03 0.1 0.3 1 0.02 0.1 0.5 2 step / shift s RMS error of ∂f finite difference: bias ∝ s² and noise ∝ 1/s best FD ≈ 0.057 parameter-shift rule: flat at floor 0.022, zero bias shift = π/2

The core equations

A variational algorithm packages the whole circuit into one scalar: an observable evaluated on a parameterized state, with fixed gates VℓV_\ell interleaving the tunable rotations and every knob θℓ\theta_\ell acting through its own generator.

f(θ)=⟨0∣ U†(θ) H U(θ) ∣0⟩,U(θ)=∏ℓVℓ e−iθℓGℓ/2(1)f(\boldsymbol\theta)=\langle 0|\,U^\dagger(\boldsymbol\theta)\,H\,U(\boldsymbol\theta)\,|0\rangle,\qquad U(\boldsymbol\theta)=\prod_{\ell} V_\ell\,e^{-i\theta_\ell G_\ell/2} \qquad (1)

where: ff — scalar cost to be minimized; HH — Hermitian observable, e.g. a molecular Hamiltonian; θℓ\theta_\ell — the ℓ\ell-th variational parameter; GℓG_\ell — Hermitian generator of the ℓ\ell-th gate; VℓV_\ell — fixed gates between the rotations. Reading it: the target ∂θℓf\partial_{\theta_\ell}f is the slope of this scalar as one knob turns, all others fixed. Isolate one parameter and fold the rest into constants. When the generator satisfies G2=IG^2=I (eigenvalues ±1\pm1) the dependence collapses to a single unit-frequency sinusoid — the algebraic heart of the subject.

f(θ)=A+Bcos⁡θ+Csin⁡θ(2)f(\theta)=A+B\cos\theta+C\sin\theta \qquad (2)

where: A,B,CA,B,C — constants fixed by HH and the rest of the circuit, independent of this θ\theta; θ\theta — the isolated parameter whose generator has eigenvalues ±1\pm1. Reading it: three numbers describe the whole slice of the landscape along this axis, so two evaluations pin down the slope. The exact derivative of a unit-frequency sinusoid is a symmetric difference at a quarter period — the two-term parameter-shift rule, the formula you use most of the time.

∂θf=12[f ⁣(θ+π2)−f ⁣(θ−π2)](3)\partial_\theta f=\tfrac12\Big[f\!\left(\theta+\tfrac{\pi}{2}\right)-f\!\left(\theta-\tfrac{\pi}{2}\right)\Big] \qquad (3)

where: ±π/2\pm\pi/2 — a macroscopic, exact shift, not an infinitesimal; 12\tfrac12 — the prefactor fixed by the unit gap of a Pauli generator. Reading it: run the identical circuit with this angle raised then lowered by π/2\pi/2, measure HH each time, and halve the difference. If GG has two eigenvalues ±r\pm r (gap 2r2r) rather than ±1\pm1, the cost oscillates at frequency rr and both shift and prefactor rescale.

∂θf=r2[f ⁣(θ+π2r)−f ⁣(θ−π2r)](4)\partial_\theta f=\frac{r}{2}\Big[f\!\left(\theta+\tfrac{\pi}{2r}\right)-f\!\left(\theta-\tfrac{\pi}{2r}\right)\Big] \qquad (4)

where: rr — half the spectral gap of GG (eigenvalues ±r\pm r), gate e−iθG/2e^{-i\theta G/2}. Reading it: the Pauli case r=1r=1 gives back equation (3); absorbing the 12\tfrac12 into the generator yields the equivalent form ∂θf=r[f(θ+π4r)−f(θ−π4r)]\partial_\theta f=r[f(\theta+\tfrac{\pi}{4r})-f(\theta-\tfrac{\pi}{4r})] seen in some references. A generator with more than one gap makes ff a finite Fourier series of KK harmonics, fixed by 2K2K equispaced samples with closed-form derivative weights.

∂θf=∑μ=12K(−1)μ−14K sin⁡2 ⁣((2μ−1)π4K)  f ⁣(θ+(2μ−1)π2K)(5)\partial_\theta f=\sum_{\mu=1}^{2K} \frac{(-1)^{\mu-1}}{4K\,\sin^2\!\big(\tfrac{(2\mu-1)\pi}{4K}\big)}\; f\!\left(\theta+\tfrac{(2\mu-1)\pi}{2K}\right) \qquad (5)

where: KK — number of distinct positive frequencies (gaps) in GG's spectrum; 2K2K — evaluations required. Reading it: for K=1K=1 the weights are +12+\tfrac12 and −12-\tfrac12 at θ±π2\theta\pm\tfrac\pi2, exactly the two-term rule; more harmonics cost more shifted runs. For a generator with no exploitable spectral structure, differentiate the conjugated observable directly: the gradient becomes a commutator expectation — an imaginary part measurable with one ancilla via a Hadamard test.

∂θℓf=i2 ⟨ψ∣ [ H~, Gℓ ] ∣ψ⟩=− Im ⟨ψ∣ H~ Gℓ ∣ψ⟩(6)\partial_{\theta_\ell} f = \tfrac{i}{2}\,\big\langle\psi\big|\,[\,\tilde H,\,G_\ell\,]\,\big|\psi\big\rangle=-\,\mathrm{Im}\,\big\langle\psi\big|\,\tilde H\,G_\ell\,\big|\psi\big\rangle \qquad (6)

where: H~=U>ℓ†H U>ℓ\tilde H=U_{>\ell}^\dagger H\,U_{>\ell} — observable conjugated by all gates after the ℓ\ell-th; ∣ψ⟩|\psi\rangle — state right after the ℓ\ell-th gate; GℓG_\ell — arbitrary Hermitian generator. Reading it: always works, but costs a controlled-GG and an ancilla, so it is the fallback when equations (3)–(5) do not apply. Finally, every shifted evaluation is estimated from finite shots, so the gradient carries a shot-noise variance that no amount of exactness removes.

Var[g^]  ≈  14 σ+2+σ−2Nshots(7)\mathrm{Var}[\hat g]\;\approx\;\frac{1}{4}\,\frac{\sigma_+^2+\sigma_-^2}{N_\mathrm{shots}} \qquad (7)

where: g^\hat g — the sampled estimate of ∂θf\partial_\theta f from one pair of shifted evaluations; σ±2\sigma_\pm^2 — single-shot variance of HH at the two shifted points; NshotsN_\mathrm{shots} — measurement shots per shifted evaluation. Reading it: the 14\tfrac14 is the square of the 12\tfrac12 prefactor, and the variance falls only as 1/Nshots1/N_\mathrm{shots} — the true cost of the rule is sampling, not arithmetic.

Derivation AWhy one angle enters as a single sinusoid

The goal is to prove equation (2) from the algebra of a single involutory rotation: no matter how deep or entangled the surrounding circuit, the cost's dependence on one ±1\pm1-generator angle is exactly A+Bcos⁡θ+Csin⁡θA+B\cos\theta+C\sin\theta, only three real constants. Everything downstream — the exactness of the two-term rule, the evaluation count, the whole spectral picture — follows from this collapse to unit frequency, so it is worth doing carefully with the Euler identity that Pauli rotations obey.

Step 1. Split the circuit at the gate. Write U(θ)=W e−iθG/2 VU(\boldsymbol\theta)=W\,e^{-i\theta G/2}\,V, let ∣ϕ⟩=V∣0⟩|\phi\rangle=V|0\rangle be the state entering it, and absorb everything after into H~=W†HW\tilde H=W^\dagger H W, so f(θ)=⟨ϕ∣ eiθG/2 H~ e−iθG/2 ∣ϕ⟩f(\theta)=\langle\phi|\,e^{i\theta G/2}\,\tilde H\,e^{-i\theta G/2}\,|\phi\rangle. Why: the only θ\theta-dependence left is a pair of exponentials conjugating a fixed observable.

Step 2. Use the involutory Euler identity. Because G2=IG^2=I, the exponential truncates exactly to e−iθG/2=cos⁡(θ/2) I−isin⁡(θ/2) Ge^{-i\theta G/2}=\cos(\theta/2)\,I-i\sin(\theta/2)\,G — the same identity behind single-qubit Pauli rotations. Why: the exponential becomes a linear combination of II and GG, so conjugation yields only products of half-angle functions.

Step 3. Expand. Multiplying out, eiθG/2H~e−iθG/2=cos⁡2 ⁣θ2 H~+sin⁡2 ⁣θ2 GH~G+isin⁡θ2cos⁡θ2 [G,H~]e^{i\theta G/2}\tilde H e^{-i\theta G/2}=\cos^2\!\tfrac\theta2\,\tilde H+\sin^2\!\tfrac\theta2\,G\tilde H G+i\sin\tfrac\theta2\cos\tfrac\theta2\,[G,\tilde H]; taking the expectation gives f(θ)=cos⁡2 ⁣θ2 a+sin⁡2 ⁣θ2 b+sin⁡θ cf(\theta)=\cos^2\!\tfrac\theta2\,a+\sin^2\!\tfrac\theta2\,b+\sin\theta\,c for real a,b,ca,b,c. Why: the cross term carries 2sin⁡θ2cos⁡θ2=sin⁡θ2\sin\tfrac\theta2\cos\tfrac\theta2=\sin\theta; the squared terms recombine to a constant plus cos⁡θ\cos\theta.

Step 4. Collapse to unit frequency. With cos⁡2θ2=1+cos⁡θ2\cos^2\tfrac\theta2=\tfrac{1+\cos\theta}{2} and sin⁡2θ2=1−cos⁡θ2\sin^2\tfrac\theta2=\tfrac{1-\cos\theta}{2}, f(θ)=a+b2+a−b2cos⁡θ+c sin⁡θ≡A+Bcos⁡θ+Csin⁡θf(\theta)=\tfrac{a+b}{2}+\tfrac{a-b}{2}\cos\theta+c\,\sin\theta\equiv A+B\cos\theta+C\sin\theta. Why: a single gap admits no harmonic above one, so the landscape along this axis is a lone sine wave — the fact the whole rule exploits. *Verified: setting G=YG=Y, H~=Z\tilde H=Z, ∣ϕ⟩=∣0⟩|\phi\rangle=|0\rangle gives a=1,b=−1,c=0a=1,b=-1,c=0, so f(θ)=cos⁡θf(\theta)=\cos\theta — matching the direct calculation ⟨0∣Ry†ZRy∣0⟩=cos⁡θ\langle 0|R_y^\dagger Z R_y|0\rangle=\cos\theta used in Worked example 1.*

Go deeper · Derivation B · 1 minExactness of the two-shift rule at π/2
Derivation BExactness of the two-shift rule at π/2

The goal is to show that the symmetric difference in equation (3) equals the derivative identically, for every θ\theta, with no truncation error — the property that separates the parameter-shift rule from a finite difference that merely uses the same step size. We start from the sinusoidal form just proved, evaluate the two macroscopic shifts with elementary angle-addition identities, and compare term by term with the analytic derivative, making the cancellation of the constant and the survival of exactly the derivative visible.

Step 1. Evaluate the two shifts. From f(θ)=A+Bcos⁡θ+Csin⁡θf(\theta)=A+B\cos\theta+C\sin\theta, use cos⁡(θ±π2)=∓sin⁡θ\cos(\theta\pm\tfrac\pi2)=\mp\sin\theta and sin⁡(θ±π2)=±cos⁡θ\sin(\theta\pm\tfrac\pi2)=\pm\cos\theta. Why: a π/2\pi/2 shift maps cos⁡→∓sin⁡\cos\to\mp\sin and sin⁡→±cos⁡\sin\to\pm\cos exactly — the quarter-period phase relation between a sinusoid and its derivative.

Step 2. Subtract. This gives f(θ+π2)=A−Bsin⁡θ+Ccos⁡θf(\theta+\tfrac\pi2)=A-B\sin\theta+C\cos\theta and f(θ−π2)=A+Bsin⁡θ−Ccos⁡θf(\theta-\tfrac\pi2)=A+B\sin\theta-C\cos\theta, so f(θ+π2)−f(θ−π2)=−2Bsin⁡θ+2Ccos⁡θf(\theta+\tfrac\pi2)-f(\theta-\tfrac\pi2)=-2B\sin\theta+2C\cos\theta. Why: the constant AA cancels and the oscillatory pieces reinforce, leaving twice the derivative's amplitude with no remainder of any order.

Step 3. Compare. The analytic derivative ∂θf=−Bsin⁡θ+Ccos⁡θ\partial_\theta f=-B\sin\theta+C\cos\theta is exactly half the difference: 12[f(θ+π2)−f(θ−π2)]=∂θf\tfrac12[f(\theta+\tfrac\pi2)-f(\theta-\tfrac\pi2)]=\partial_\theta f for all θ\theta. Why: unlike a finite difference, whose Taylor remainder is O(ϵ2)O(\epsilon^2) and vanishes only as ϵ→0\epsilon\to0, this equality is algebraic and holds at the macroscopic shift π/2\pi/2. *Verified: at θ=0\theta=0 with B=0,C=1B=0,C=1 (so f=sin⁡θf=\sin\theta), 12[sin⁡(π2)−sin⁡(−π2)]=12[1−(−1)]=1=cos⁡0=∂θsin⁡θ∣0\tfrac12[\sin(\tfrac\pi2)-\sin(-\tfrac\pi2)]=\tfrac12[1-(-1)]=1=\cos 0=\partial_\theta\sin\theta|_0; numerically at θ=π/3\theta=\pi/3 with f=cos⁡θf=\cos\theta, 12[cos⁡(5π/6)−cos⁡(−π/6)]=−0.8660=−sin⁡(π/3)\tfrac12[\cos(5\pi/6)-\cos(-\pi/6)]=-0.8660=-\sin(\pi/3).*

Go deeper · Derivation C · 1 minFrom the spectral gap to the general multi-term rule
Derivation CFrom the spectral gap to the general multi-term rule

The goal is to extend the rule beyond involutory generators: first to a single arbitrary gap 2r2r, fixing the rescaled shift and prefactor of equation (4), then to a generator with KK distinct gaps, where the cost is a band-limited Fourier series and the derivative comes from trigonometric interpolation on 2K2K equispaced points as in equation (5). The thread throughout: each pairwise eigenvalue difference of the generator contributes one harmonic, so the harmonic count sets the evaluation count.

Step 1. Find the frequency from the spectrum. Diagonalize G=∑jλj∣j⟩⟨j∣G=\sum_j\lambda_j|j\rangle\langle j|; the conjugated observable has matrix elements ⟨m∣eiθG/2H~e−iθG/2∣n⟩=eiθ(λm−λn)/2H~mn\langle m|e^{i\theta G/2}\tilde H e^{-i\theta G/2}|n\rangle=e^{i\theta(\lambda_m-\lambda_n)/2}\tilde H_{mn}. For a two-eigenvalue generator with λ∈{+r,−r}\lambda\in\{+r,-r\} the only nonzero off-diagonal frequency is (λm−λn)/2=±r(\lambda_m-\lambda_n)/2=\pm r, so f(θ)=A+Bcos⁡(rθ)+Csin⁡(rθ)f(\theta)=A+B\cos(r\theta)+C\sin(r\theta). Why: the cost oscillates at the eigenvalue differences of the generator, and a single gap 2r2r produces a single frequency rr in θ\theta.

Step 2. Rescale the shift. The subtraction gives f(θ+s)−f(θ−s)=2sin⁡(rs)[Ccos⁡(rθ)−Bsin⁡(rθ)]=2sin⁡(rs)r ∂θff(\theta+s)-f(\theta-s)=2\sin(rs)[C\cos(r\theta)-B\sin(r\theta)]=\tfrac{2\sin(rs)}{r}\,\partial_\theta f; choosing rs=π2rs=\tfrac\pi2 (so s=π2rs=\tfrac{\pi}{2r}) makes sin⁡(rs)=1\sin(rs)=1 and yields ∂θf=r2[f(θ+π2r)−f(θ−π2r)]\partial_\theta f=\tfrac r2[f(\theta+\tfrac{\pi}{2r})-f(\theta-\tfrac{\pi}{2r})]. Why: the shift sits at the sinusoid's quarter period and r/2r/2 compensates the frequency; r=1r=1 is the two-term rule exactly.

Step 3. Add harmonics and interpolate. A multi-gap generator gives f(θ)=a0+∑k=1K(akcos⁡kθ+bksin⁡kθ)f(\theta)=a_0+\sum_{k=1}^{K}(a_k\cos k\theta+b_k\sin k\theta) with frequencies k∈{∣λi−λj∣}k\in\{|\lambda_i-\lambda_j|\}. The 2K2K equispaced points θμ=θ+(2μ−1)π2K\theta_\mu=\theta+\tfrac{(2\mu-1)\pi}{2K} fix all coefficients, and the even grid's spectral-differentiation weights give equation (5). Why: differentiating an interpolating trigonometric polynomial is exact for a band-limited function, so 2K2K evaluations reproduce the derivative with no error — the natural generalization of the two-point rule. *Verified: for K=1K=1 the weights are 14sin⁡2(π/4)=+12\tfrac{1}{4\sin^2(\pi/4)}=+\tfrac12 at θ+π2\theta+\tfrac\pi2 and −14sin⁡2(3π/4)=−12-\tfrac{1}{4\sin^2(3\pi/4)}=-\tfrac12 at θ+3π2=θ−π2\theta+\tfrac{3\pi}{2}=\theta-\tfrac\pi2, collapsing to equation (3); numerically the r=2r=2 gap rule with s=π/4s=\pi/4 and prefactor 11 reproduces the analytic derivative to machine precision.*

Limiting cases

The form of the exact rule is dictated entirely by the eigenvalue spectrum of the generator — how many distinct gaps it has, and how large they are.

CaseResultMeaning
Involutory generator (G2=IG^2=I, eigenvalues ±1\pm1)∂θf=12[f(θ+π2)−f(θ−π2)]\partial_\theta f=\tfrac12[f(\theta+\tfrac{\pi}{2})-f(\theta-\tfrac{\pi}{2})]Single Pauli rotations RP(θ)=e−iθP/2R_P(\theta)=e^{-i\theta P/2}; two evaluations, exact — the common case.
Two-eigenvalue gap 2r2r (eigenvalues ±r\pm r)∂θf=r2[f(θ+π2r)−f(θ−π2r)]\partial_\theta f=\tfrac r2[f(\theta+\tfrac{\pi}{2r})-f(\theta-\tfrac{\pi}{2r})]Shift and prefactor scale with the gap; recovers the ±π/2\pm\pi/2 rule at r=1r=1.
Multi-gap generator (KK distinct frequencies)∂θf=∑μ=12Kcμ f(θ+sμ)\partial_\theta f=\sum_{\mu=1}^{2K} c_\mu\,f(\theta+s_\mu)Generalized rule: 2K2K equispaced evaluations interpolate the band-limited cost.
Arbitrary / non-decomposable generator∂θf=−Im ⟨ψ∣H~ G∣ψ⟩\partial_\theta f=-\mathrm{Im}\,\langle\psi|\tilde H\,G|\psi\rangle via ancillaHadamard test with one ancilla and a controlled-GG; works for any GG.
Vanishing true gradient (barren plateau)Varθ[∂θf]=O(2−n)\mathrm{Var}_{\boldsymbol\theta}[\partial_\theta f]=O(2^{-n})The rule is still exact, but the signal drops below shot noise — a trainability wall, not a formula failure.

Worked examples

1 · A single-qubit gradient, exact versus finite difference (fully worked)

Take f(θ)=⟨0∣Ry†(θ) Z Ry(θ)∣0⟩f(\theta)=\langle 0|R_y^\dagger(\theta)\,Z\,R_y(\theta)|0\rangle with Ry(θ)=e−iθY/2R_y(\theta)=e^{-i\theta Y/2}. Find the analytic gradient at θ0=π/3\theta_0=\pi/3, evaluate it with the two-term shift rule, and compare with a central finite difference.

Step 1. Get the cost in closed form. Ry(θ)∣0⟩=cos⁡θ2∣0⟩+sin⁡θ2∣1⟩R_y(\theta)|0\rangle=\cos\tfrac\theta2|0\rangle+\sin\tfrac\theta2|1\rangle, so ⟨Z⟩=cos⁡2θ2−sin⁡2θ2=cos⁡θ\langle Z\rangle=\cos^2\tfrac\theta2-\sin^2\tfrac\theta2=\cos\theta. Thus f(θ)=cos⁡θf(\theta)=\cos\theta, of the form A+Bcos⁡θ+Csin⁡θA+B\cos\theta+C\sin\theta with A=0,B=1,C=0A=0,B=1,C=0 — a clean ±1\pm1-generator sinusoid. The analytic derivative is ∂θf=−sin⁡θ\partial_\theta f=-\sin\theta, so at θ0=π/3\theta_0=\pi/3 the true value is −sin⁡(π/3)=−0.86603-\sin(\pi/3)=\mathbf{-0.86603}.

Step 2. Apply the two-term rule. Using equation (3), ∂θf=12[f(π3+π2)−f(π3−π2)]=12[cos⁡(5π6)−cos⁡(−π6)]=12[−32−32]=−0.86603\partial_\theta f=\tfrac12[f(\tfrac\pi3+\tfrac\pi2)-f(\tfrac\pi3-\tfrac\pi2)]=\tfrac12[\cos(\tfrac{5\pi}{6})-\cos(-\tfrac\pi6)]=\tfrac12[-\tfrac{\sqrt3}{2}-\tfrac{\sqrt3}{2}]=\mathbf{-0.86603}. It matches the analytic derivative to every digit — as it must, since the equality is exact for this functional form. The shift rule reproduces −0.86603 with no error.

Step 3. Compare a finite difference. With a central difference [f(θ0+ϵ)−f(θ0−ϵ)]/2ϵ[f(\theta_0+\epsilon)-f(\theta_0-\epsilon)]/2\epsilon on the same noiseless function: at ϵ=0.5\epsilon=0.5 it gives −0.83039-0.83039 (error +0.036+0.036), at ϵ=0.1\epsilon=0.1 it gives −0.86458-0.86458 (error +0.0014+0.0014), at ϵ=0.01\epsilon=0.01 it gives −0.86601-0.86601 (error +0.00001+0.00001). The bias shrinks as ϵ2\epsilon^2, so you would push ϵ\epsilon small — but under shot noise the statistical error of that same estimate grows as 1/ϵ1/\epsilon, so a tiny ϵ\epsilon is unusable in practice. The shift rule is exact at a macroscopic π/2\pi/2; the finite difference is only asymptotically correct and noise-limited.

2 · The shot budget for a gradient step

A hardware-efficient VQE ansatz has p=100p=100 single-Pauli-rotation parameters. Each expectation value is measured with ⟨H⟩\langle H\rangle scaled so the single-shot variance is σ2≈1\sigma^2\approx1. How many shots does one full gradient cost if each component must be resolved to standard error δ=0.01\delta=0.01?

Step 1. Cost of one component. By equation (7), Var[g^]≈14(σ+2+σ−2)/Nshots\mathrm{Var}[\hat g]\approx\tfrac14(\sigma_+^2+\sigma_-^2)/N_\mathrm{shots}. Taking the worst case σ±2=1\sigma_\pm^2=1, this is 12Nshots\tfrac{1}{2N_\mathrm{shots}}, so the standard error is 1/2Nshots1/\sqrt{2N_\mathrm{shots}}. Setting it equal to δ=0.01\delta=0.01 gives Nshots=1/(2δ2)=5000N_\mathrm{shots}=1/(2\delta^2)=\mathbf{5000} shots per shifted evaluation.

Step 2. Two evaluations per component. The two-term rule needs the circuit at θ+π2\theta+\tfrac\pi2 and θ−π2\theta-\tfrac\pi2, so one gradient component costs 2Nshots=10 0002N_\mathrm{shots}=\mathbf{10\,000} shots.

Step 3. Scale to the full gradient. With p=100p=100 independent parameters and no shot reuse, one full gradient evaluation costs 2p Nshots=2(100)(5000)=1062p\,N_\mathrm{shots}=2(100)(5000)=\mathbf{10^{6}} shots. A single optimizer step already burns a million shots — which is why shot-frugal estimators and the O(2−n)O(2^{-n}) shrinkage of barren plateaus dominate the practical cost of variational algorithms far more than the arithmetic of the rule does.

3 · Counting evaluations for a multi-gap generator

A gate is e−iθHC/2e^{-i\theta H_C/2} where the cost Hamiltonian HCH_C has four distinct eigenvalues. How many shifted evaluations does the exact gradient need?

Step 1. Count the harmonics. The frequencies are the distinct positive eigenvalue differences, at most (42)=6\binom{4}{2}=6, so K≤6K\le6 and the generalized rule of equation (5) needs up to 2K=122K=\mathbf{12} equispaced evaluations — two would be badly biased.

Step 2. Prefer decomposition. If HC=∑acaPaH_C=\sum_a c_a P_a is a sum of commuting Paulis, each e−iθcaPa/2e^{-i\theta c_a P_a/2} is a two-eigenvalue gate handled by the cheap two-term rule, and ∂θf\partial_\theta f is the sum. Exploiting structure turns one 12-evaluation problem into several 2-evaluation ones — usually far cheaper.

Physics of the portrait

The parameter-shift rule is barely a decade old, yet it already anchors an entire subfield: the point where a purely quantum fact — that a Pauli rotation makes any observable a lone sinusoid — meets the classical business of gradient descent. The story of who noticed this, and how it generalized, is the story of variational quantum computing finding its footing.

Origins · 1 minparameter-shift rule and how this was discovered
PR
parameter-shift rule
analytic quantum gradients from shifted circuit evaluations · variational quantum algorithms and quantum machine learning

The parameter-shift rule is one of the youngest load-bearing ideas in quantum computing, and unlike most of the field it was invented under pressure of practice rather than principle. The prehistory is Stephen Jordan's 2005 quantum algorithm for numerical gradient estimation, which read a black-box derivative from phase kickback — elegant, but demanding coherent oracle access no near-term device could give. The modern rule was born when noisy intermediate-scale hardware forced a different question: how do you differentiate a circuit you can only sample? In 2018, Kosuke Mitarai, Makoto Negoro, Masahiro Kitagawa and Keisuke Fujii, framing "quantum circuit learning," observed that a Pauli-generated gate makes the cost a sinusoid whose derivative is an exact difference of two shifted expectation values — no ancilla, no finite-difference bias. In 2019, Maria Schuld, Ville Bergholm, Christian Gogolin, Josh Izaac and Nathan Killoran sharpened this into the clean two-term ±π/2\pm\pi/2 statement, proved its exactness, and made it the differentiation engine now sitting under PennyLane and Qiskit's gradient tapes. Generalization followed fast: Banchi and Crooks gave stochastic and multi-frequency forms, and in 2022 David Wierichs, Josh Izaac, Cody Wang and Cedric Yen-Yu Lin derived the general equidistant multi-term rules from Fourier interpolation, settling exactly how many evaluations a given spectrum demands. What began as a hardware convenience turned out to be the natural calculus of variational circuits — the reason "training a quantum model" means something concrete.

History
2005
— Jordan gives a quantum algorithm for numerical gradient estimation by phase kickback
2017
— Guerreschi and Smelyanskiy study practical gradient optimization for hybrid quantum-classical algorithms
2018
— Mitarai, Negoro, Kitagawa and Fujii introduce quantum circuit learning with the shift-rule gradient
2019
— Schuld, Bergholm, Gogolin, Izaac and Killoran prove the two-term ±π/2 analytic gradient on hardware
2022
— Wierichs, Izaac, Wang and Lin derive the general equidistant multi-term parameter-shift rules

Going further

References. Mitarai, Negoro, Kitagawa, Fujii — Quantum circuit learning, Phys. Rev. A 98, 032309 (2018) · Schuld, Bergholm, Gogolin, Izaac, Killoran — Evaluating analytic gradients on quantum hardware, Phys. Rev. A 99, 032331 (2019) · Wierichs, Izaac, Wang, Lin — General parameter-shift rules for quantum gradients, Quantum 6, 677 (2022) · Banchi, Crooks — Measuring analytic gradients with the stochastic parameter-shift rule, Quantum 5, 386 (2021) · Cerezo et al. — Variational Quantum Algorithms, Nat. Rev. Phys. 3, 625 (2021) · Nielsen & Chuang — Quantum Computation and Quantum Information (single-qubit rotation generators).

Provenance. The sinusoidal collapse (equation 2) is re-derived from the involutory identity e−iθP/2=cos⁡θ2 I−isin⁡θ2 Pe^{-i\theta P/2}=\cos\tfrac\theta2\,I-i\sin\tfrac\theta2\,P (Nielsen & Chuang) and the conjugated-observable expansion; a verifier should confirm f(θ)=cos⁡θf(\theta)=\cos\theta for the RyR_y–ZZ circuit of Worked example 1. The two-term rule and its exactness proof are owned by Mitarai et al. (2018) and Schuld et al. (2019); check the ±π/2\pm\pi/2 equality as in Derivation 2 (−sin⁡(π/3)=−0.86603-\sin(\pi/3)=-0.86603). The generalized 2K2K-term weights and the K=1K=1 collapse are Wierichs et al. (2022). The gap-rule convention here (gate e−iθG/2e^{-i\theta G/2}, eigenvalues ±r\pm r, shift π/2r\pi/2r, prefactor r/2r/2) reconciles with the absorbed-12\tfrac12 form r[f(θ±π4r)]r[f(\theta\pm\tfrac{\pi}{4r})]; both verified to reproduce the analytic derivative. Variance and shot scaling connect to Cost-Function and Measurement Estimation and Cerezo et al. (2021).

Prerequisites. Parameterized Quantum Circuits and Ansatz Design · Variational Quantum Eigensolver · Cost-Function and Measurement Estimation in Variational Algorithms. Leads to. Classical Optimizers for Variational Quantum Algorithms · Barren Plateaus in Variational Landscapes · Quantum Machine Learning Models.

Ask the tutor: Ask me to walk through the two-term rule on your own ansatz, or to count exactly how many shifted evaluations your gate's generator spectrum demands.

Is the parameter-shift rule just a finite difference with a big step?

It looks identical in form — two evaluations, subtract, scale — but the meaning differs. A finite difference approximates the derivative by assuming a Taylor expansion, accepting an O(ϵ2)O(\epsilon^2) truncation error that only vanishes as ϵ→0\epsilon\to0. The shift rule uses the exact fact that the cost along one ±1\pm1-generator axis is a unit-frequency sinusoid, and a symmetric difference of a sinusoid at ±π/2\pm\pi/2 equals its derivative algebraically, for any θ\theta, with no remainder. So it is a finite difference only in appearance and an exact identity in substance — which is why the macroscopic π/2\pi/2 shift works where a finite difference would carry a large bias.

Does the rule need extra qubits or controlled operations?

For the two-term rule and the generalized multi-term rule, no. You re-run the same ansatz on the same qubits with one angle offset by the prescribed shift and measure the same observable — nothing controlled, no ancilla — which is what makes it hardware-friendly on near-term devices. The only version needing an extra qubit is the ancilla form of equation (6), used when a generator has no exploitable spectral structure and cannot be decomposed: there you perform a Hadamard test with a controlled-GG to read off a commutator's imaginary part. In practice most ansätze are built from Pauli rotations, so the cheap ancilla-free rules cover the overwhelming majority of cases.

Why is a macroscopic π/2 shift better than a tiny one?

Because the exactness comes from the functional form, not from smallness, so you are free to choose the shift that minimizes noise — the largest, π/2\pi/2. The estimator's variance scales as 1/sin⁡2(shift)1/\sin^2(\text{shift}) times shot noise, and π/2\pi/2 sits at sin⁡=1\sin=1, the minimum. A small shift instead divides two noisy, nearly-equal expectation values by a tiny denominator and amplifies the statistical error with no compensating gain, since there is no bias left to reduce. So where finite differences face a genuine bias–variance tradeoff, the shift rule has no bias and simply picks the variance-minimizing macroscopic shift outright.

What happens if one parameter appears in several gates?

The two-term rule can break, because the cost then depends on the shared parameter through a sum of frequencies rather than one — even if each gate has a two-eigenvalue generator. You differentiate either by the product rule (shift each occurrence separately and add, treating them as independent parameters that share a value) or by the generalized multi-term rule keyed to the combined spectrum. This "weight tying" is common in quantum machine learning, where a data-reuploading circuit reuses a trainable parameter across layers, and forgetting it silently corrupts gradients. When in doubt, count the distinct frequencies the parameter induces and use 2K2K evaluations.

How does the parameter-shift rule relate to barren plateaus?

They are two halves of the trainability story. The shift rule computes an unbiased gradient at two evaluations per parameter, with estimator variance that is pure shot noise falling as 1/Nshots1/N_\mathrm{shots}. Barren plateaus concern the true gradient: for deep, expressive, or global-cost circuits its variance over random parameters shrinks as O(2−n)O(2^{-n}), so the actual slope is exponentially tiny. Together, the exact gradient you can compute is buried beneath shot noise unless you take exponentially many shots. The rule is not the culprit — it is the diagnostic that makes the plateau quantitative, motivating local cost functions, shallow structured ansätze, and careful initialization.

Can I use the shift rule for second derivatives and the natural gradient?

Yes. Applying it twice — shifting two parameters, or the same one, by ±π/2\pm\pi/2 each — gives exact Hessian entries at four evaluations per pair, which some optimizers use for curvature. More importantly, the same shifted circuits supply the quantum Fisher information, or Fubini–Study metric, defining the quantum natural gradient: instead of stepping along −∂θf-\partial_\theta f you step along the metric-corrected direction, which respects state-space geometry and often converges faster. The metric is built from overlaps of shifted states, measurable by the same hardware-friendly machinery. So the rule is not only a first-derivative tool but the common engine behind first-order, curvature-aware, and geometry-aware training of variational circuits.

Before this

Where this leads