bluemira.optimisation.problem ============================= .. py:module:: bluemira.optimisation.problem .. autoapi-nested-parse:: Interface for defining an optimisation problem. Classes ------- .. autoapisummary:: bluemira.optimisation.problem.OptimisationProblemBase bluemira.optimisation.problem.OptimisationProblem Module Contents --------------- .. py:class:: OptimisationProblemBase Common base class for OptimisationProblem classes. .. py:attribute:: __MethodT .. py:attribute:: __AnyT .. py:method:: _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_objective`` case, 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 .. py:method:: __is_method(f: __MethodT, cls: type[Any]) -> bool :staticmethod: Determine if the given method is a member of this base class or not. Note that ``f`` must 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 .. py:class:: OptimisationProblem Bases: :py:obj:`abc.ABC`, :py:obj:`OptimisationProblemBase` .. autoapi-inheritance-diagram:: bluemira.optimisation.problem.OptimisationProblem :parts: 1 :private-bases: Interface for an optimisation problem. This is an alternative to running an optimisation using the :func:`.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. .. py:method:: objective(x: numpy.ndarray) -> float :abstractmethod: The objective function to minimise. .. py:method:: df_objective(x: numpy.ndarray) -> numpy.ndarray The gradient of the objective function at ``x``. .. py:method:: eq_constraints() -> list[bluemira.optimisation.typed.ConstraintT] :returns: The equality constraints on the optimisation. .. py:method:: ineq_constraints() -> list[bluemira.optimisation.typed.ConstraintT] :returns: The inequality constraints on the optimisation. .. py:method:: bounds() -> tuple[numpy.typing.ArrayLike, numpy.typing.ArrayLike] :returns: The lower and upper bounds of the optimisation parameters. .. rubric:: 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. .. py:method:: 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 :func:`.optimise` for more function parameter details. :returns: the result of optimisation .. py:method:: check_constraints(x: numpy.ndarray, *, warn: bool = True) -> bool Check if the given parameterisation violates this optimiser's constraints. :param x: The parameterisation to check the constraints against. :param warn: If ``True`` print a warning that lists the violated constraints. :rtype: True if any constraints are violated by the parameterisation.