Documentation

LeanPool.LeanQuantumAlg.Primitives.ParameterShift

Parameter-shift rule #

A variational (parameterized) quantum model has a cost C(θ) = ⟨ψ| U(θ)† O U(θ) |ψ⟩ that is optimized over the parameters θ. When θ enters through a single Pauli rotation gate, C is a frequency-1 trigonometric polynomial in θ, and its exact analytic gradient is obtained from two shifted evaluations — the parameter-shift rule C'(θ) = (C(θ + π/2) − C(θ − π/2)) / 2.

This module records the parameter-shift rule abstractly (ParamShiftModel), and instantiates it on a concrete single-qubit R_Y(θ) ansatz with observable Z, whose cost is cos θ.

Sources: Schuld et al. (2019), Evaluating analytic gradients on quantum hardware; Wierichs et al. (2022), General parameter-shift rules for quantum gradients; Farhi, Goldstone, Gutmann (2014), A Quantum Approximate Optimization Algorithm.

Main results #

A single-parameter variational cost whose dependence on the parameter is a frequency-1 trigonometric polynomial a + b cos θ + c sin θ — the structure that makes the parameter-shift rule exact. A parameterized-circuit cost built from a single Pauli rotation gate has this form.

  • cost :

    The cost function.

  • a :

    Constant Fourier coefficient.

  • b :

    Cosine Fourier coefficient.

  • c :

    Sine Fourier coefficient.

  • trig (θ : ) : self.cost θ = self.a + self.b * Real.cos θ + self.c * Real.sin θ

    The cost is a frequency-1 trigonometric polynomial.

Instances For

    Parameter-shift rule. The exact derivative of a frequency-1 trigonometric cost is the symmetric finite difference at shift π/2.

    noncomputable def QuantumAlg.varCost (ψ : PureState 1) (O : HilbertOperator 1) (θ : ) :

    The single-qubit R_Y(θ) variational cost with observable O on input ψ: C(θ) = ⟨ψ| R_Y(θ)† O R_Y(θ) |ψ⟩.

    Equations
    Instances For

      R_Y(θ) |0⟩ = cos(θ/2) |0⟩ + sin(θ/2) |1⟩.

      Inner product of two single-qubit states in the computational basis.

      The R_Y(θ) ansatz cost with observable Z on |0⟩ equals cos θ.

      A concrete variational model: the R_Y / Z / |0⟩ cost cos θ.

      Equations
      Instances For

        Parameter-shift rule for the R_Y / Z / |0⟩ ansatz.

        theorem QuantumAlg.ParameterShiftRule.main (M : ParamShiftModel) (θ : ) :
        deriv M.cost θ = (M.cost (θ + Real.pi / 2) - M.cost (θ - Real.pi / 2)) / 2

        Main parameter-shift theorem for a frequency-1 variational cost.

        theorem QuantumAlg.ParameterShiftRule.main_trig_identity (a b c θ : ) :
        deriv (fun (t : ) => a + b * Real.cos t + c * Real.sin t) θ = (a + b * Real.cos (θ + Real.pi / 2) + c * Real.sin (θ + Real.pi / 2) - (a + b * Real.cos (θ - Real.pi / 2) + c * Real.sin (θ - Real.pi / 2))) / 2

        Public supporting theorem: the quantum-free trigonometric identity.

        Public supporting theorem: the concrete R_Y / Z / |0⟩ cost.

        Public supporting theorem: parameter shift for the concrete R_Y / Z / |0⟩ cost.