Post-processing#

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

from __future__ import annotations

from gemseo import create_discipline
from gemseo import create_scenario
from gemseo import execute_post
from gemseo import get_available_post_processings
from gemseo.problems.mdo.sellar.sellar_design_space import SellarDesignSpace

Get available post-processors#

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

get_available_post_processings()
['Animation', 'BasicHistory', 'ConstraintsHistory', 'Correlations', 'DataVersusModel', 'GradientSensitivity', 'HessianHistory', 'ObjConstrHist', 'OptHistoryView', 'ParallelCoordinates', 'ParetoFront', 'QuadApprox', 'RadarChart', 'Robustness', 'SOM', 'ScatterPlotMatrix', 'TopologyGifAnimation', 'TopologyView', 'VariableInfluence']

Post-process a scenario#

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

disciplines = create_discipline(["Sellar1", "Sellar2", "SellarSystem"])
design_space = SellarDesignSpace()
scenario = create_scenario(
    disciplines, "obj", design_space, name="SellarMDFScenario", formulation_name="MDF"
)
scenario.add_constraint("c_1", constraint_type="ineq")
scenario.add_constraint("c_2", constraint_type="ineq")
scenario.execute(algo_name="NLOPT_SLSQP", max_iter=100)
execute_post(scenario, post_name="OptHistoryView", save=False, show=False)
  • Evolution of the optimization variables
  • Evolution of the objective value
  • Evolution of the distance to the optimum
  • Evolution of the inequality constraints
    INFO - 16:17:29: *** Start SellarMDFScenario execution ***
    INFO - 16:17:29: SellarMDFScenario
    INFO - 16:17:29:    Disciplines: Sellar1 Sellar2 SellarSystem
    INFO - 16:17:29:    MDO formulation: MDF
    INFO - 16:17:29: Optimization problem:
    INFO - 16:17:29:    minimize obj(x_1, x_2, x_shared)
    INFO - 16:17:29:    with respect to x_1, x_2, x_shared
    INFO - 16:17:29:    under the inequality constraints
    INFO - 16:17:29:       c_1(x_1, x_2, x_shared) <= 0
    INFO - 16:17:29:       c_2(x_1, x_2, x_shared) <= 0
    INFO - 16:17:29:    over the design space:
    INFO - 16:17:29:       +-------------+-------------+-------+-------------+-------+
    INFO - 16:17:29:       | Name        | Lower bound | Value | Upper bound | Type  |
    INFO - 16:17:29:       +-------------+-------------+-------+-------------+-------+
    INFO - 16:17:29:       | x_1         |      0      |   1   |      10     | float |
    INFO - 16:17:29:       | x_2         |      0      |   1   |      10     | float |
    INFO - 16:17:29:       | x_shared[0] |     -10     |   4   |      10     | float |
    INFO - 16:17:29:       | x_shared[1] |      0      |   3   |      10     | float |
    INFO - 16:17:29:       +-------------+-------------+-------+-------------+-------+
    INFO - 16:17:29: Solving optimization problem with algorithm NLOPT_SLSQP:
    INFO - 16:17:29:      1%|          | 1/100 [00:00<00:02, 40.52 it/sec, feas=True, obj=23]
    INFO - 16:17:29:      2%|▏         | 2/100 [00:00<00:01, 51.25 it/sec, feas=True, obj=5.39]
    INFO - 16:17:29:      3%|▎         | 3/100 [00:00<00:01, 55.66 it/sec, feas=True, obj=3.41]
    INFO - 16:17:29:      4%|▍         | 4/100 [00:00<00:01, 58.09 it/sec, feas=True, obj=3.19]
    INFO - 16:17:29:      5%|▌         | 5/100 [00:00<00:01, 59.33 it/sec, feas=True, obj=3.18]
    INFO - 16:17:29:      6%|▌         | 6/100 [00:00<00:01, 60.37 it/sec, feas=True, obj=3.18]
    INFO - 16:17:29:      7%|▋         | 7/100 [00:00<00:01, 61.16 it/sec, feas=True, obj=3.18]
    INFO - 16:17:29:      8%|▊         | 8/100 [00:00<00:01, 61.63 it/sec, feas=True, obj=3.18]
    INFO - 16:17:29: Optimization result:
    INFO - 16:17:29:    Optimizer info:
    INFO - 16:17:29:       Status: None
    INFO - 16:17:29:       Message: Successive iterates of the objective function are closer than ftol_rel or ftol_abs. GEMSEO stopped the driver.
    INFO - 16:17:29:    Solution:
    INFO - 16:17:29:       The solution is feasible.
    INFO - 16:17:29:       Objective: 3.183393962198803
    INFO - 16:17:29:       Standardized constraints:
    INFO - 16:17:29:          c_1 = -8.71791527856658e-12
    INFO - 16:17:29:          c_2 = -20.24472268402231
    INFO - 16:17:29:       Design space:
    INFO - 16:17:29:          +-------------+-------------+-----------------------+-------------+-------+
    INFO - 16:17:29:          | Name        | Lower bound |         Value         | Upper bound | Type  |
    INFO - 16:17:29:          +-------------+-------------+-----------------------+-------------+-------+
    INFO - 16:17:29:          | x_1         |      0      | 1.945503909158366e-12 |      10     | float |
    INFO - 16:17:29:          | x_2         |      0      |           0           |      10     | float |
    INFO - 16:17:29:          | x_shared[0] |     -10     |   1.977638860662459   |      10     | float |
    INFO - 16:17:29:          | x_shared[1] |      0      |           0           |      10     | float |
    INFO - 16:17:29:          +-------------+-------------+-----------------------+-------------+-------+
    INFO - 16:17:29: *** End SellarMDFScenario execution ***

<gemseo.post.opt_history_view.OptHistoryView object at 0x7b1d3881e360>

It is also possible to pass a settings model to execute_post() with the keyword settings_model, as shown below. See Post-processor Settings for more information.

from gemseo.settings.post import ConstraintsHistory_Settings  # noqa: E402

execute_post(
    scenario,
    settings_model=ConstraintsHistory_Settings(
        constraint_names=["c_1", "c_2"],
        save=False,
        show=True,
    ),
)
Evolution of the constraints w.r.t. iterations, c_1 (inequality), c_2 (inequality)
<gemseo.post.constraints_history.ConstraintsHistory object at 0x7b1d3881fa10>

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

Gallery generated by Sphinx-Gallery