qrunch.tools.minimizers.scipy_minimizer

Wrapper around the minimizer from the Scipy package.

Module Attributes

DEFAULT_OPTIONS

The default options for the Scipy minimizer.

Classes

ScipyMinimizer

Minimizer that uses the minimize function from the Scipy.minimizer package with the specified method.

ScipyMinimizerMethods

Scipy minimize methods.

ScipyMinimizerOptions

Options controlling ScipyMinimizer.

DEFAULT_OPTIONS

The default options for the Scipy minimizer.

class ScipyMinimizer

Bases: Minimizer

Minimizer that uses the minimize function from the Scipy.minimizer package with the specified method.

__init__(method: ScipyMinimizerMethods | None = None, options: ScipyMinimizerOptions | None = None) None

Initialize the minimizer.

Parameters:
Return type:

None

minimize(function: Callable[[list[ndarray[Any, dtype[float64]]]], list[float]], initial_guess: ndarray[Any, dtype[float64]], iteration: int | None, bounds: tuple[float, float] | list[tuple[float, float]] | None = None, circuit: Circuit | None = None, operator: HermitianPauliSum | None = None) MinimizerResult

Minimize the given function using the initial guess.

Parameters:
  • function (Callable[[list[ndarray[Any, dtype[float64]]]], list[float]]) – The function to minimize. Takes a numpy array of parameters as input and outputs a scalar value.

  • initial_guess (ndarray[Any, dtype[float64]]) – The initial guess of the parameters.

  • iteration (int | None) – The current iteration. Not used in this minimizer.

  • bounds (tuple[float, float] | list[tuple[float, float]] | None) – The bounds for the parameters. If a single tuple is given all parameters are given the same bounds if a list of tuples is given it must match the number of parameters.

  • circuit (Circuit | None) – The parameterized circuit to be minimized.

  • operator (HermitianPauliSum | None) – The operator used in the expectation value.

Return type:

MinimizerResult

class ScipyMinimizerMethods

Bases: Enum

Scipy minimize methods.

BFGS = 'BFGS'
CG = 'CG'
COBYLA = 'COBYLA'
COBYQA = 'COBYQA'
L_BFGS_B = 'L-BFGS-B'
NELDER_MEAD = 'Nelder-Mead'
POWELL = 'Powell'
SLSQP = 'SLSQP'
TNC = 'TNC'
class ScipyMinimizerOptions

Bases: DataclassPublicAPI

Options controlling ScipyMinimizer.

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

Parameters:
  • gradient_tolerance – float, default=1e-8 Gradient infinity-norm tolerance (gtol). Relevant for quasi-Newton / gradient-based methods that use first-order stopping criteria.

  • max_function_evaluations – int, default=10000 Hard cap on the number of objective evaluations (maxfun) before termination.

  • max_iterations_per_parameter – int, default=10000 Maximum iterations multiplied by the number of parameters gives maxiter; effectively scales iteration budget with problem size.

  • function_tolerance – float, default=10 * eps Relative function value tolerance (ftol). Iteration stops when \((f^k - f^{k+1}) / \max\{|f^k|, |f^{k+1}|, 1\} \leq ftol\).

  • jacobian_step_size – float, default=1e-6 Finite-difference step size (eps) used when SciPy internally approximates gradients.

  • max_line_search_steps – int, default=100 Maximum number of line-search steps (maxls) per outer iteration for methods that perform a line search.

__init__(*, gradient_tolerance: float = 1e-08, max_function_evaluations: int = 10000, max_iterations_per_parameter: int = 10000, function_tolerance: float = 2.220446049250313e-15, jacobian_step_size: float = 1e-06, max_line_search_steps: int = 100) None
Parameters:
  • gradient_tolerance (float)

  • max_function_evaluations (int)

  • max_iterations_per_parameter (int)

  • function_tolerance (float)

  • jacobian_step_size (float)

  • max_line_search_steps (int)

Return type:

None

static __new__(cls, *args: Any, **kwargs: Any) Any
Parameters:
  • args (Any)

  • kwargs (Any)

Return type:

Any

function_tolerance: float = 2.220446049250313e-15
gradient_tolerance: float = 1e-08
jacobian_step_size: float = 1e-06
max_function_evaluations: int = 10000
max_iterations_per_parameter: int = 10000
max_line_search_steps: int = 100