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, restricted: bool = False) 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.

  • restricted (bool) – Whether the calculation should be performed restricted. Defaults to False.

Return type:

None

clear_cache() None

Clear the cache of the estimator.

Return type:

None

compute_energy(operator: FermionHermitianSumProtocol | PairedHardcoreBosonHermitianSumProtocol, circuit: Circuit, shots: int | None = None) float

Compute the energy.

Parameters:
Return type:

float

compute_gradient(operator: FermionHermitianSumProtocol | PairedHardcoreBosonHermitianSumProtocol, circuit: Circuit, shots: int | None = None) ndarray[tuple[Any, ...], dtype[float64]]

Compute the gradient.

Parameters:
Return type:

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

compute_hessian(operator: FermionHermitianSumProtocol | PairedHardcoreBosonHermitianSumProtocol, circuit: Circuit, shots: int | None = None) ndarray[tuple[Any, ...], dtype[float64]]

Compute the Hessian.

Parameters:
Return type:

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

compute_hessian_on_trial_vector(operator: FermionHermitianSumProtocol | PairedHardcoreBosonHermitianSumProtocol, kappa_vec: ndarray[tuple[Any, ...], dtype[float64]], circuit: Circuit, shots: int | 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 (FermionHermitianSumProtocol | PairedHardcoreBosonHermitianSumProtocol) – 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 | 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

is_restricted() bool

Return True if the calculation is restricted.

Return type:

bool

support_hessian_on_trial_vector(operator: FermionHermitianSumProtocol | PairedHardcoreBosonHermitianSumProtocol) bool

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

Parameters:

operator (FermionHermitianSumProtocol | PairedHardcoreBosonHermitianSumProtocol) – Operator to check support for.

Return type:

bool