bluemira.optimisation._optimiser

Defines the interface for an Optimiser.

Classes

OptimiserResult

Container for optimiser results.

Optimiser

Interface for an optimiser supporting bounds and constraints.

Module Contents

class bluemira.optimisation._optimiser.OptimiserResult

Container for optimiser results.

f_x: float

The evaluation of the optimised parameterisation.

x: numpy.ndarray

The optimised parameterisation.

n_evals: int

The number of evaluations of the objective function in the optimisation.

history: list[tuple[numpy.ndarray, float]]

The history of the parameterisation at each iteration.

The first element of each tuple is the parameterisation (x), the second is the evaluation of the objective function at x (f(x)).

constraint_history: list[tuple[numpy.ndarray, Ellipsis]]

Constraint history

constraints_satisfied: bool | None = None

Whether all constraints have been satisfied to within the required tolerance.

Is None if constraints have not been checked.

class bluemira.optimisation._optimiser.Optimiser

Bases: abc.ABC

Inheritance diagram of bluemira.optimisation._optimiser.Optimiser

Interface for an optimiser supporting bounds and constraints.

abstract add_eq_constraint(f_constraint: bluemira.optimisation.typed.OptimiserCallable, tolerance: numpy.ndarray, df_constraint: bluemira.optimisation.typed.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.typed.OptimiserCallable) – The constraint function, with form as described above.

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

  • df_constraint (bluemira.optimisation.typed.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.

Return type:

None

Notes

Inequality constraints are only supported by algorithms:

  • SLSQP

  • COBYLA

  • ISRES

abstract add_ineq_constraint(f_constraint: bluemira.optimisation.typed.OptimiserCallable, tolerance: numpy.ndarray, df_constraint: bluemira.optimisation.typed.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.typed.OptimiserCallable) – The constraint function, with form as described above.

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

  • df_constraint (bluemira.optimisation.typed.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.

Return type:

None

Notes

Inequality constraints are only supported by algorithms:

  • SLSQP

  • COBYLA

  • ISRES

abstract optimise(x0: numpy.ndarray | None = None) 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.

Return type:

OptimiserResult

abstract 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.

Parameters:

bounds (numpy.ndarray)

Return type:

None

abstract 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.

Parameters:

bounds (numpy.ndarray)

Return type:

None