ConceptIntermediateTraining and gradients

Parameter-Shift Rule

The parameter-shift rule computes the exact derivative of an expectation value with respect to the angle of a gate $e^{-i\theta P/2}$ from two evaluations of the same circuit at $\theta\pm\pi/2$.

For a function $f(\theta)=\langle\psi|U^\dagger(\theta)OU(\theta)|\psi\rangle$ where the parameterised gate is $e^{-i\theta P/2}$ and its generator $P/2$ has the two eigenvalues $\pm\tfrac12$, we have $f(\theta)=a+b\cos\theta+c\sin\theta$, and hence $$\frac{\partial f}{\partial\theta}=\frac{f(\theta+\tfrac{\pi}{2})-f(\theta-\tfrac{\pi}{2})}{2}.$$ This is not an approximate finite difference; it is an exact equality, and the shift is large, so shot errors are not amplified as they are in finite differences with small steps. Mitarai and colleagues (2018) introduced this formula in the context of circuit learning, Schuld and colleagues developed it further, and it is used in PennyLane.

Cost: two evaluations per parameter, i.e. $2P$ evaluations for the full gradient. If one parameter appears in several gates, their contributions are summed. Gates whose generators have more than two distinct eigenvalues need generalised shift rules with more terms. The lab uses this rule to compute the gradients of the variational classifier.

Compare this with finite differences $[f(\theta+h)-f(\theta-h)]/2h$: with small $h$ the numerator becomes a small difference between two noisy values, so the shot error is amplified by a factor of $1/h$; the shift rule uses $h=\pi/2$ and stays exact.

Mathematical formula

$$\frac{\partial f}{\partial\theta}=\frac{1}{2}\left[f\!\left(\theta+\frac{\pi}{2}\right)-f\!\left(\theta-\frac{\pi}{2}\right)\right]$$

Worked example

$f(\theta)=\langle0|R_X(\theta)^\dagger ZR_X(\theta)|0\rangle=\cos\theta$. At $\theta=\pi/3$: $f(\pi/3+\pi/2)=\cos(5\pi/6)=-0.866$ and $f(\pi/3-\pi/2)=\cos(-\pi/6)=0.866$, so the derivative is $\tfrac12(-0.866-0.866)=-0.866=-\sin(\pi/3)$, matching the analytical derivative.

Test your understanding

The quiz needs JavaScript.

Related topics

References

  1. K. Mitarai; M. Negoro; M. Kitagawa; K. Fujii (2018). Quantum circuit learning. Phys. Rev. A 98:032309 doi:10.1103/PhysRevA.98.032309
  2. Xanadu (2025). Parameter-shift rules. PennyLane Glossary pennylane.ai
  3. Maria Schuld; Francesco Petruccione (2021). Machine Learning with Quantum Computers. Springer (Quantum Science and Technology) doi:10.1007/978-3-030-83098-4