.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/namespaces/plot_sobieski_namespaces_example.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_namespaces_plot_sobieski_namespaces_example.py: Multi-point computations using namespaces ========================================= .. GENERATED FROM PYTHON SOURCE LINES 24-31 .. code-block:: Python from __future__ import annotations from gemseo import create_design_space from gemseo import create_discipline from gemseo import create_scenario .. GENERATED FROM PYTHON SOURCE LINES 32-38 About namespaces ---------------- Namespaces are prefixes to input or output names of the disciplines. The name of a variable can be prefixed by the namespace and a separator, ":" by default. This allows to control the coupling of disciplines, or to duplicate a discipline in a process. .. GENERATED FROM PYTHON SOURCE LINES 40-46 Instantiate the disciplines --------------------------- We instantiate twice the same discipline, they will be configured with the namespaces to compute different outputs. Some inputs will be shared, without namespace, and others will have different namespaces. .. GENERATED FROM PYTHON SOURCE LINES 46-48 .. code-block:: Python disciplines = create_discipline(["SobieskiMission", "SobieskiMission"]) .. GENERATED FROM PYTHON SOURCE LINES 49-57 Setting the namespaces ---------------------- In the SSBJ test case, the ``y_34`` vector is the engine Specific Fuel Consumption (SFC). Let's say that we want to compute the average range of the aircraft, operating at two different operating conditions (``oc1`` and ``oc2``), which leads to two different SFC. We add the specific namespaces to the SFC (``y_34``) of the disciplines, and to the output range (``y_4``) The other inputs of the discipline remain the same, so they share their values. .. GENERATED FROM PYTHON SOURCE LINES 57-63 .. code-block:: Python disciplines[0].input_grammar.add_namespace("y_34", "oc1") disciplines[1].input_grammar.add_namespace("y_34", "oc2") disciplines[0].output_grammar.add_namespace("y_4", "oc1") disciplines[1].output_grammar.add_namespace("y_4", "oc2") .. GENERATED FROM PYTHON SOURCE LINES 64-69 Averaging the outputs --------------------- Then we need to create a specific discipline to average the outputs. We use the LinearCombination discipline for that. Note that the namespaces can be set by the input name directly. .. GENERATED FROM PYTHON SOURCE LINES 69-78 .. code-block:: Python disciplines.append( create_discipline( "LinearCombination", input_names=["oc1:y_4", "oc2:y_4"], output_name="average_y_4", input_coefficients={"oc1:y_4": 0.5, "oc2:y_4": 0.5}, ) ) .. GENERATED FROM PYTHON SOURCE LINES 79-83 Build, execute and post-process the scenario -------------------------------------------- In the design space, we add the two variables that are namespaced, and simulate several SFCs. The other variables remain at their default input's values. .. GENERATED FROM PYTHON SOURCE LINES 83-87 .. code-block:: Python design_space = create_design_space() design_space.add_variable("oc1:y_34", lower_bound=0.8, upper_bound=2.0) design_space.add_variable("oc2:y_34", lower_bound=0.8, upper_bound=2.0) .. GENERATED FROM PYTHON SOURCE LINES 88-91 Instantiate the scenario ^^^^^^^^^^^^^^^^^^^^^^^^ The objective is the averaged range. .. GENERATED FROM PYTHON SOURCE LINES 91-99 .. code-block:: Python scenario = create_scenario( disciplines, formulation_name="MDF", objective_name="average_y_4", design_space=design_space, maximize_objective=True, scenario_type="DOE", ) .. GENERATED FROM PYTHON SOURCE LINES 100-104 Visualize the XDSM ^^^^^^^^^^^^^^^^^^ The XDSM shows well the averaging proces and the duplication of the disciplines as well as the data handling .. GENERATED FROM PYTHON SOURCE LINES 104-108 .. code-block:: Python scenario.xdsmize(save_html=False) scenario.execute(n_samples=20, algo_name="LHS") .. rst-class:: sphx-glr-script-out .. code-block:: none INFO - 16:25:57: *** Start DOEScenario execution *** INFO - 16:25:57: DOEScenario INFO - 16:25:57: Disciplines: LinearCombination SobieskiMission SobieskiMission INFO - 16:25:57: MDO formulation: MDF INFO - 16:25:57: Optimization problem: INFO - 16:25:57: minimize -average_y_4(oc1:y_34, oc2:y_34) INFO - 16:25:57: with respect to oc1:y_34, oc2:y_34 INFO - 16:25:57: over the design space: INFO - 16:25:57: +----------+-------------+-------+-------------+-------+ INFO - 16:25:57: | Name | Lower bound | Value | Upper bound | Type | INFO - 16:25:57: +----------+-------------+-------+-------------+-------+ INFO - 16:25:57: | oc1:y_34 | 0.8 | None | 2 | float | INFO - 16:25:57: | oc2:y_34 | 0.8 | None | 2 | float | INFO - 16:25:57: +----------+-------------+-------+-------------+-------+ INFO - 16:25:57: Solving optimization problem with algorithm LHS: INFO - 16:25:57: 5%|▌ | 1/20 [00:00<00:00, 174.40 it/sec, feas=True, obj=-437] INFO - 16:25:57: 10%|█ | 2/20 [00:00<00:00, 313.53 it/sec, feas=True, obj=-540] INFO - 16:25:57: 15%|█▌ | 3/20 [00:00<00:00, 430.46 it/sec, feas=True, obj=-342] INFO - 16:25:57: 20%|██ | 4/20 [00:00<00:00, 530.57 it/sec, feas=True, obj=-561] INFO - 16:25:57: 25%|██▌ | 5/20 [00:00<00:00, 619.89 it/sec, feas=True, obj=-422] INFO - 16:25:57: 30%|███ | 6/20 [00:00<00:00, 697.02 it/sec, feas=True, obj=-394] INFO - 16:25:57: 35%|███▌ | 7/20 [00:00<00:00, 766.60 it/sec, feas=True, obj=-332] INFO - 16:25:57: 40%|████ | 8/20 [00:00<00:00, 827.61 it/sec, feas=True, obj=-450] INFO - 16:25:57: 45%|████▌ | 9/20 [00:00<00:00, 884.02 it/sec, feas=True, obj=-496] INFO - 16:25:57: 50%|█████ | 10/20 [00:00<00:00, 932.96 it/sec, feas=True, obj=-535] INFO - 16:25:57: 55%|█████▌ | 11/20 [00:00<00:00, 977.88 it/sec, feas=True, obj=-359] INFO - 16:25:57: 60%|██████ | 12/20 [00:00<00:00, 1017.95 it/sec, feas=True, obj=-679] INFO - 16:25:57: 65%|██████▌ | 13/20 [00:00<00:00, 1056.87 it/sec, feas=True, obj=-452] INFO - 16:25:57: 70%|███████ | 14/20 [00:00<00:00, 1091.37 it/sec, feas=True, obj=-390] INFO - 16:25:57: 75%|███████▌ | 15/20 [00:00<00:00, 1125.46 it/sec, feas=True, obj=-307] INFO - 16:25:57: 80%|████████ | 16/20 [00:00<00:00, 1155.44 it/sec, feas=True, obj=-451] INFO - 16:25:57: 85%|████████▌ | 17/20 [00:00<00:00, 1174.00 it/sec, feas=True, obj=-370] INFO - 16:25:57: 90%|█████████ | 18/20 [00:00<00:00, 1197.61 it/sec, feas=True, obj=-492] INFO - 16:25:57: 95%|█████████▌| 19/20 [00:00<00:00, 1219.87 it/sec, feas=True, obj=-373] INFO - 16:25:57: 100%|██████████| 20/20 [00:00<00:00, 1236.31 it/sec, feas=True, obj=-679] INFO - 16:25:57: Optimization result: INFO - 16:25:57: Optimizer info: INFO - 16:25:57: Status: None INFO - 16:25:57: Message: None INFO - 16:25:57: Solution: INFO - 16:25:57: Objective: -679.194677915797 INFO - 16:25:57: Design space: INFO - 16:25:57: +----------+-------------+--------------------+-------------+-------+ INFO - 16:25:57: | Name | Lower bound | Value | Upper bound | Type | INFO - 16:25:57: +----------+-------------+--------------------+-------------+-------+ INFO - 16:25:57: | oc1:y_34 | 0.8 | 0.830888541534102 | 2 | float | INFO - 16:25:57: | oc2:y_34 | 0.8 | 0.9211557680119258 | 2 | float | INFO - 16:25:57: +----------+-------------+--------------------+-------------+-------+ INFO - 16:25:57: *** End DOEScenario execution (time: 0:00:00.018701) *** .. GENERATED FROM PYTHON SOURCE LINES 109-111 Plot the optimization history view ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. GENERATED FROM PYTHON SOURCE LINES 111-112 .. code-block:: Python scenario.post_process(post_name="OptHistoryView", save=False, show=True) .. rst-class:: sphx-glr-horizontal * .. image-sg:: /examples/namespaces/images/sphx_glr_plot_sobieski_namespaces_example_001.png :alt: Evolution of the optimization variables :srcset: /examples/namespaces/images/sphx_glr_plot_sobieski_namespaces_example_001.png :class: sphx-glr-multi-img * .. image-sg:: /examples/namespaces/images/sphx_glr_plot_sobieski_namespaces_example_002.png :alt: Evolution of the objective value :srcset: /examples/namespaces/images/sphx_glr_plot_sobieski_namespaces_example_002.png :class: sphx-glr-multi-img * .. image-sg:: /examples/namespaces/images/sphx_glr_plot_sobieski_namespaces_example_003.png :alt: Evolution of the distance to the optimum :srcset: /examples/namespaces/images/sphx_glr_plot_sobieski_namespaces_example_003.png :class: sphx-glr-multi-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.277 seconds) .. _sphx_glr_download_examples_namespaces_plot_sobieski_namespaces_example.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_sobieski_namespaces_example.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_sobieski_namespaces_example.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_sobieski_namespaces_example.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_