.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/api/plot_post.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_api_plot_post.py: Post-processing =============== In this example, we will discover the different functions of the API related to graphical post-processing of scenarios. .. GENERATED FROM PYTHON SOURCE LINES 29-42 .. code-block:: default from __future__ import annotations from gemseo.api import configure_logger from gemseo.api import create_discipline from gemseo.api import create_scenario from gemseo.api import execute_post from gemseo.api import get_available_post_processings from gemseo.api import get_post_processing_options_schema from gemseo.problems.sellar.sellar_design_space import SellarDesignSpace configure_logger() .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 43-48 Get available DOE algorithms ---------------------------- The :meth:`~gemseo.api.get_available_post_processings` function returns the list of post-processing algorithms available in |g| or in external modules .. GENERATED FROM PYTHON SOURCE LINES 48-50 .. code-block:: default print(get_available_post_processings()) .. rst-class:: sphx-glr-script-out .. code-block:: none ['BasicHistory', 'Compromise', 'ConstraintsHistory', 'Correlations', 'GradientSensitivity', 'HighTradeOff', 'KMeans', 'MultiObjectiveDiagram', 'ObjConstrHist', 'OptHistoryView', 'ParallelCoordinates', 'ParetoFront', 'Petal', 'QuadApprox', 'Radar', 'RadarChart', 'Robustness', 'SOM', 'ScatterPareto', 'ScatterPlotMatrix', 'VariableInfluence'] .. GENERATED FROM PYTHON SOURCE LINES 51-55 Get options schema ------------------ For a given post-processing algorithm, e.g. :code:`"RadarChart"`, we can get the options; e.g. .. GENERATED FROM PYTHON SOURCE LINES 55-57 .. code-block:: default print(get_post_processing_options_schema("RadarChart")) .. rst-class:: sphx-glr-script-out .. code-block:: none {'$schema': 'http://json-schema.org/draft-04/schema', 'additionalProperties': False, 'type': 'object', 'properties': {'save': {'description': 'If True, save the figure.', 'type': 'boolean'}, 'show': {'description': 'If True, display the figure.', 'type': 'boolean'}, 'file_path': {'anyOf': [{'description': 'The path of the file to save the figures.\nIf the extension is missing, use ``file_extension``.\nIf None,\ncreate a file path\nfrom ``directory_path``, ``file_name`` and ``file_extension``.', 'type': 'string'}, {'description': 'The path of the file to save the figures.\nIf the extension is missing, use ``file_extension``.\nIf None,\ncreate a file path\nfrom ``directory_path``, ``file_name`` and ``file_extension``.', 'type': 'null'}]}, 'file_extension': {'anyOf': [{'description': "A file extension, e.g. 'png', 'pdf', 'svg', ...\nIf None, use a default file extension.", 'type': 'string'}, {'description': "A file extension, e.g. 'png', 'pdf', 'svg', ...\nIf None, use a default file extension.", 'type': 'null'}]}, 'file_name': {'anyOf': [{'description': 'The name of the file to save the figures.\nIf None, use a default one generated by the post-processing.', 'type': 'string'}, {'description': 'The name of the file to save the figures.\nIf None, use a default one generated by the post-processing.', 'type': 'null'}]}, 'directory_path': {'anyOf': [{'description': 'The path of the directory to save the figures.\nIf None, use the current working directory.', 'type': 'string'}, {'description': 'The path of the directory to save the figures.\nIf None, use the current working directory.', 'type': 'null'}]}, 'fig_size': {'anyOf': [{'type': 'null'}, {'minItems': 2, 'maxItems': 2, 'type': 'array', 'items': {'type': 'number'}}]}, 'iteration': {'anyOf': [{'type': 'integer'}, {'enum': ['opt'], 'type': 'string'}]}, 'constraint_names': {'anyOf': [{'type': 'null'}, {'type': 'array', 'items': {'minItems': 1, 'type': 'string'}}]}, 'show_names_radially': {'description': 'Whether to write the names of the constraints\nin the radial direction.\nOtherwise, write them horizontally.\nThe radial direction can be useful for a high number of constraints.', 'type': 'boolean'}}, 'required': []} .. GENERATED FROM PYTHON SOURCE LINES 58-64 Post-process a scenario ----------------------- The API function :meth:`~gemseo.api.execute_post` can generate visualizations of the optimization or DOE results. For that, it consider the object to post-process :code:`to_post_proc`, the post processing :code:`post_name` with its :code:`**options`. E.g. .. GENERATED FROM PYTHON SOURCE LINES 64-69 .. code-block:: default disciplines = create_discipline(["Sellar1", "Sellar2", "SellarSystem"]) design_space = SellarDesignSpace() scenario = create_scenario(disciplines, "MDF", "obj", design_space, "SellarMDFScenario") scenario.execute({"algo": "NLOPT_SLSQP", "max_iter": 100}) execute_post(scenario, "OptHistoryView", save=False, show=True) .. rst-class:: sphx-glr-horizontal * .. image-sg:: /examples/api/images/sphx_glr_plot_post_001.png :alt: Evolution of the optimization variables :srcset: /examples/api/images/sphx_glr_plot_post_001.png :class: sphx-glr-multi-img * .. image-sg:: /examples/api/images/sphx_glr_plot_post_002.png :alt: Evolution of the objective value :srcset: /examples/api/images/sphx_glr_plot_post_002.png :class: sphx-glr-multi-img * .. image-sg:: /examples/api/images/sphx_glr_plot_post_003.png :alt: Distance to the optimum :srcset: /examples/api/images/sphx_glr_plot_post_003.png :class: sphx-glr-multi-img * .. image-sg:: /examples/api/images/sphx_glr_plot_post_004.png :alt: Hessian diagonal approximation :srcset: /examples/api/images/sphx_glr_plot_post_004.png :class: sphx-glr-multi-img .. rst-class:: sphx-glr-script-out .. code-block:: none /home/docs/checkouts/readthedocs.org/user_builds/gemseo/envs/4.3.0.post0/lib/python3.9/site-packages/gemseo/algos/design_space.py:458: ComplexWarning: Casting complex values to real discards the imaginary part self.__current_value[name] = array_value.astype( INFO - 16:59:49: INFO - 16:59:49: *** Start SellarMDFScenario execution *** INFO - 16:59:49: SellarMDFScenario INFO - 16:59:49: Disciplines: Sellar1 Sellar2 SellarSystem INFO - 16:59:49: MDO formulation: MDF INFO - 16:59:49: Optimization problem: INFO - 16:59:49: minimize obj(x_local, x_shared) INFO - 16:59:49: with respect to x_local, x_shared INFO - 16:59:49: over the design space: INFO - 16:59:49: +-------------+-------------+-------+-------------+-------+ INFO - 16:59:49: | name | lower_bound | value | upper_bound | type | INFO - 16:59:49: +-------------+-------------+-------+-------------+-------+ INFO - 16:59:49: | x_local | 0 | 1 | 10 | float | INFO - 16:59:49: | x_shared[0] | -10 | 4 | 10 | float | INFO - 16:59:49: | x_shared[1] | 0 | 3 | 10 | float | INFO - 16:59:49: +-------------+-------------+-------+-------------+-------+ INFO - 16:59:49: Solving optimization problem with algorithm NLOPT_SLSQP: INFO - 16:59:49: ... 0%| | 0/100 [00:00 .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 1.136 seconds) .. _sphx_glr_download_examples_api_plot_post.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_post.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_post.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_