qrunch.chemistry.orbital_optimizers.newton_orbital_optimizer

Module containing an orbital optimizer implementation using Newton’s method.

Module Attributes

DEFAULT_OPTIONS

The default options for the Newton Orbital Optimizer Scipy minimizer.

Classes

BasinHoppingOptions

Options for SciPy basinhopping global optimization.

NewtonMinimizerOptions

The default options for SciPy minimizer.

NewtonOrbitalOptimizer

Implement a solver to find and apply Newton's method for orbital optimization.

NewtonOrbitalOptimizerOrbitalOptimizerCreator

Builder for the orbital optimizer algorithm using Newton's method.

class BasinHoppingOptions

Bases: DataclassPublicAPI

Options for SciPy basinhopping global optimization.

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

Parameters:
  • number_of_macro_iterations – How many basin hopping steps to perform. (default=3)

  • temperature – Controls accept probability for worse solutions. (default=0.01)

  • stepsize – Size of random displacement. (default=0.05)

  • number_of_successive_failures – Stop if no improvement after this many steps. (default=4)

  • seed – RNG seed for reproducibility. (default=None)

  • display – Verbosity. (default=True)

  • active – Activate Basin Hopping. (default=False)

__init__(*, number_of_macro_iterations: int = 3, temperature: float = 0.01, stepsize: float = 0.05, number_of_successive_failures: int = 4, seed: int | None = None, display: bool = True, active: bool = False) None
Parameters:
  • number_of_macro_iterations (int)

  • temperature (float)

  • stepsize (float)

  • number_of_successive_failures (int)

  • seed (int | None)

  • display (bool)

  • active (bool)

Return type:

None

active: bool = False
display: bool = True
number_of_macro_iterations: int = 3
number_of_successive_failures: int = 4
seed: int | None = None
stepsize: float = 0.05
temperature: float = 0.01
DEFAULT_OPTIONS = NewtonMinimizerOptions(relative_error_tolerance=1e-05, max_iterations_per_parameter=10000, jacobian_step_size=1e-06, use_hessian_on_trialvector_for_single_step=False)

The default options for the Newton Orbital Optimizer Scipy minimizer.

class NewtonMinimizerOptions

Bases: DataclassPublicAPI

The default options for SciPy minimizer.

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

Parameters:
  • relative_error_tolerance – Convergence tolerance (default=1.0e-5)

  • max_iterations_per_parameter – Maximum number of iterations per parameter. (default=10000)

  • jacobian_step_size – Jacobian step size (default=1e-6)

  • use_hessian_on_trialvector_for_single_step – If True, supply the Hessian-vector product (hessp) to SciPy instead of the full Hessian matrix (hess) for the single step procedure. This can be more efficient when the gradient calculator implements a direct Hessian-vector product. (default=False). In case the gradient calculator does not support Hessian-vector products for the given operator, we will fall back to using the full Hessian matrix even if this option is True, and log a warning. (default=False)

__init__(*, relative_error_tolerance: float = 1e-05, max_iterations_per_parameter: int = 10000, jacobian_step_size: float = 1e-06, use_hessian_on_trialvector_for_single_step: bool = False) None
Parameters:
  • relative_error_tolerance (float)

  • max_iterations_per_parameter (int)

  • jacobian_step_size (float)

  • use_hessian_on_trialvector_for_single_step (bool)

Return type:

None

jacobian_step_size: float = 1e-06
max_iterations_per_parameter: int = 10000
relative_error_tolerance: float = 1e-05
use_hessian_on_trialvector_for_single_step: bool = False
class NewtonOrbitalOptimizer

Bases: OrbitalOptimizerAlgorithm

Implement a solver to find and apply Newton’s method for orbital optimization.

__init__(gradient_calculator: GradientCalculator, shots: int | ShotsPerGroup | None = None, options: NewtonMinimizerOptions = NewtonMinimizerOptions(relative_error_tolerance=1e-05, max_iterations_per_parameter=10000, jacobian_step_size=1e-06, use_hessian_on_trialvector_for_single_step=False), basin_hopping_options: BasinHoppingOptions | None = None) None

Initialize builder for the orbital optimizer.

Parameters:
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 gradient is evaluated at \(\\kappa = 0\), i.e. using the unrotated operator directly.

Parameters:
Return type:

float | None

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

Compute kappa analytically at zero kappa using Newton’s method.

The method uses the gradient and Hessian in from the gradient calculator.

Parameters:
  • operator (T) – The operator to rotate.

  • circuit (Circuit) – The circuit used to evaluate the operator.

Return type:

OrbitalOptimizerResult[T]

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

Perform a single Newton-CG step (maxiter=1).

Parameters:
  • operator (T) – The operator to rotate.

  • circuit (Circuit) – The circuit used to evaluate the operator.

Return type:

OrbitalOptimizerResult[T]

class NewtonOrbitalOptimizerOrbitalOptimizerCreator

Bases: object

Builder for the orbital optimizer algorithm using Newton’s method.

__init__() None

Initialize builder for the orbital optimizer.

Return type:

None

choose_gradient_calculator() GradientCalculatorSubCreator[Self]

Choose gradient calculator to use for the orbital optimizer.

Return type:

GradientCalculatorSubCreator[Self]

create() NewtonOrbitalOptimizer

Create an instance of NewtonOrbitalOptimizer.

Return type:

NewtonOrbitalOptimizer

with_basin_hopping_options(basin_hopping_options: BasinHoppingOptions) Self

Set the basin-hopping options for global optimization.

Parameters:

basin_hopping_options (BasinHoppingOptions) – Options controlling the basin-hopping wrapper.

Return type:

Self

with_options(options: NewtonMinimizerOptions) Self

Set the options to use for the orbital optimizer.

Parameters:

options (NewtonMinimizerOptions) – Options to pass to the minimizer

Return type:

Self

with_shots(shots: int | None) Self

Set the number of shots to use when calling the gradient_calculator to compute the energy, gradient, etc.

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 total number of shots to use when calling the gradient_calculator to compute the energy, gradient, etc.

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