.. 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 31-48 .. code-block:: default from __future__ import division, unicode_literals from matplotlib import pyplot as plt from gemseo.api import ( configure_logger, create_discipline, create_scenario, execute_post, get_available_post_processings, get_post_processing_options_schema, ) from gemseo.problems.sellar.sellar_design_space import SellarDesignSpace configure_logger() .. rst-class:: sphx-glr-script-out Out: .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 49-54 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 54-56 .. code-block:: default print(get_available_post_processings()) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none ['BasicHistory', 'ConstraintsHistory', 'Correlations', 'GradientSensitivity', 'KMeans', 'ObjConstrHist', 'OptHistoryView', 'ParallelCoordinates', 'ParetoFront', 'QuadApprox', 'RadarChart', 'Robustness', 'SOM', 'ScatterPlotMatrix', 'VariableInfluence'] .. GENERATED FROM PYTHON SOURCE LINES 57-61 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 61-63 .. code-block:: default print(get_post_processing_options_schema("RadarChart")) .. rst-class:: sphx-glr-script-out 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. If the extension is missing, use ``file_extension``. If None, create a file path from ``directory_path``, ``file_name`` and ``file_extension``.', 'type': 'string'}, {'description': 'The path of the file to save the figures. If the extension is missing, use ``file_extension``. If None, create a file path from ``directory_path``, ``file_name`` and ``file_extension``.', 'type': 'null'}]}, 'file_extension': {'anyOf': [{'description': "A file extension, e.g. 'png', 'pdf', 'svg', ... If None, use a default file extension.", 'type': 'string'}, {'description': "A file extension, e.g. 'png', 'pdf', 'svg', ... If None, use a default file extension.", 'type': 'null'}]}, 'file_name': {'anyOf': [{'description': 'The name of the file to save the figures. If None, use a default one generated by the post-processing.', 'type': 'string'}, {'description': 'The name of the file to save the figures. If 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. If None, use the current working directory.', 'type': 'string'}, {'description': 'The path of the directory to save the figures. If None, use the current working directory.', 'type': 'null'}]}, 'fig_size': {'anyOf': [{'description': 'The width and height of the figure in inches, e.g. `(w, h)`. If None, use the :attr:`DEFAULT_FIG_SIZE` of the post-processor.', 'type': 'null'}, {'minItems': 2, 'maxItems': 2, 'description': 'The width and height of the figure in inches, e.g. `(w, h)`. If None, use the :attr:`DEFAULT_FIG_SIZE` of the post-processor.', 'type': 'array', 'items': {'type': 'number'}}]}, 'iteration': {'description': 'The number of iteration to post-process.', 'type': 'integer'}, 'constraints_list': {'description': 'The names of the constraints.', 'type': 'array', 'items': {'minItems': 1, 'type': 'string'}}}, 'required': ['constraints_list']} .. GENERATED FROM PYTHON SOURCE LINES 64-70 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 70-79 .. code-block:: default disciplines = create_discipline(["Sellar1", "Sellar2", "SellarSystem"]) design_space = SellarDesignSpace() scenario = create_scenario( disciplines, "MDF", "obj", design_space, "SellarMDFScenario", "MDO" ) scenario.execute({"algo": "NLOPT_SLSQP", "max_iter": 100}) execute_post(scenario, "OptHistoryView", show=False, save=False) # Workaround for HTML rendering, instead of ``show=True`` plt.show() .. rst-class:: sphx-glr-horizontal * .. image:: /examples/api/images/sphx_glr_plot_post_001.png :alt: Evolution of the optimization variables :class: sphx-glr-multi-img * .. image:: /examples/api/images/sphx_glr_plot_post_002.png :alt: Evolution of the objective value :class: sphx-glr-multi-img * .. image:: /examples/api/images/sphx_glr_plot_post_003.png :alt: Distance to the optimum :class: sphx-glr-multi-img * .. image:: /examples/api/images/sphx_glr_plot_post_004.png :alt: Hessian diagonal approximation :class: sphx-glr-multi-img .. rst-class:: sphx-glr-script-out Out: .. code-block:: none INFO - 14:42:44: INFO - 14:42:44: *** Start MDO Scenario execution *** INFO - 14:42:44: SellarMDFScenario INFO - 14:42:44: Disciplines: Sellar1 Sellar2 SellarSystem INFO - 14:42:44: MDOFormulation: MDF INFO - 14:42:44: Algorithm: NLOPT_SLSQP INFO - 14:42:44: Optimization problem: INFO - 14:42:44: Minimize: obj(x_local, x_shared) INFO - 14:42:44: With respect to: x_local, x_shared INFO - 14:42:44: Design space: INFO - 14:42:44: +----------+-------------+--------+-------------+-------+ INFO - 14:42:44: | name | lower_bound | value | upper_bound | type | INFO - 14:42:44: +----------+-------------+--------+-------------+-------+ INFO - 14:42:44: | x_local | 0 | (1+0j) | 10 | float | INFO - 14:42:44: | x_shared | -10 | (4+0j) | 10 | float | INFO - 14:42:44: | x_shared | 0 | (3+0j) | 10 | float | INFO - 14:42:44: +----------+-------------+--------+-------------+-------+ INFO - 14:42:44: Optimization: 0%| | 0/100 [00:00` .. 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 `_