bluemira.optimisation._nlopt.functions ====================================== .. py:module:: bluemira.optimisation._nlopt.functions Attributes ---------- .. autoapisummary:: bluemira.optimisation._nlopt.functions._FloatOrArrayT Classes ------- .. autoapisummary:: bluemira.optimisation._nlopt.functions.ConstraintType bluemira.optimisation._nlopt.functions._NloptFunction bluemira.optimisation._nlopt.functions.ObjectiveFunction bluemira.optimisation._nlopt.functions.Constraint Module Contents --------------- .. py:data:: _FloatOrArrayT .. py:class:: ConstraintType(*args, **kwds) Bases: :py:obj:`enum.Enum` .. autoapi-inheritance-diagram:: bluemira.optimisation._nlopt.functions.ConstraintType :parts: 1 :private-bases: Enumeration of constraint types. .. py:attribute:: EQUALITY .. py:attribute:: INEQUALITY .. py:class:: _NloptFunction(f: collections.abc.Callable[[numpy.ndarray], _FloatOrArrayT], bounds: tuple[_FloatOrArrayT, _FloatOrArrayT]) Base class for NLOpt objective/constraint functions. Implements the ability to calculate a numerical gradient, if an analytical one is not provided. .. py:attribute:: f .. py:attribute:: f0 :type: float | numpy.ndarray :value: 0 .. py:attribute:: bounds .. py:method:: _approx_derivative(x: numpy.ndarray) -> numpy.ndarray :returns: The approximated derivative of the function at `x`. .. py:method:: set_approx_derivative_lower_bound(lower_bound: numpy.ndarray) -> None Set the lower bounds for use in derivative approximation. .. py:method:: set_approx_derivative_upper_bound(upper_bound: numpy.ndarray) -> None Set the upper bounds for use in derivative approximation. .. py:class:: ObjectiveFunction(f: bluemira.optimisation.typed.ObjectiveCallable, df: bluemira.optimisation.typed.OptimiserCallable | None, n_variables: int, bounds: tuple[_FloatOrArrayT, _FloatOrArrayT] = (-np.inf, np.inf)) Bases: :py:obj:`_NloptFunction` .. autoapi-inheritance-diagram:: bluemira.optimisation._nlopt.functions.ObjectiveFunction :parts: 1 :private-bases: Holds an objective function for an NLOpt optimiser. Adapts the given objective function, and optional derivative, to a form understood by NLOpt. If no optimiser derivative is given, and the algorithm is gradient based, a numerical approximation of the gradient is calculated. .. py:attribute:: f :type: bluemira.optimisation.typed.ObjectiveCallable .. py:attribute:: f0 :type: float .. py:attribute:: df .. py:attribute:: history :type: list[tuple[numpy.ndarray, float]] :value: [] .. py:attribute:: prev_iter .. py:method:: call(x: numpy.ndarray, grad: numpy.ndarray) -> float Execute the NLOpt objective function. :returns: The value of the objective function at `x`. .. py:method:: call_with_history(x: numpy.ndarray, grad: numpy.ndarray) -> float Execute the NLOpt objective function, recording the iteration history. :returns: The value of the objective function at `x`, with the iteration history recorded. .. py:method:: _call_inner(x: numpy.ndarray, grad: numpy.ndarray) -> float Execute the objective function in the form required by NLOpt. :returns: The value of the objective function at `x`. .. py:method:: _store_x(x: numpy.ndarray) -> None Store ``x`` in ``self.prev_iter``. .. py:class:: Constraint(constraint_type: ConstraintType, f: bluemira.optimisation.typed.OptimiserCallable, tolerance: numpy.ndarray, df: bluemira.optimisation.typed.OptimiserCallable | None = None, bounds: tuple[_FloatOrArrayT, _FloatOrArrayT] = (-np.inf, np.inf)) Bases: :py:obj:`_NloptFunction` .. autoapi-inheritance-diagram:: bluemira.optimisation._nlopt.functions.Constraint :parts: 1 :private-bases: Holder for NLOpt constraint functions. .. py:attribute:: f :type: bluemira.optimisation.typed.OptimiserCallable .. py:attribute:: f0 :type: numpy.ndarray .. py:attribute:: constraint_type .. py:attribute:: tolerance .. py:attribute:: df .. py:attribute:: history :type: list[tuple[numpy.ndarray, Ellipsis]] :value: [] .. py:method:: call(result: numpy.ndarray, x: numpy.ndarray, grad: numpy.ndarray) -> None Execute the constraint function in the form required by NLOpt. https://nlopt.readthedocs.io/en/latest/NLopt_Python_Reference/#vector-valued-constraints .. py:method:: call_with_history(result: numpy.ndarray, x: numpy.ndarray, grad: numpy.ndarray) -> None