Post-processing

In this example, we will discover the different functions of the API related to graphical post-processing of scenarios.

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()

Out:

<RootLogger root (INFO)>

Get available DOE algorithms

The get_available_post_processings() function returns the list of post-processing algorithms available in GEMSEO or in external modules

print(get_available_post_processings())

Out:

['BasicHistory', 'ConstraintsHistory', 'Correlations', 'GradientSensitivity', 'KMeans', 'ObjConstrHist', 'OptHistoryView', 'ParallelCoordinates', 'ParetoFront', 'QuadApprox', 'RadarChart', 'Robustness', 'SOM', 'ScatterPlotMatrix', 'VariableInfluence']

Get options schema

For a given post-processing algorithm, e.g. "RadarChart", we can get the options; e.g.

print(get_post_processing_options_schema("RadarChart"))

Out:

{'$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'}]}, 'iteration': {'description': 'The number of iteration to post-process.', 'type': 'integer'}, 'figsize_x': {'minimum': 2.0, 'description': 'The size of the figure in horizontal direction (inches).', 'type': 'number'}, 'figsize_y': {'minimum': 2.0, 'description': 'The size of the figure in vertical direction (inches).', 'type': 'number'}, 'constraints_list': {'description': 'The names of the constraints.', 'type': 'array', 'items': {'minItems': 1, 'type': 'string'}}}, 'required': ['constraints_list']}

Post-process a scenario

The API function execute_post() can generate visualizations of the optimization or DOE results. For that, it consider the object to post-process to_post_proc, the post processing post_name with its **options. E.g.

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()
  • Evolution of the optimization variables
  • Evolution of the objective value
  • Distance to the optimum
  • Hessian diagonal approximation

Out:

INFO - 09:26:06:
INFO - 09:26:06: *** Start MDO Scenario execution ***
INFO - 09:26:06: SellarMDFScenario
INFO - 09:26:06:    Disciplines: Sellar1 Sellar2 SellarSystem
INFO - 09:26:06:    MDOFormulation: MDF
INFO - 09:26:06:    Algorithm: NLOPT_SLSQP
INFO - 09:26:06: Optimization problem:
INFO - 09:26:06:    Minimize: obj(x_local, x_shared)
INFO - 09:26:06:    With respect to: x_local, x_shared
INFO - 09:26:06: Design Space:
INFO - 09:26:06: +----------+-------------+--------+-------------+-------+
INFO - 09:26:06: | name     | lower_bound | value  | upper_bound | type  |
INFO - 09:26:06: +----------+-------------+--------+-------------+-------+
INFO - 09:26:06: | x_local  |      0      | (1+0j) |      10     | float |
INFO - 09:26:06: | x_shared |     -10     | (4+0j) |      10     | float |
INFO - 09:26:06: | x_shared |      0      | (3+0j) |      10     | float |
INFO - 09:26:06: +----------+-------------+--------+-------------+-------+
INFO - 09:26:06: Optimization:   0%|          | 0/100 [00:00<?, ?it]
INFO - 09:26:06: Optimization:   7%|▋         | 7/100 [00:00<00:00, 929.57 it/sec, obj=3.11]
INFO - 09:26:06: Optimization:  14%|█▍        | 14/100 [00:00<00:00, 482.37 it/sec, obj=0.527]
INFO - 09:26:06: Optimization result:
INFO - 09:26:06: Objective value = 0.5272881447442123
INFO - 09:26:06: The result is feasible.
INFO - 09:26:06: Status: None
INFO - 09:26:06: Optimizer message: Successive iterates of the objective function are closer than ftol_rel or ftol_abs. GEMSEO Stopped the driver
INFO - 09:26:06: Number of calls to the objective function by the optimizer: 16
INFO - 09:26:06: Design Space:
INFO - 09:26:06: +----------+-------------+----------------------+-------------+-------+
INFO - 09:26:06: | name     | lower_bound |        value         | upper_bound | type  |
INFO - 09:26:06: +----------+-------------+----------------------+-------------+-------+
INFO - 09:26:06: | x_local  |      0      | 6.79195297030182e-13 |      10     | float |
INFO - 09:26:06: | x_shared |     -10     |  0.5816375628646853  |      10     | float |
INFO - 09:26:06: | x_shared |      0      |          0           |      10     | float |
INFO - 09:26:06: +----------+-------------+----------------------+-------------+-------+
INFO - 09:26:06: *** MDO Scenario run terminated in 0:00:00.218078 ***

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

Gallery generated by Sphinx-Gallery