.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/post_process/post_process_opt_problem.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_post_process_post_process_opt_problem.py: Post-process an optimization problem ==================================== .. GENERATED FROM PYTHON SOURCE LINES 25-34 .. code-block:: Python from __future__ import annotations from gemseo import create_design_space from gemseo import execute_algo from gemseo import execute_post from gemseo.algos.opt_problem import OptimizationProblem from gemseo.core.mdofunctions.mdo_function import MDOFunction .. GENERATED FROM PYTHON SOURCE LINES 35-37 We consider a minimization problem over the interval :math:`[0,1]` of the :math:`f(x)=x^2` objective function: .. GENERATED FROM PYTHON SOURCE LINES 37-46 .. code-block:: Python objective = MDOFunction(lambda x: x**2, "f", input_names=["x"], output_names=["y"]) design_space = create_design_space() design_space.add_variable("x", l_b=0.0, u_b=1.0) optimization_problem = OptimizationProblem(design_space) optimization_problem.objective = objective .. GENERATED FROM PYTHON SOURCE LINES 47-48 We solve this optimization problem with the gradient-free algorithm COBYLA: .. GENERATED FROM PYTHON SOURCE LINES 48-50 .. code-block:: Python execute_algo(optimization_problem, "NLOPT_COBYLA", max_iter=10) .. GENERATED FROM PYTHON SOURCE LINES 51-54 Then, we can post-process this :class:`.OptimizationProblem` with the function :func:`.execute_post`: .. GENERATED FROM PYTHON SOURCE LINES 54-56 .. code-block:: Python execute_post(optimization_problem, "BasicHistory", variable_names=["y"]) .. GENERATED FROM PYTHON SOURCE LINES 57-62 .. note:: By default, |g| saves the images on the disk. Use ``save=False`` to not save figures and ``show=True`` to display them on the screen. .. seealso:: `Post-processing algorithms `_. .. _sphx_glr_download_examples_post_process_post_process_opt_problem.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: post_process_opt_problem.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: post_process_opt_problem.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_