bluemira.optimisation._scipy.optimiser

Scipy optimisation interface

Classes

ScipyOptimiser

Interface for an optimiser supporting bounds and constraints.

Module Contents

class bluemira.optimisation._scipy.optimiser.ScipyOptimiser(algorithm: bluemira.optimisation._algorithm.AlgorithmType, n_variables: int, f_objective: bluemira.optimisation.typing.ObjectiveCallable, df_objective: bluemira.optimisation.typing.OptimiserCallable | None = None, opt_conditions: collections.abc.Mapping[str, int | float] | None = None, opt_parameters: collections.abc.Mapping[str, Any] | None = None, *, keep_history: bool = False)

Bases: bluemira.optimisation._optimiser.Optimiser

Inheritance diagram of bluemira.optimisation._scipy.optimiser.ScipyOptimiser

Interface for an optimiser supporting bounds and constraints.

Parameters:
  • algorithm (bluemira.optimisation._algorithm.AlgorithmType)

  • n_variables (int)

  • f_objective (bluemira.optimisation.typing.ObjectiveCallable)

  • df_objective (bluemira.optimisation.typing.OptimiserCallable | None)

  • opt_conditions (collections.abc.Mapping[str, int | float] | None)

  • opt_parameters (collections.abc.Mapping[str, Any] | None)

  • keep_history (bool)

n_variables
f_objective
df_objective = None
_eq_constraints = []
_ineq_constraints = []
_config
keep_history = False
property algorithm: bluemira.optimisation._algorithm.AlgorithmType

returns: the optimiser’s algorithm.

Return type:

bluemira.optimisation._algorithm.AlgorithmType

property opt_parameters: collections.abc.Mapping[str, int | float]

returns: the optimiser algorithms’s parameters.

Return type:

collections.abc.Mapping[str, int | float]

property lower_bounds: numpy.ndarray

returns: the lower bounds for the optimisation parameters.

Return type:

numpy.ndarray

property upper_bounds: numpy.ndarray

returns: the upper bounds for the optimisation parameters.

Return type:

numpy.ndarray

_get_scipy_config() bluemira.optimisation._scipy.registry.ScipyAlgConfig

Helper to safely retrieve config or raise an error.

Returns:

  • The associated entry in the scipy registry, which contains

  • configuration information specific to each algorithm.

Raises:

OptimisationError – Algorithm is not supported by SciPy.

Return type:

bluemira.optimisation._scipy.registry.ScipyAlgConfig

_set_algorithm(alg: bluemira.optimisation._algorithm.AlgorithmType) None

Set the optimiser’s algorithm.

Parameters:

alg (bluemira.optimisation._algorithm.AlgorithmType)

Return type:

None

_set_parameters(opt_parameters: collections.abc.Mapping[str, int | float]) None

Initialise the optimiser’s parameters.

Parameters:

opt_parameters (collections.abc.Mapping[str, int | float])

Return type:

None

add_eq_constraint(f_constraint: bluemira.optimisation.typing.OptimiserCallable, tolerance: numpy.ndarray, df_constraint: bluemira.optimisation.typing.OptimiserCallable | None = None) None

Add an equality constraint to the optimiser.

The constraint is a vector-valued, non-linear, equality constraint of the form \(f_{c}(x) = 0\).

The constraint function should have the form \(f(x) \rightarrow y\), where:

  • \(x\) is a numpy array of the optimisation parameters.

  • \(y\) is a numpy array containing the values of the constraint at \(x\), with size \(m\), where \(m\) is the dimensionality of the constraint.

Parameters:
  • f_constraint (bluemira.optimisation.typing.OptimiserCallable) – The constraint function, with form as described above.

  • tolerance (numpy.ndarray) – The tolerances for each optimisation parameter.

  • df_constraint (bluemira.optimisation.typing.OptimiserCallable | None) – The gradient of the constraint function. This should have the same form as the constraint function, however its output array should have dimensions \(m \times n\) where :math`m` is the dimensionality of the constraint, and \(n\) is the number of optimisation parameters.

Raises:

OptimisationError – Algorithm does not support equality constraints.

Return type:

None

Notes

Equality constraints are only supported by algorithms:

  • SLSQP

  • COBYQA

  • TRUST_CONSTR

However, equality constraints can be converted to pairs of inequality constraints to work with other algorithms, such as COBYLA.

add_ineq_constraint(f_constraint: bluemira.optimisation.typing.OptimiserCallable, tolerance: numpy.ndarray, df_constraint: bluemira.optimisation.typing.OptimiserCallable | None = None) None

Add an inequality constrain to the optimiser.

The constraint is a vector-valued, non-linear, inequality constraint of the form \(f_{c}(x) \le 0\).

The constraint function should have the form \(f(x) \rightarrow y\), where:

  • \(x\) is a numpy array of the optimisation parameters.

  • \(y\) is a numpy array containing the values of the constraint at \(x\), with size \(m\), where \(m\) is the dimensionality of the constraint.

Parameters:
  • f_constraint (bluemira.optimisation.typing.OptimiserCallable) – The constraint function, with form as described above.

  • tolerance (numpy.ndarray) – The tolerances for each optimisation parameter.

  • df_constraint (bluemira.optimisation.typing.OptimiserCallable | None) – The gradient of the constraint function. This should have the same form as the constraint function, however its output array should have dimensions \(m \times n\) where :math`m` is the dimensionality of the constraint, and \(n\) is the number of optimisation parameters.

Raises:

OptimisationError – Algorithm does not support inequality constraints.

Return type:

None

Notes

Inequality constraints are only supported by algorithms:

  • SLSQP

  • COBYLA

  • COBYQA

optimise(x0: numpy.ndarray | None = None) bluemira.optimisation._optimiser.OptimiserResult

Run the optimiser.

Parameters:

x0 (numpy.ndarray | None) – The initial guess for each of the optimisation parameters. If not given, each parameter is set to the average of its lower and upper bound. If no bounds exist, the initial guess will be all zeros.

Returns:

  • The result of the optimisation, containing the optimised

  • parameters x, as well as other information about the

  • optimisation.

Raises:
  • OptimisationError – Low-level optimisation error.

  • KeyboardInterrupt – Optimisation halted by user.

Return type:

bluemira.optimisation._optimiser.OptimiserResult

set_lower_bounds(bounds: numpy.ndarray) None

Set the lower bound for each optimisation parameter.

Set to -np.inf to unbound the parameter’s minimum.

Raises:

ValueError – Incorrect bounds dimensions.

Parameters:

bounds (numpy.ndarray)

Return type:

None

set_upper_bounds(bounds: numpy.ndarray) None

Set the upper bound for each optimisation parameter.

Set to np.inf to unbound the parameter’s minimum.

Raises:

ValueError – Incorrect bounds dimensions.

Parameters:

bounds (numpy.ndarray)

Return type:

None