Note
Click here to download the full example code
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.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()
<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())
['BasicHistory', 'Compromise', 'ConstraintsHistory', 'Correlations', 'GradientSensitivity', 'HighTradeOff', 'KMeans', 'MultiObjectiveDiagram', 'ObjConstrHist', 'OptHistoryView', 'ParallelCoordinates', 'ParetoFront', 'Petal', 'QuadApprox', 'Radar', 'RadarChart', 'Robustness', 'SOM', 'ScatterPareto', '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"))
{'$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': []}
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")
scenario.execute({"algo": "NLOPT_SLSQP", "max_iter": 100})
execute_post(scenario, "OptHistoryView", save=False, show=True)
/home/docs/checkouts/readthedocs.org/user_builds/gemseo/envs/4.2.0/lib/python3.9/site-packages/gemseo/algos/design_space.py:459: ComplexWarning: Casting complex values to real discards the imaginary part
self.__current_value[name] = array_value.astype(
INFO - 17:26:16:
INFO - 17:26:16: *** Start SellarMDFScenario execution ***
INFO - 17:26:16: SellarMDFScenario
INFO - 17:26:16: Disciplines: Sellar1 Sellar2 SellarSystem
INFO - 17:26:16: MDO formulation: MDF
INFO - 17:26:16: Optimization problem:
INFO - 17:26:16: minimize obj(x_local, x_shared)
INFO - 17:26:16: with respect to x_local, x_shared
INFO - 17:26:16: over the design space:
INFO - 17:26:16: +-------------+-------------+-------+-------------+-------+
INFO - 17:26:16: | name | lower_bound | value | upper_bound | type |
INFO - 17:26:16: +-------------+-------------+-------+-------------+-------+
INFO - 17:26:16: | x_local | 0 | 1 | 10 | float |
INFO - 17:26:16: | x_shared[0] | -10 | 4 | 10 | float |
INFO - 17:26:16: | x_shared[1] | 0 | 3 | 10 | float |
INFO - 17:26:16: +-------------+-------------+-------+-------------+-------+
INFO - 17:26:16: Solving optimization problem with algorithm NLOPT_SLSQP:
INFO - 17:26:16: ... 0%| | 0/100 [00:00<?, ?it]
INFO - 17:26:16: ... 1%| | 1/100 [00:00<00:04, 20.87 it/sec, obj=21.8+j]
INFO - 17:26:16: ... 2%|▏ | 2/100 [00:00<00:05, 17.52 it/sec, obj=101+j]
INFO - 17:26:16: ... 3%|▎ | 3/100 [00:00<00:03, 26.17 it/sec, obj=4.79+j]
WARNING - 17:26:16: MDAJacobi has reached its maximum number of iterations but the normed residual 0.021417306370533573 is still above the tolerance 1e-06.
INFO - 17:26:16: ... 4%|▍ | 4/100 [00:00<00:05, 17.48 it/sec, obj=0.827-.151j]
INFO - 17:26:16: ... 5%|▌ | 5/100 [00:00<00:04, 20.36 it/sec, obj=3.19+j]
INFO - 17:26:16: ... 6%|▌ | 6/100 [00:00<00:03, 24.39 it/sec, obj=0.571+j]
INFO - 17:26:16: ... 7%|▋ | 7/100 [00:00<00:04, 21.09 it/sec, obj=0.535+j]
INFO - 17:26:16: ... 8%|▊ | 8/100 [00:00<00:04, 21.81 it/sec, obj=0.528-3.7e-9j]
INFO - 17:26:16: ... 9%|▉ | 9/100 [00:00<00:04, 22.42 it/sec, obj=0.527+j]
INFO - 17:26:17: ... 10%|█ | 10/100 [00:00<00:03, 22.90 it/sec, obj=0.527+j]
INFO - 17:26:17: ... 11%|█ | 11/100 [00:00<00:03, 24.24 it/sec, obj=0.527+j]
INFO - 17:26:17: ... 12%|█▏ | 12/100 [00:00<00:03, 26.42 it/sec, obj=0.527+j]
INFO - 17:26:17: ... 13%|█▎ | 13/100 [00:00<00:03, 27.65 it/sec, obj=0.527+j]
INFO - 17:26:17: ... 14%|█▍ | 14/100 [00:00<00:02, 28.81 it/sec, obj=0.527+j]
INFO - 17:26:17: ... 15%|█▌ | 15/100 [00:00<00:03, 27.80 it/sec, obj=Not evaluated]
INFO - 17:26:17: Optimization result:
INFO - 17:26:17: Optimizer info:
INFO - 17:26:17: Status: None
INFO - 17:26:17: Message: Successive iterates of the objective function are closer than ftol_rel or ftol_abs. GEMSEO Stopped the driver
INFO - 17:26:17: Number of calls to the objective function by the optimizer: 18
INFO - 17:26:17: Solution:
INFO - 17:26:17: Objective: (0.5272881448154496+0j)
INFO - 17:26:17: Design space:
INFO - 17:26:17: +-------------+-------------+-----------------------+-------------+-------+
INFO - 17:26:17: | name | lower_bound | value | upper_bound | type |
INFO - 17:26:17: +-------------+-------------+-----------------------+-------------+-------+
INFO - 17:26:17: | x_local | 0 | 2.938599008285442e-13 | 10 | float |
INFO - 17:26:17: | x_shared[0] | -10 | 0.581646121057025 | 10 | float |
INFO - 17:26:17: | x_shared[1] | 0 | 1.421009702353169e-15 | 10 | float |
INFO - 17:26:17: +-------------+-------------+-----------------------+-------------+-------+
INFO - 17:26:17: *** End SellarMDFScenario execution (time: 0:00:00.561599) ***
<gemseo.post.opt_history_view.OptHistoryView object at 0x7fcce866b6a0>
Total running time of the script: ( 0 minutes 1.897 seconds)