bluemira.geometry.optimisation._optimise
Classes
Container for the result of a geometry optimisation. |
Functions
|
Minimise the given objective function for a geometry parameterisation. |
Module Contents
- class bluemira.geometry.optimisation._optimise.GeomOptimiserResult
Bases:
Generic[_GeomT]Container for the result of a geometry optimisation.
- geom: _GeomT
The geometry parameterisation with optimised parameters.
- f_x: float
The evaluation of 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.
- constraint_history: list[tuple[numpy.ndarray, Ellipsis]]
The history of the constraints at each iteration.
- constraints_satisfied: bool | None = None
Whether all constraints have been satisfied to within the required tolerance.
Is
Noneif constraints have not been checked.
- bluemira.geometry.optimisation._optimise.optimise_geometry(geom: _GeomT, f_objective: bluemira.geometry.optimisation.typed.GeomOptimiserObjective, df_objective: bluemira.geometry.optimisation.typed.GeomOptimiserCallable | None = None, *, keep_out_zones: collections.abc.Iterable[bluemira.geometry.wire.BluemiraWire | KeepOutZoneDict | bluemira.geometry.optimisation._tools.KeepOutZone] = (), 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, eq_constraints: collections.abc.Iterable[bluemira.geometry.optimisation.typed.GeomConstraintT] = (), ineq_constraints: collections.abc.Iterable[bluemira.geometry.optimisation.typed.GeomConstraintT] = (), keep_history: bool = False, check_constraints: bool = True, check_constraints_warn: bool = True) GeomOptimiserResult[_GeomT]
Minimise the given objective function for a geometry parameterisation.
- Parameters:
geom (_GeomT) – The geometry to optimise the parameters of. The existing parameterisation is used as the initial guess in the optimisation.
f_objective (bluemira.geometry.optimisation.typed.GeomOptimiserObjective) – The objective function to minimise. Must take as an argument a
GeometryParameterisationand return afloat.df_objective (bluemira.geometry.optimisation.typed.GeomOptimiserCallable | None) – The derivative of the objective function, by default
None. If not given, an approximation of the derivative is made using the ‘central differences’ method. This argument is ignored if a non-gradient based algorithm is used.keep_out_zones (collections.abc.Iterable[bluemira.geometry.wire.BluemiraWire | KeepOutZoneDict | bluemira.geometry.optimisation._tools.KeepOutZone]) – An iterable of keep-out zones: closed wires that the geometry must not intersect. Each item can be given as a
KeepOutZone, or a dictionary with keys the same as the properties of the classKeepOutZone, or just aBluemiraWire.algorithm (bluemira.optimisation._algorithm.AlgorithmType) – The optimisation algorithm to use, by default
Algorithm.SLSQP.opt_conditions (collections.abc.Mapping[str, int | float] | None) –
The stopping conditions for the optimiser. Supported conditions are:
ftol_abs: float
ftol_rel: float
xtol_abs: float
xtol_rel: float
max_eval: int
max_time: float
stop_val: float
for defaults see
AlgorithmDefaultConditions.opt_parameters (collections.abc.Mapping[str, Any] | None) – The algorithm-specific optimisation parameters.
eq_constraints (collections.abc.Iterable[bluemira.geometry.optimisation.typed.GeomConstraintT]) –
- The equality constraints for the optimiser.
A dict with keys:
f_constraint: the constraint function.
tolerance: the tolerances in each constraint dimension.
- df_constraint (optional): the derivative of the constraint
function. If not given, a numerical approximation of the gradient is made (if a gradient is required).
The constraint is a vector-valued, non-linear, equality constraint of the form \(f_{c}(g) = 0\).
The constraint function should have the form \(f(g) \rightarrow y\), where:
\(g\) is a geometry parameterisation.
\(y\) is a numpy array containing the values of the constraint at \(g\), with size \(m\), where \(m\) is the dimensionality of the constraint.
The tolerance array must have the same dimensionality as the constraint.
The gradient function should have the same form as the constraint function, however its output should have size \(n \times m\) where, again, \(m\) is the dimensionality of the constraint and \(n\) is the number of parameters in the geometry parameterisation.
Equality constraints are only supported by algorithms:
SLSQP
COBYLA
ISRES
ineq_constraints (collections.abc.Iterable[bluemira.geometry.optimisation.typed.GeomConstraintT])
keep_history (bool)
check_constraints (bool)
check_constraints_warn (bool)
- Return type:
GeomOptimiserResult[_GeomT]
- ineq_constraints:
The geometric inequality constraints for the optimiser. This argument has the same form as the
eq_constraintargument, but each constraint is of the form \(f_{c}(g) \le 0\).Inequality constraints are only supported by algorithms:
SLSQP
COBYLA
ISRES
- keep_history:
Whether or not to record the history of the optimisation parameters at each iteration. Note that this can significantly impact the performance of the optimisation. (default:
False)- check_constraints:
Whether to check all constraints have been satisfied at the end of the optimisation, and warn if they have not. Note that, if this is set to False, the result’s
constraints_satisfiedattribute will be set toNone.- check_constraints_warn:
Whether to print a warning that constraints have not been satisfied at the end of an optimisation. This argument has no effect if
check_constraintsisFalse.
- Return type:
The result of the optimisation.
- Parameters:
geom (_GeomT)
f_objective (bluemira.geometry.optimisation.typed.GeomOptimiserObjective)
df_objective (bluemira.geometry.optimisation.typed.GeomOptimiserCallable | None)
keep_out_zones (collections.abc.Iterable[bluemira.geometry.wire.BluemiraWire | KeepOutZoneDict | bluemira.geometry.optimisation._tools.KeepOutZone])
algorithm (bluemira.optimisation._algorithm.AlgorithmType)
opt_conditions (collections.abc.Mapping[str, int | float] | None)
opt_parameters (collections.abc.Mapping[str, Any] | None)
eq_constraints (collections.abc.Iterable[bluemira.geometry.optimisation.typed.GeomConstraintT])
ineq_constraints (collections.abc.Iterable[bluemira.geometry.optimisation.typed.GeomConstraintT])
keep_history (bool)
check_constraints (bool)
check_constraints_warn (bool)