qrunch.quantum.algorithms.second_quantization.orbital_optimizers.simple_orbital_optimizer

Module containing the simple orbital optimizer.

Functions

default_orbital_optimizer_factory(estimator, ...)

Default factory for creating a SimpleOrbitalOptimizer.

Classes

SimpleOrbitalOptimizer

An orbital optimizer using a simple cost function and any Minimizer to perform the optimization.

SimpleOrbitalOptimizerCreator

Creator for the orbital optimizer algorithm.

class SimpleOrbitalOptimizer

Bases: OrbitalOptimizerAlgorithm

An orbital optimizer using a simple cost function and any Minimizer to perform the optimization.

__init__(estimator: Estimator, minimizer: Minimizer, mapper: Mapper | None = None, shots: int | ShotsPerGroup | None = None) None

Initialize orbital optimizer.

Parameters:
  • estimator (Estimator) – The estimator to use in the cost function.

  • minimizer (Minimizer) – The minimizer to use in the orbital optimization algorithm.

  • mapper (Mapper | None) – Mapper to use for creating qubit operators.

  • shots (int | ShotsPerGroup | None) – Number of shots to use for the estimator.

Return type:

None

clear_cache() None

Clear the cache of the underlying estimator.

Return type:

None

gradient_norm(operator: FermionHermitianSumProtocol | PairedHardcoreBosonHermitianSumProtocol, circuit: Circuit) float | None

Compute the norm of the orbital-optimization gradient at zero rotation.

The method return None, as the SimpleOrbitalOptimizer does not have an analytical gradient.

Parameters:
Return type:

float | None

property mapper: Mapper

Return the mapper.

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

Run the orbital optimization and find the eigenvalue.

The orbital optimizer rotates the observable so that the expectation value is minimized.

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.

  • callback – An optional callback function that is called at each minimizer iteration.

Return type:

OrbitalOptimizerResult[T]

run_single_step(operator: T, circuit: Circuit) OrbitalOptimizerResult[T]

Perform a single, cheap orbital-optimization step.

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

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

Return type:

OrbitalOptimizerResult[T]

class SimpleOrbitalOptimizerCreator

Bases: object

Creator for the orbital optimizer algorithm.

__init__() None

Initialize builder for the orbital optimizer.

Return type:

None

choose_minimizer() MinimizerSubCreator[Self]

Choose minimizer to use for the orbital optimizer.

Return type:

MinimizerSubCreator[Self]

create() SimpleOrbitalOptimizer

Create an instance of SimpleOrbitalOptimizer.

Return type:

SimpleOrbitalOptimizer

with_estimator(estimator: Estimator) SimpleOrbitalOptimizerCreator

Set the estimator to use for the orbital optimizer.

Parameters:

estimator (Estimator) – Estimator to use. Can be created using the estimator_creator() builder.

Return type:

SimpleOrbitalOptimizerCreator

with_shots(shots: int | None) Self

Set the number of shots to use when calling the estimator.

This is the number of shots that will be used in each call to the quantum computer or simulator, and not necessarily the total number of shots. The total number of shots will in many cases be much higher.

Parameters:
  • shots (int | None) – Number of shots to use in the estimator. If None is given, the estimator is assumed to be exact

  • simulator). ((e.g. the excitation gate)

Return type:

Self

with_total_estimator_shots(shots: int | None) Self

Set the number of shots to use when calling the estimator.

The total number of shots are then distributed across the different groups in the estimator according to the shots per group strategy of the estimator. This ensures better use of the shot budget, and therefore, better use of the quantum resources.

Parameters:
  • shots (int | None) – Number of shots to use in the estimator. If None is given, the estimator is assumed to be exact

  • simulator). ((e.g. the excitation gate)

Return type:

Self

default_orbital_optimizer_factory(estimator: Estimator, shots: int | ShotsPerGroup | None) OrbitalOptimizerAlgorithm

Default factory for creating a SimpleOrbitalOptimizer.

Parameters:
  • estimator (Estimator) – The estimator to use in the orbital optimizer.

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

Returns:

An instance of SimpleOrbitalOptimizer using the given estimator and number of shots.

Return type:

OrbitalOptimizerAlgorithm