Skip to main content

Module gradient

Module gradient 

Source
Expand description

Gradients of expectation values, by the adjoint method and by parameter shift.

Both compute ⟨H⟩ = ⟨0|U†HU|0⟩ and d⟨H⟩/dθ for a Hermitian H = Σ c_k P_k. The adjoint method (run_expectation_gradient) is exact in one pair of statevectors and costs one circuit evaluation regardless of the parameter count, but runs only on the statevector backend. Parameter shift (run_expectation_gradient_shift) costs two evaluations per trainable gate and reaches any backend with a native observable path, including widths past the statevector cap.

The differentiated circuit must be unitary (no measurement, reset, or conditional) on both paths. Differentiable gates are Rx, Ry, Rz, Rzz, P, and PauliRot for both: those are the Gate variants carrying a rotation angle, so the shift rule reaches no gate the adjoint rejects.

Structs§

ExpectationGradient
Expectation value and its gradient with respect to each parameter slot.

Functions§

run_expectation_gradient
Compute ⟨H⟩ and its exact gradient with respect to the trainable parameters using the adjoint method on the statevector backend.
run_expectation_gradient_shift
Compute ⟨H⟩ and its gradient by the parameter-shift rule, routing every evaluation through automatic backend selection.