gradient

package
v1.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 17, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package gradient provides quantum gradient computation methods.

CostFunc creates an optim.ObjectiveFunc from a parameterized circuit and Hamiltonian using statevector simulation.

ParameterShift and FiniteDifference compute gradients of an objective function, suitable for use as optim.GradientFunc.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CostFunc

func CostFunc(circuit *ir.Circuit, hamiltonian pauli.PauliSum,
	paramNames []string) optim.ObjectiveFunc

CostFunc creates an ObjectiveFunc that evaluates the expectation value ⟨ψ(θ)|H|ψ(θ)⟩ using statevector simulation. Each call binds the parameter vector to paramNames and runs a fresh simulation.

The returned function is goroutine-safe because each call creates its own simulator instance.

func FiniteDifference

func FiniteDifference(f optim.ObjectiveFunc, h float64) optim.GradientFunc

FiniteDifference returns approximate gradients via central differences with step size h.

func ParameterShift

func ParameterShift(f optim.ObjectiveFunc) optim.GradientFunc

ParameterShift returns exact gradients via the parameter-shift rule. For each parameter, it evaluates f(x + π/2*e_i) and f(x - π/2*e_i), computing the gradient as [f(x+s) - f(x-s)] / 2. This requires 2*N function evaluations per call (N = number of parameters).

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL