qrunch.chemistry.orbital_optimizers.local_gradient_calculator

Module dedicated to local approximation-based orbital optimization gradient and Hessian computations.

This interface is intended for scenarios where gradients and Hessians are computed using a local approximation around a specific reference point (e.g., x=0).

Classes

BosonReducedDensityMatrixGradientCalculator

Class to construct the gradient and hessian for orbital optimization using boson RDMs.

ReducedDensityMatrixGradientCalculator

Class to construct the gradient and hessian for orbital optimization using restricted RDMs.

RestrictedReducedDensityMatrixGradientCalculator

Class to construct the gradient and hessian for orbital optimization using restricted RDMs.

UnrestrictedReducedDensityMatrixGradientCalculator

Class to construct the gradient and hessian for orbital optimization using unrestricted RDMs.

class BosonReducedDensityMatrixGradientCalculator

Bases: object

Class to construct the gradient and hessian for orbital optimization using boson RDMs.

__init__(estimator: Estimator, mapper: Mapper | None = None) None

Initialize gradient calculator using boson RDMs.

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

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

Return type:

None

clear_cache() None

Clear the cache of the calculators.

Return type:

None

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

Compute the energy (at kappa=0).

Parameters:
  • operator (ChemistryPairedHardcoreBosonHermitianSum) – Operator to estimate the energy of.

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

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

Return type:

float

compute_gradient(operator: ChemistryPairedHardcoreBosonHermitianSum, circuit: Circuit, shots: int | None = None) ndarray[Any, dtype[float64]]

Compute the gradient.

Parameters:
  • operator (ChemistryPairedHardcoreBosonHermitianSum) – Operator to estimate the gradient from.

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

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

Return type:

ndarray[Any, dtype[float64]]

compute_hessian(operator: ChemistryPairedHardcoreBosonHermitianSum, circuit: Circuit, shots: int | None = None) ndarray[Any, dtype[float64]]

Compute the Hessian.

Parameters:
  • operator (ChemistryPairedHardcoreBosonHermitianSum) – Operator to estimate the Hessian from.

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

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

Return type:

ndarray[Any, dtype[float64]]

compute_second_order_energy(operator: ChemistryPairedHardcoreBosonHermitianSum, kappa: ndarray[Any, dtype[float64]], circuit: Circuit, shots: int | None = None) float

Compute the second order energy in terms of the kappa rotation parameters.

Parameters:
  • operator (ChemistryPairedHardcoreBosonHermitianSum) – Operator to estimate the Hessian from.

  • kappa (ndarray[Any, dtype[float64]]) – The orbital rotation parameters.

  • circuit (Circuit) – Circuit to use as the ansatz for estimating the RDMs.

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

Return type:

float

get_estimator_shots() int

Get the total amount of shots made by the estimator.

Return type:

int

class ReducedDensityMatrixGradientCalculator

Bases: GradientCalculator

Class to construct the gradient and hessian for orbital optimization using restricted RDMs.

__init__(estimator: Estimator, mapper: Mapper | None = None) None

Initialize the gradient calculator using restricted RDMs.

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

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

Return type:

None

clear_cache() None

Clear the cache of the calculators.

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[Any, dtype[float64]]

Compute the gradient.

Parameters:
Return type:

ndarray[Any, dtype[float64]]

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

Compute the Hessian.

Parameters:
Return type:

ndarray[Any, dtype[float64]]

compute_second_order_energy(operator: FermionHermitianSumProtocol | PairedHardcoreBosonHermitianSumProtocol, kappa: ndarray[Any, dtype[float64]], circuit: Circuit, shots: int | None = None) float

Compute the second-order energy in terms of the kappa rotation parameters.

Parameters:
Return type:

float

get_estimator_shots() int

Get the total amount of shots made by the estimator.

Return type:

int

class RestrictedReducedDensityMatrixGradientCalculator

Bases: object

Class to construct the gradient and hessian for orbital optimization using restricted RDMs.

__init__(estimator: Estimator, mapper: Mapper | None = None) None

Initialize the gradient calculator using restricted RDMs.

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

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

Return type:

None

clear_cache() None

Clear the cache of the calculators.

Return type:

None

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

Compute the energy (at kappa=0).

Parameters:
  • operator (ChemistryFermionHermitianSum) – Operator to estimate the energy of.

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

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

Return type:

float

