
The Parameter-Shift Rule: Two Circuit Runs for an Exact Gradient
For a single Pauli rotation, the parameter-shift rule gives an exact expectation-value derivative from two shifted circuit evaluations. See it on a one-qubit Ry example.
Training a parameterized quantum circuit means adjusting gate angles until a measured objective improves. A classical optimizer needs derivatives, but a quantum device gives measurement samples rather than a differentiable statevector. For common rotation gates, the parameter-shift rule rewrites a derivative as a difference of ordinary circuit expectation values at two shifted angles.
The rule on one qubit
Start in |0⟩, apply R_y(theta), and measure Z. The expectation is f(theta) = cos(theta), so its derivative is -sin(theta). Since R_y(theta) = exp(-i theta Y/2) is generated by a Pauli operator with eigenvalues plus and minus one half, its exact shift rule is:
df/dtheta = [f(theta + pi/2) - f(theta - pi/2)] / 2
The two circuit evaluations do not use a tiny step. Their pi/2 shifts come from the gate's generator, which is why this is an exact derivative of the ideal expectation, not a finite-difference approximation. The original derivation by Schuld and colleagues explains how the rule applies to gates with two distinct generator eigenvalues.
This NumPy snippet simulates the one-qubit state and checks the shifted result against the analytic derivative:
import numpy as np
ket0 = np.array([1, 0], dtype=complex)
Z = np.diag([1, -1])
def expectation_z(theta):
c, s = np.cos(theta / 2), np.sin(theta / 2)
R_y = np.array([[c, -s], [s, c]], dtype=complex)
psi = R_y @ ket0
return float(np.real(np.vdot(psi, Z @ psi)))
theta = 0.7
shift = np.pi / 2
gradient = (expectation_z(theta + shift) - expectation_z(theta - shift)) / 2
print(f"parameter-shift = {gradient:.6f}")
print(f"exact derivative = {-np.sin(theta):.6f}")
Both lines print about -0.644218. The code computes exact statevector expectations; on a quantum processor, each expectation is estimated from repeated shots, so the gradient still has sampling noise.
When two shifts are not enough
The formula above applies to one occurrence of a Pauli rotation such as R_x, R_y, or R_z. If the same classical parameter controls several gates, differentiate each gate occurrence and add its contribution. For generators with more than two distinct eigenvalues, generalized parameter-shift rules can require additional shifted evaluations. Work on generalized rules lays out those cases. This distinction matters when turning a neat single-gate identity into a reliable gradient routine for a larger variational circuit.