• Algorithms
  • Also: quantum gradient
  • Also: analytic quantum gradient

Parameter-Shift Rule

The parameter-shift rule is a method for computing exact gradients of quantum circuits on real hardware by evaluating the circuit at shifted parameter values, enabling gradient-based optimization of variational quantum algorithms.

The parameter-shift rule computes the exact gradient of a quantum circuit expectation value with respect to a rotation gate parameter, using only circuit evaluations. Unlike finite differences, it gives exact gradients that work on real quantum hardware without added noise.

The Rule

For a parameterized gate of the form R(θ) = exp(-i θ G / 2) where G is a Pauli operator (Pauli X, Y, or Z), the gradient is:

d/dθ ⟨ψ(θ)|M|ψ(θ)⟩ = (1/2) [f(θ + π/2) - f(θ - π/2)]

Where f(θ) = ⟨ψ(θ)|M|ψ(θ)⟩ is the expectation value at parameter θ.

This means: evaluate the circuit at θ + π/2, evaluate it again at θ - π/2, take the difference, and divide by 2. That is the exact gradient.

Why It Works

Pauli rotation gates have eigenvalues ±1, which means their generator G has only two eigenvalues (±1/2 for standard parameterization). This restricted spectrum is what makes the two-point evaluation exact rather than approximate. For generators with more eigenvalues, generalized parameter-shift rules require more evaluation points.

Advantage Over Finite Differences

Classical finite differences estimate the gradient as:

df/dθ ≈ [f(θ + ε) - f(θ)] / ε

This approximation has error proportional to ε and is sensitive to shot noise. The parameter-shift rule evaluates at θ ± π/2 (large shifts) and gives an exact result regardless of shot noise contributions, as the shift acts as its own differentiating mechanism.

In PennyLane

PennyLane uses the parameter-shift rule by default for gradients:

import pennylane as qml
import numpy as np

dev = qml.device("default.qubit", wires=2)

@qml.qnode(dev, diff_method="parameter-shift")
def circuit(theta):
    qml.RY(theta, wires=0)
    qml.CNOT(wires=[0, 1])
    return qml.expval(qml.PauliZ(0))

theta = np.array(0.5, requires_grad=True)
grad = qml.grad(circuit)(theta)
print(f"Gradient: {grad:.4f}")
# Same result using only two circuit evaluations

The diff_method="parameter-shift" is the hardware-compatible gradient method. It works on real devices via cloud APIs because it requires only additional circuit evaluations, not special hardware features.

Cost

Computing the gradient of all n parameters in a circuit requires 2n circuit evaluations. For deep circuits with many parameters, this can be expensive. Techniques like stochastic gradient descent, which computes gradients for a random subset of parameters per step, reduce this cost in practice.

See also