compute_gradient(operator: ChemistryFermionHermitianSum, circuit: Circuit, shots: int | None = None) ndarray[Any, dtype[float64]]

Compute the gradient.

\[\frac{\partial E^{(1)}(\kappa)}{\partial \kappa_{xy}} = \sum_{q} h_{yq} \gamma_{xq} - \sum_{q} h_{xq} \gamma_{yq} - \sum_{p} h_{px} \gamma_{py} + \sum_{p} h_{py} \gamma_{px} + \sum_{pqrsm} g_{yqrs} \Gamma_{xrsq} - \sum_{pqrsm} g_{xqrs} \Gamma_{yrsq} + \sum_{pqrsm} g_{pqys} \Gamma_{xpsq} - \sum_{pqrsm} g_{pqxs} \Gamma_{ypsq} + \sum_{pqrsn} g_{pxrs} \Gamma_{prsy} - \sum_{pqrsn} g_{pyrs} \Gamma_{prsx} + \sum_{pqrsn} g_{pqrx} \Gamma_{prqy} - \sum_{pqrsn} g_{pqry} \Gamma_{prqx}\]
Parameters:
  • operator (ChemistryFermionHermitianSum) – Operator to estimate the gradient from.

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

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

Return type:

ndarray[Any, dtype[float64]]

compute_hessian(operator: ChemistryFermionHermitianSum, circuit: Circuit, shots: int | None = None) ndarray[Any, dtype[float64]]

Compute the Hessian.

The calculation is based on eq. (S14) in [arXiv:2212.02482v1], but with the ordering of the indices changes to the physics ordering: pqrs -> prsq.

Furthermore, the indices 1 and 2 of the two-body reduced density matrices are swapped, as this seems to be an error in the paper.

Parameters:
  • operator (ChemistryFermionHermitianSum) – Operator to estimate the Hessian from.

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

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

Return type:

ndarray[Any, dtype[float64]]

compute_second_order_energy(operator: ChemistryFermionHermitianSum, kappa: ndarray[Any, dtype[float64]], circuit: Circuit, shots: int | None = None) float

Compute the second order energy in terms of the kappa rotation parameters.

Parameters:
  • operator (ChemistryFermionHermitianSum) – Operator to estimate the Hessian from.

  • kappa (ndarray[Any, dtype[float64]]) – The orbital rotation parameters.

  • circuit (Circuit) – Circuit to use as the ansatz for estimating the RDMs.

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

Return type:

float

get_estimator_shots() int

Get The total amount of shots made by the estimator.

Return type:

int

class UnrestrictedReducedDensityMatrixGradientCalculator

Bases: object

Class to construct the gradient and hessian for orbital optimization using unrestricted RDMs.

__init__(estimator: Estimator, mapper: Mapper | None = None) None

Initialize the gradient calculator using unrestricted RDMs.

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

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

Return type:

None

clear_cache() None

Clear the cache of the calculators.

Return type:

None

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

Compute the energy (at kappa=0).

Parameters:
  • operator (ChemistryFermionHermitianSum) – Operator to estimate the energy of.

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

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

Return type:

float

compute_gradient(operator: ChemistryFermionHermitianSum, circuit: Circuit, shots: int | None = None) ndarray[Any, dtype[float64]]

Compute the gradient.

Parameters:
  • operator (ChemistryFermionHermitianSum) – Operator to estimate the gradient from.

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

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

Return type:

ndarray[Any, dtype[float64]]

compute_hessian(operator: ChemistryFermionHermitianSum, circuit: Circuit, shots: int | None = None) ndarray[Any, dtype[float64]]

Compute the Hessian.

Parameters:
  • operator (ChemistryFermionHermitianSum) – Operator to estimate the Hessian from.

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

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

Return type:

ndarray[Any, dtype[float64]]

compute_second_order_energy(operator: ChemistryFermionHermitianSum, kappa: ndarray[Any, dtype[float64]], circuit: Circuit, shots: int | None = None) float

Compute the second order energy in terms of the kappa rotation parameters.

Parameters:
  • operator (ChemistryFermionHermitianSum) – Operator to estimate the Hessian from.

  • kappa (ndarray[Any, dtype[float64]]) – The orbital rotation parameters.

  • circuit (Circuit) – Circuit to use as the ansatz for estimating the RDMs.

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

Return type:

float

get_estimator_shots() int

Get The total amount of shots made by the estimator.

Return type:

int