bluemira.geometry.optimisation._optimise ======================================== .. py:module:: bluemira.geometry.optimisation._optimise Classes ------- .. autoapisummary:: bluemira.geometry.optimisation._optimise.GeomOptimiserResult Functions --------- .. autoapisummary:: bluemira.geometry.optimisation._optimise.optimise_geometry Module Contents --------------- .. py:class:: GeomOptimiserResult Bases: :py:obj:`Generic`\ [\ :py:obj:`_GeomT`\ ] .. autoapi-inheritance-diagram:: bluemira.geometry.optimisation._optimise.GeomOptimiserResult :parts: 1 :private-bases: Container for the result of a geometry optimisation. .. py:attribute:: geom :type: _GeomT The geometry parameterisation with optimised parameters. .. py:attribute:: f_x :type: float The evaluation of the optimised parameterisation. .. py:attribute:: n_evals :type: int The number of evaluations of the objective function in the optimisation. .. py:attribute:: history :type: list[tuple[numpy.ndarray, float]] The history of the parameterisation at each iteration. .. py:attribute:: constraint_history :type: list[tuple[numpy.ndarray, Ellipsis]] The history of the constraints at each iteration. .. py:attribute:: constraints_satisfied :type: bool | None :value: None Whether all constraints have been satisfied to within the required tolerance. Is ``None`` if constraints have not been checked. .. py:function:: 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. :param geom: The geometry to optimise the parameters of. The existing parameterisation is used as the initial guess in the optimisation. :param f_objective: The objective function to minimise. Must take as an argument a ``GeometryParameterisation`` and return a ``float``. :param df_objective: 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. :param keep_out_zones: An iterable of keep-out zones: closed wires that the geometry must not intersect. Each item can be given as a :class:`.KeepOutZone`, or a dictionary with keys the same as the properties of the class :class:`.KeepOutZone`, or just a :class:`~bluemira.geometry.wire.BluemiraWire`. :param algorithm: The optimisation algorithm to use, by default :obj:`.Algorithm.SLSQP`. :param opt_conditions: 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 :class:`~bluemira.optimisation._algorithm.AlgorithmDefaultConditions`. :param opt_parameters: The algorithm-specific optimisation parameters. :param eq_constraints: 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 :math:`f_{c}(g) = 0`. The constraint function should have the form :math:`f(g) \rightarrow y`, where: * :math:`g` is a geometry parameterisation. * :math:`y` is a numpy array containing the values of the constraint at :math:`g`, with size :math:`m`, where :math:`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 :math:`n \times m` where, again, :math:`m` is the dimensionality of the constraint and :math:`n` is the number of parameters in the geometry parameterisation. Equality constraints are only supported by algorithms: * SLSQP * COBYLA * ISRES ineq_constraints: The geometric inequality constraints for the optimiser. This argument has the same form as the ``eq_constraint`` argument, but each constraint is of the form :math:`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_satisfied`` attribute will be set to ``None``. 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_constraints`` is ``False``. :rtype: The result of the optimisation.