bluemira.optimisation._scipy.optimiser ====================================== .. py:module:: bluemira.optimisation._scipy.optimiser .. autoapi-nested-parse:: Scipy optimisation interface Classes ------- .. autoapisummary:: bluemira.optimisation._scipy.optimiser.ScipyOptimiser Module Contents --------------- .. py:class:: ScipyOptimiser(algorithm: bluemira.optimisation._algorithm.AlgorithmType, n_variables: int, f_objective: bluemira.optimisation.typing.ObjectiveCallable, df_objective: bluemira.optimisation.typing.OptimiserCallable | None = None, opt_conditions: collections.abc.Mapping[str, int | float] | None = None, opt_parameters: collections.abc.Mapping[str, Any] | None = None, *, keep_history: bool = False) Bases: :py:obj:`bluemira.optimisation._optimiser.Optimiser` .. autoapi-inheritance-diagram:: bluemira.optimisation._scipy.optimiser.ScipyOptimiser :parts: 1 :private-bases: Interface for an optimiser supporting bounds and constraints. .. py:attribute:: n_variables .. py:attribute:: f_objective .. py:attribute:: df_objective :value: None .. py:attribute:: _eq_constraints :value: [] .. py:attribute:: _ineq_constraints :value: [] .. py:attribute:: _config .. py:attribute:: keep_history :value: False .. py:property:: algorithm :type: bluemira.optimisation._algorithm.AlgorithmType returns: the optimiser's algorithm. .. py:property:: opt_parameters :type: collections.abc.Mapping[str, int | float] returns: the optimiser algorithms's parameters. .. py:property:: lower_bounds :type: numpy.ndarray returns: the lower bounds for the optimisation parameters. .. py:property:: upper_bounds :type: numpy.ndarray returns: the upper bounds for the optimisation parameters. .. py:method:: _get_scipy_config() -> bluemira.optimisation._scipy.registry.ScipyAlgConfig Helper to safely retrieve config or raise an error. :returns: * *The associated entry in the scipy registry, which contains* * *configuration information specific to each algorithm.* :raises OptimisationError: Algorithm is not supported by SciPy. .. py:method:: _set_algorithm(alg: bluemira.optimisation._algorithm.AlgorithmType) -> None Set the optimiser's algorithm. .. py:method:: _set_parameters(opt_parameters: collections.abc.Mapping[str, int | float]) -> None Initialise the optimiser's parameters. .. py:method:: add_eq_constraint(f_constraint: bluemira.optimisation.typing.OptimiserCallable, tolerance: numpy.ndarray, df_constraint: bluemira.optimisation.typing.OptimiserCallable | None = None) -> None Add an equality constraint to the optimiser. The constraint is a vector-valued, non-linear, equality constraint of the form :math:`f_{c}(x) = 0`. The constraint function should have the form :math:`f(x) \rightarrow y`, where: * :math:`x` is a numpy array of the optimisation parameters. * :math:`y` is a numpy array containing the values of the constraint at :math:`x`, with size :math:`m`, where :math:`m` is the dimensionality of the constraint. :param f_constraint: The constraint function, with form as described above. :param tolerance: The tolerances for each optimisation parameter. :param df_constraint: The gradient of the constraint function. This should have the same form as the constraint function, however its output array should have dimensions :math:`m \times n` where :math`m` is the dimensionality of the constraint, and :math:`n` is the number of optimisation parameters. :raises OptimisationError: Algorithm does not support equality constraints. .. rubric:: Notes Equality constraints are only supported by algorithms: * SLSQP * COBYQA * TRUST_CONSTR However, equality constraints can be converted to pairs of inequality constraints to work with other algorithms, such as COBYLA. .. py:method:: add_ineq_constraint(f_constraint: bluemira.optimisation.typing.OptimiserCallable, tolerance: numpy.ndarray, df_constraint: bluemira.optimisation.typing.OptimiserCallable | None = None) -> None Add an inequality constrain to the optimiser. The constraint is a vector-valued, non-linear, inequality constraint of the form :math:`f_{c}(x) \le 0`. The constraint function should have the form :math:`f(x) \rightarrow y`, where: * :math:`x` is a numpy array of the optimisation parameters. * :math:`y` is a numpy array containing the values of the constraint at :math:`x`, with size :math:`m`, where :math:`m` is the dimensionality of the constraint. :param f_constraint: The constraint function, with form as described above. :param tolerance: The tolerances for each optimisation parameter. :param df_constraint: The gradient of the constraint function. This should have the same form as the constraint function, however its output array should have dimensions :math:`m \times n` where :math`m` is the dimensionality of the constraint, and :math:`n` is the number of optimisation parameters. :raises OptimisationError: Algorithm does not support inequality constraints. .. rubric:: Notes Inequality constraints are only supported by algorithms: * SLSQP * COBYLA * COBYQA .. py:method:: optimise(x0: numpy.ndarray | None = None) -> bluemira.optimisation._optimiser.OptimiserResult Run the optimiser. :param x0: The initial guess for each of the optimisation parameters. If not given, each parameter is set to the average of its lower and upper bound. If no bounds exist, the initial guess will be all zeros. :returns: * *The result of the optimisation, containing the optimised* * parameters ``x``, as well as other information about the * *optimisation.* :raises OptimisationError: Low-level optimisation error. :raises KeyboardInterrupt: Optimisation halted by user. .. py:method:: set_lower_bounds(bounds: numpy.ndarray) -> None Set the lower bound for each optimisation parameter. Set to `-np.inf` to unbound the parameter's minimum. :raises ValueError: Incorrect bounds dimensions. .. py:method:: set_upper_bounds(bounds: numpy.ndarray) -> None Set the upper bound for each optimisation parameter. Set to `np.inf` to unbound the parameter's minimum. :raises ValueError: Incorrect bounds dimensions.