qrunch.quantum.algorithms.second_quantization.orbital_optimizers.gradient_calculator

Module dedicated to general (full-domain) orbital optimization gradient and Hessian computations.

This interface is intended for scenarios where gradients and Hessians can be computed for any parameter set, not just around a single reference point.

Classes

FiniteDifferencesGradientCalculator

Class to construct the gradient and hessian for orbital optimization using finite differences.

class FiniteDifferencesGradientCalculator

Bases: GradientCalculator

Class to construct the gradient and hessian for orbital optimization using finite differences.

__init__(estimator: Estimator, mapper: Mapper | None = None, *, epsilon: float = 1e-05) → None

Initialize the gradient calculator using finite differences.

Parameters:
  • estimator (Estimator) – Estimator to use for estimating.

  • mapper (Mapper | None) – Mapper to use when mapping RDM operators.

  • epsilon (float) – The finite difference. Defaults to 1e-5.

Return type:

None

clear_cache() → None

Clear the cache of the estimator.

Return type:

None

compute_energy(operator: FermionHermitianSum | PairedHardcoreBosonHermitianSum, circuit: Circuit, shots: int | ShotsPerGroup | None = None) → float

Compute the energy.

Parameters:
Return type:

float

compute_gradient(operator: FermionHermitianSum | PairedHardcoreBosonHermitianSum, circuit: Circuit, shots: int | ShotsPerGroup | None = None) → ndarray[tuple[Any, ...], dtype[float64]]

Compute the gradient.

Parameters:
Return type:

ndarray[tuple[Any, …], dtype[float64]]

compute_hessian(operator: FermionHermitianSum | PairedHardcoreBosonHermitianSum, circuit: Circuit, shots: int | ShotsPerGroup | None = None) → ndarray[tuple[Any, ...], dtype[float64]]

Compute the Hessian.

Parameters:
Return type:

ndarray[tuple[Any, …], dtype[float64]]

compute_hessian_on_trial_vector(operator: FermionHermitianSum | PairedHardcoreBosonHermitianSum, kappa_vec: ndarray[tuple[Any, ...], dtype[float64]], circuit: Circuit, shots: int | ShotsPerGroup | None = None) → ndarray[tuple[Any, ...], dtype[float64]]

Compute the Hessian contracted with a trial vector.

This builds the full Hessian via finite differences and then contracts it with the supplied trial vector: hessian @ kappa_vec.

Parameters:
  • operator (FermionHermitianSum | PairedHardcoreBosonHermitianSum) – Operator to estimate the Hessian from.

  • kappa_vec (ndarray[tuple[Any, ...], dtype[float64]]) – The trial vector to contract with the Hessian.

  • circuit (Circuit) – The circuit ansatz with minimized parameters set.

  • shots (int | ShotsPerGroup | None) – The number of shots to use in the estimator.

Return type:

ndarray[tuple[Any, …], dtype[float64]]

get_estimator_shots() → int

Get the total amount of shots made by the estimator.

Return type:

int

support_hessian_on_trial_vector(operator: FermionHermitianSum | PairedHardcoreBosonHermitianSum) → bool

Indicate whether this class supports computing the Hessian on a trial vector.

Parameters:

operator (FermionHermitianSum | PairedHardcoreBosonHermitianSum) – Operator to check support for.

Return type:

bool