Optimization algorithms#

In this example, we will discover the different high-levels functions related to optimization algorithms.

from __future__ import annotations

from gemseo import get_algorithm_options_schema
from gemseo import get_available_opt_algorithms

Get available optimization algorithms#

The get_available_opt_algorithms() function returns the list of optimization algorithms available in GEMSEO or in external modules

get_available_opt_algorithms()
['Augmented_Lagrangian_order_0', 'Augmented_Lagrangian_order_1', 'Scipy_MILP', 'HEXALY', 'MMA', 'MNBI', 'MultiStart', 'NLOPT_MMA', 'NLOPT_COBYLA', 'NLOPT_SLSQP', 'NLOPT_BOBYQA', 'NLOPT_BFGS', 'NLOPT_NEWUOA', 'PDFO_COBYLA', 'PDFO_BOBYQA', 'PDFO_NEWUOA', 'PYOPTSPARSE_SLSQP', 'PYOPTSPARSE_SNOPT', 'PYMOO_GA', 'PYMOO_NSGA2', 'PYMOO_NSGA3', 'PYMOO_UNSGA3', 'PYMOO_RNSGA3', 'SMT_EGO', 'DUAL_ANNEALING', 'SHGO', 'DIFFERENTIAL_EVOLUTION', 'INTERIOR_POINT', 'DUAL_SIMPLEX', 'SLSQP', 'L-BFGS-B', 'TNC', 'NELDER-MEAD', 'COBYQA']

Get options schema#

For a given optimization algorithm, e.g. "NLOPT_SLSQP", we can get the options; e.g.

get_algorithm_options_schema("NLOPT_SLSQP")
{'$defs': {'ProgressBarDataName': {'enum': ['ProgressBarData'], 'title': 'ProgressBarDataName', 'type': 'string'}}, 'additionalProperties': False, 'description': 'The settings for the NLopt SLSQP algorithm.', 'properties': {'kkt_tol_abs': {'default': inf, 'description': 'The absolute tolerance on the KKT residual norm.\n\nIf ``inf`` this criterion is not activated.', 'minimum': 0, 'title': 'Kkt Tol Abs', 'type': 'number'}, 'kkt_tol_rel': {'default': inf, 'description': 'The relative tolerance on the KKT residual norm.\n\nIf ``inf`` this criterion is not activated.', 'minimum': 0, 'title': 'Kkt Tol Rel', 'type': 'number'}, 'enable_progress_bar': {'anyOf': [{'type': 'boolean'}, {'type': 'null'}], 'default': None, 'description': 'Whether to enable the progress bar in the optimization log.\n\nIf ``None``, use the global value of ``enable_progress_bar`` (see the\n``configure`` function to change it globally).', 'title': 'Enable Progress Bar'}, 'eq_tolerance': {'default': 0.01, 'description': 'The tolerance on the equality constraints.', 'minimum': 0, 'title': 'Eq Tolerance', 'type': 'number'}, 'ineq_tolerance': {'default': 0.0001, 'description': 'The tolerance on the inequality constraints.', 'minimum': 0, 'title': 'Ineq Tolerance', 'type': 'number'}, 'log_problem': {'default': True, 'description': 'Whether to log the definition and result of the problem.', 'title': 'Log Problem', 'type': 'boolean'}, 'max_time': {'default': 0.0, 'description': 'The maximum runtime in seconds, disabled if 0.', 'minimum': 0, 'title': 'Max Time', 'type': 'number'}, 'normalize_design_space': {'default': True, 'description': 'Whether to normalize the design space variables between 0 and 1.', 'title': 'Normalize Design Space', 'type': 'boolean'}, 'progress_bar_data_name': {'$ref': '#/$defs/ProgressBarDataName', 'default': 'ProgressBarData', 'description': 'The name of a :class:`.BaseProgressBarData` class\nto define the data of an evaluation problem to be displayed in the progress bar.'}, 'reset_iteration_counters': {'default': True, 'description': 'Whether to reset the iteration counters before each execution.', 'title': 'Reset Iteration Counters', 'type': 'boolean'}, 'round_ints': {'default': True, 'description': 'Whether to round the integer variables.', 'title': 'Round Ints', 'type': 'boolean'}, 'store_jacobian': {'default': True, 'description': 'Whether to store the Jacobian matrices in the database.\n\n    This argument is ignored when the ``use_database`` option is ``False``.\n    If a gradient-based algorithm is used,\n    this option cannot be set along with kkt options.', 'title': 'Store Jacobian', 'type': 'boolean'}, 'use_database': {'default': True, 'description': 'Whether to wrap the functions in the database.', 'title': 'Use Database', 'type': 'boolean'}, 'use_one_line_progress_bar': {'default': False, 'description': 'Whether to log the progress bar on a single line.', 'title': 'Use One Line Progress Bar', 'type': 'boolean'}, 'ftol_rel': {'default': 1e-08, 'description': 'The relative tolerance on the objective function.', 'minimum': 0, 'title': 'Ftol Rel', 'type': 'number'}, 'ftol_abs': {'default': 1e-14, 'description': 'The absolute tolerance on the objective function.', 'minimum': 0, 'title': 'Ftol Abs', 'type': 'number'}, 'max_iter': {'default': 1000, 'description': 'The maximum number of iterations.', 'exclusiveMinimum': 0, 'title': 'Max Iter', 'type': 'integer'}, 'scaling_threshold': {'anyOf': [{'minimum': 0, 'type': 'number'}, {'type': 'null'}], 'default': None, 'description': 'The threshold on the reference function value that triggers scaling.\n\nIf ``None``, do not scale the functions.', 'title': 'Scaling Threshold'}, 'stop_crit_n_x': {'anyOf': [{'minimum': 2, 'type': 'integer'}, {'type': 'null'}], 'default': None, 'description': 'The minimum number of design vectors to consider in the stopping criteria.', 'title': 'Stop Crit N X'}, 'xtol_rel': {'default': 1e-08, 'description': 'The relative tolerance on the design parameters.', 'minimum': 0, 'title': 'Xtol Rel', 'type': 'number'}, 'xtol_abs': {'default': 1e-14, 'description': 'The absolute tolerance on the design parameters.', 'minimum': 0, 'title': 'Xtol Abs', 'type': 'number'}, 'stopval': {'default': -inf, 'description': 'The objective value at which the optimization will stop.', 'title': 'Stopval', 'type': 'number'}}, 'title': 'NLOPT_SLSQP_Settings', 'type': 'object'}

Or import its settings model and pass it directly with the keyword "algo_settings_model".

from gemseo.settings.opt import NLOPT_SLSQP_Settings  # noqa: E402, I001

settings_model = NLOPT_SLSQP_Settings()

See Algorithm Settings for more information on how to use settings models.

Total running time of the script: (0 minutes 0.003 seconds)

Gallery generated by Sphinx-Gallery