qrunch.quantum.algorithms.second_quantization.orbital_optimizers.protocols

Protocols for orbital optimizers.

Classes

GradientCalculator

Protocol for calculating gradients and Hessians for orbital optimization.

OrbitalOptimizerAlgorithm

Protocol class for an orbital optimizer.

OrbitalOptimizerResult

Result of orbital optimization.

class GradientCalculator

Bases: Protocol

Protocol for calculating gradients and Hessians for orbital optimization.

__init__(*args, **kwargs)
clear_cache() None

Clear the cache of the underlying 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[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]]

get_estimator_shots() int

Get the total amount of shots made by the estimator.

Return type:

int

class OrbitalOptimizerAlgorithm

Bases: ABC

Protocol class for an orbital optimizer.

The orbital optimization algorithm rotates the observable with an ansatz unitary so that the expectation value is minimized.

abstractmethod clear_cache() None

Clear the cache of the underlying estimator.

Return type:

None

abstractmethod run(operator: T, circuit: Circuit) OrbitalOptimizerResult[T]

Run the orbital optimizer and find the eigenvalue.

Parameters:
  • operator (T) – The operator whose expectation value should be minimized.

  • circuit (Circuit) – The parametrized circuit to find optimal parameters for. Should contain unspecified parameters.

Return type:

OrbitalOptimizerResult[T]

class OrbitalOptimizerResult

Bases: Generic[T_COV]

Result of orbital optimization.

All fields are immutable (frozen=True) so an instance can be safely reused.

Parameters:
  • sampler_shots – The total amount of shots used by the sampler

  • rotation_matrices – Optimal rotation_matrices

  • estimated_value – Estimated expectation value of the rotated operator

  • rotated_operator – The rotated second quantized operator.

  • rotation_parameters – Optimal parameters in the exponential of the rotation matrices (default=None)

__init__(sampler_shots: int, rotation_matrices: tuple[ndarray[Any, dtype[float64]], ...], estimated_value: float, rotated_operator: T_COV, rotation_parameters: tuple[dict[tuple[int, int], float64], ...] | None = None) None
Parameters:
  • sampler_shots (int)

  • rotation_matrices (tuple[ndarray[Any, dtype[float64]], ...])

  • estimated_value (float)

  • rotated_operator (T_COV)

  • rotation_parameters (tuple[dict[tuple[int, int], float64], ...] | None)

Return type:

None

estimated_value: float
rotated_operator: T_COV
rotation_matrices: tuple[ndarray[Any, dtype[float64]], ...]
rotation_parameters: tuple[dict[tuple[int, int], float64], ...] | None = None
sampler_shots: int