Note
Go to the end 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 import configure_logger
from gemseo import create_discipline
from gemseo import create_scenario
from gemseo import execute_post
from gemseo import get_available_post_processings
from gemseo 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
get_available_post_processings()
['Animation', 'BasicHistory', 'Compromise', 'ConstraintsHistory', 'Correlations', 'GradientSensitivity', 'HighTradeOff', 'MultiObjectiveDiagram', 'ObjConstrHist', 'OptHistoryView', 'ParallelCoordinates', 'ParetoFront', 'Petal', 'QuadApprox', 'Radar', 'RadarChart', 'Robustness', 'SOM', 'ScatterPareto', 'ScatterPlotMatrix', 'TopologyView', 'VariableInfluence']
Get options schema¶
For a given post-processing algorithm, e.g. "RadarChart"
,
we can get the options; e.g.
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': [{'description': 'The width and height of the figure in inches, e.g. ``(w, h)``.\nIf ``None``, use the :attr:`.OptPostProcessor.DEFAULT_FIG_SIZE`\nof the post-processor.', 'type': 'null'}, {'minItems': 2, 'maxItems': 2, 'description': 'The width and height of the figure in inches, e.g. ``(w, h)``.\nIf ``None``, use the :attr:`.OptPostProcessor.DEFAULT_FIG_SIZE`\nof the post-processor.', 'type': 'array', 'items': {'type': 'number'}}]}, 'iteration': {'anyOf': [{'description': 'Either an iteration in :math:`-N,\\ldots,-1,1,`ldots,N`\nor the tag :attr:`.OPTIMUM` for the iteration\nat which the optimum is located,\nwhere :math:`N` is the length of the database.', 'type': 'integer'}, {'enum': ['opt'], 'description': 'Either an iteration in :math:`-N,\\ldots,-1,1,`ldots,N`\nor the tag :attr:`.OPTIMUM` for the iteration\nat which the optimum is located,\nwhere :math:`N` is the length of the database.', 'type': 'string'}]}, 'constraint_names': {'anyOf': [{'description': 'The names of the constraints.\nIf ``None``, use all the constraints.', 'type': 'null'}, {'description': 'The names of the constraints.\nIf ``None``, use all the constraints.', '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/develop/lib/python3.9/site-packages/gemseo/algos/design_space.py:444: ComplexWarning: Casting complex values to real discards the imaginary part
self.__current_value[name] = array_value.astype(
INFO - 15:35:47:
INFO - 15:35:47: *** Start SellarMDFScenario execution ***
INFO - 15:35:47: SellarMDFScenario
INFO - 15:35:47: Disciplines: Sellar1 Sellar2 SellarSystem
INFO - 15:35:47: MDO formulation: MDF
INFO - 15:35:47: Optimization problem:
INFO - 15:35:47: minimize obj(x_local, x_shared)
INFO - 15:35:47: with respect to x_local, x_shared
INFO - 15:35:47: over the design space:
INFO - 15:35:47: +-------------+-------------+-------+-------------+-------+
INFO - 15:35:47: | name | lower_bound | value | upper_bound | type |
INFO - 15:35:47: +-------------+-------------+-------+-------------+-------+
INFO - 15:35:47: | x_local | 0 | 1 | 10 | float |
INFO - 15:35:47: | x_shared[0] | -10 | 4 | 10 | float |
INFO - 15:35:47: | x_shared[1] | 0 | 3 | 10 | float |
INFO - 15:35:47: +-------------+-------------+-------+-------------+-------+
INFO - 15:35:47: Solving optimization problem with algorithm NLOPT_SLSQP:
INFO - 15:35:47: ... 0%| | 0/100 [00:00<?, ?it]
INFO - 15:35:47: ... 1%| | 1/100 [00:00<00:02, 33.76 it/sec, obj=21.8+j]
INFO - 15:35:48: ... 2%|▏ | 2/100 [00:00<00:03, 26.00 it/sec, obj=101+j]
INFO - 15:35:48: ... 3%|▎ | 3/100 [00:00<00:02, 38.83 it/sec, obj=4.79+j]
INFO - 15:35:48: ... 4%|▍ | 4/100 [00:00<00:03, 29.78 it/sec, obj=0.661+.177j]
INFO - 15:35:48: ... 5%|▌ | 5/100 [00:00<00:02, 33.88 it/sec, obj=2.02+j]
INFO - 15:35:48: ... 6%|▌ | 6/100 [00:00<00:02, 40.58 it/sec, obj=0.547-3.32e-12j]
INFO - 15:35:48: ... 7%|▋ | 7/100 [00:00<00:02, 35.69 it/sec, obj=0.579+j]
INFO - 15:35:48: ... 8%|▊ | 8/100 [00:00<00:02, 40.72 it/sec, obj=0.531+j]
INFO - 15:35:48: ... 9%|▉ | 9/100 [00:00<00:02, 34.84 it/sec, obj=0.527+j]
INFO - 15:35:48: ... 10%|█ | 10/100 [00:00<00:02, 35.27 it/sec, obj=0.527+j]
INFO - 15:35:48: ... 11%|█ | 11/100 [00:00<00:02, 35.68 it/sec, obj=0.527+j]
INFO - 15:35:48: ... 12%|█▏ | 12/100 [00:00<00:02, 37.59 it/sec, obj=0.527+j]
INFO - 15:35:48: ... 13%|█▎ | 13/100 [00:00<00:02, 40.68 it/sec, obj=0.527+j]
INFO - 15:35:48: ... 14%|█▍ | 14/100 [00:00<00:02, 42.47 it/sec, obj=0.527+j]
INFO - 15:35:48: ... 15%|█▌ | 15/100 [00:00<00:01, 44.08 it/sec, obj=0.527+j]
INFO - 15:35:48: Optimization result:
INFO - 15:35:48: Optimizer info:
INFO - 15:35:48: Status: None
INFO - 15:35:48: Message: Successive iterates of the objective function are closer than ftol_rel or ftol_abs. GEMSEO Stopped the driver
INFO - 15:35:48: Number of calls to the objective function by the optimizer: 19
INFO - 15:35:48: Solution:
INFO - 15:35:48: Objective: (0.5272881443195433+0j)
INFO - 15:35:48: Sellar design space:
INFO - 15:35:48: +-------------+-------------+-----------------------+-------------+-------+
INFO - 15:35:48: | name | lower_bound | value | upper_bound | type |
INFO - 15:35:48: +-------------+-------------+-----------------------+-------------+-------+
INFO - 15:35:48: | x_local | 0 | 7.016609515630991e-16 | 10 | float |
INFO - 15:35:48: | x_shared[0] | -10 | 0.5816394181438191 | 10 | float |
INFO - 15:35:48: | x_shared[1] | 0 | 3.813464287068206e-12 | 10 | float |
INFO - 15:35:48: +-------------+-------------+-----------------------+-------------+-------+
INFO - 15:35:48: *** End SellarMDFScenario execution (time: 0:00:00.354605) ***
<gemseo.post.opt_history_view.OptHistoryView object at 0x7fcc230bf880>
Total running time of the script: ( 0 minutes 1.298 seconds)