.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/api/plot_optimization.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_api_plot_optimization.py: Optimization algorithms ======================= In this example, we will discover the different high-levels functions related to optimization algorithms. .. GENERATED FROM PYTHON SOURCE LINES 30-36 .. code-block:: Python from __future__ import annotations from gemseo import get_algorithm_options_schema from gemseo import get_available_opt_algorithms .. GENERATED FROM PYTHON SOURCE LINES 37-42 Get available optimization algorithms ------------------------------------- The :meth:`.get_available_opt_algorithms` function returns the list of optimization algorithms available in |g| or in external modules .. GENERATED FROM PYTHON SOURCE LINES 42-44 .. code-block:: Python get_available_opt_algorithms() .. rst-class:: sphx-glr-script-out .. code-block:: none ['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'] .. GENERATED FROM PYTHON SOURCE LINES 45-49 Get options schema ------------------ For a given optimization algorithm, e.g. ``"NLOPT_SLSQP"``, we can get the options; e.g. .. GENERATED FROM PYTHON SOURCE LINES 49-51 .. code-block:: Python get_algorithm_options_schema("NLOPT_SLSQP") .. rst-class:: sphx-glr-script-out .. code-block:: none {'$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'} .. GENERATED FROM PYTHON SOURCE LINES 52-54 Or import its settings model and pass it directly with the keyword "algo_settings_model". .. GENERATED FROM PYTHON SOURCE LINES 54-58 .. code-block:: Python from gemseo.settings.opt import NLOPT_SLSQP_Settings # noqa: E402, I001 settings_model = NLOPT_SLSQP_Settings() .. GENERATED FROM PYTHON SOURCE LINES 59-60 See :ref:`algorithm_settings` for more information on how to use settings models. .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.003 seconds) .. _sphx_glr_download_examples_api_plot_optimization.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_optimization.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_optimization.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_optimization.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_