bluemira.optimisation.problem
Interface for defining an optimisation problem.
Classes
Common base class for OptimisationProblem classes. |
|
Interface for an optimisation problem. |
Module Contents
- class bluemira.optimisation.problem.OptimisationProblemBase
Common base class for OptimisationProblem classes.
- __MethodT
- __AnyT
- _overridden_or_default(f: __MethodT, cls: type[Any], default: __AnyT) __MethodT | __AnyT
If the given object is not a member of this class return a default.
This can be used to decide whether a function has been overridden or not. Which is useful in this class for the
df_objectivecase, where overriding the method is possible, but not necessary. We want it to appear in the class interface, but we want to be able to tell if it’s been overridden so we can use an approximate gradient if it has not been.- Returns:
overridden or default object
- Parameters:
f (__MethodT)
cls (type[Any])
default (__AnyT)
- Return type:
__MethodT | __AnyT
- static __is_method(f: __MethodT, cls: type[Any]) bool
Determine if the given method is a member of this base class or not.
Note that
fmust be a bound method, i.e., it needs the__func__dunder method.- Returns:
true if the given method is a member of this base class else false
- Parameters:
f (__MethodT)
cls (type[Any])
- Return type:
bool
- class bluemira.optimisation.problem.OptimisationProblem
Bases:
abc.ABC,OptimisationProblemBaseInterface for an optimisation problem.
This is an alternative to running an optimisation using the
optimise()function.Using this interface to define an optimisation can provide a few benefits, including:
Shared state between optimisation functions and constraints. This can enable things like shared parameters and dynamic constraints.
Switch out optimisation problems using Liskov Substitution.
Logical grouping of related functions.
- abstract objective(x: numpy.ndarray) float
The objective function to minimise.
- Parameters:
x (numpy.ndarray)
- Return type:
float
- df_objective(x: numpy.ndarray) numpy.ndarray
The gradient of the objective function at
x.- Parameters:
x (numpy.ndarray)
- Return type:
numpy.ndarray
- eq_constraints() list[bluemira.optimisation.typed.ConstraintT]
- Returns:
The equality constraints on the optimisation.
- Return type:
- ineq_constraints() list[bluemira.optimisation.typed.ConstraintT]
- Returns:
The inequality constraints on the optimisation.
- Return type:
- bounds() tuple[numpy.typing.ArrayLike, numpy.typing.ArrayLike]
- Returns:
The lower and upper bounds of the optimisation parameters.
- Return type:
tuple[numpy.typing.ArrayLike, numpy.typing.ArrayLike]
Notes
Each set of bounds must be convertible to a numpy array of floats. If the lower or upper bound is a scalar value, that value is set as the bound for each of the optimisation parameters.
- optimise(x0: numpy.ndarray, *, algorithm: bluemira.optimisation._algorithm.AlgorithmType = Algorithm.SLSQP, opt_conditions: collections.abc.Mapping[str, int | float] | None = None, opt_parameters: collections.abc.Mapping[str, Any] | None = None, keep_history: bool = False, check_constraints: bool = True, check_constraints_warn: bool = True) bluemira.optimisation._optimise.OptimiserResult
Perform the optimisation.
See
optimise()for more function parameter details.- Returns:
the result of optimisation
- Parameters:
x0 (numpy.ndarray)
algorithm (bluemira.optimisation._algorithm.AlgorithmType)
opt_conditions (collections.abc.Mapping[str, int | float] | None)
opt_parameters (collections.abc.Mapping[str, Any] | None)
keep_history (bool)
check_constraints (bool)
check_constraints_warn (bool)
- Return type:
bluemira.optimisation._optimise.OptimiserResult
- check_constraints(x: numpy.ndarray, *, warn: bool = True) bool
Check if the given parameterisation violates this optimiser’s constraints.
- Parameters:
x (numpy.ndarray) – The parameterisation to check the constraints against.
warn (bool) – If
Trueprint a warning that lists the violated constraints.
- Return type:
True if any constraints are violated by the parameterisation.