.. 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-33 .. code-block:: Python from __future__ import annotations from gemseo import configure_logger from gemseo import create_design_space from gemseo import create_discipline from gemseo import create_scenario configure_logger() .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 34-40 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 42-48 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 48-50 .. code-block:: Python disciplines = create_discipline(["SobieskiMission", "SobieskiMission"]) .. GENERATED FROM PYTHON SOURCE LINES 51-59 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 59-65 .. 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 66-71 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 71-80 .. 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 81-85 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 85-89 .. 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 90-93 Instantiate the scenario ^^^^^^^^^^^^^^^^^^^^^^^^ The objective is the averaged range. .. GENERATED FROM PYTHON SOURCE LINES 93-101 .. 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 102-106 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 106-110 .. 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 - 20:39:19: *** Start DOEScenario execution *** INFO - 20:39:19: DOEScenario INFO - 20:39:19: Disciplines: LinearCombination SobieskiMission SobieskiMission INFO - 20:39:19: MDO formulation: MDF INFO - 20:39:19: Optimization problem: INFO - 20:39:19: minimize -average_y_4(oc1:y_34, oc2:y_34) INFO - 20:39:19: with respect to oc1:y_34, oc2:y_34 INFO - 20:39:19: over the design space: INFO - 20:39:19: +----------+-------------+-------+-------------+-------+ INFO - 20:39:19: | Name | Lower bound | Value | Upper bound | Type | INFO - 20:39:19: +----------+-------------+-------+-------------+-------+ INFO - 20:39:19: | oc1:y_34 | 0.8 | None | 2 | float | INFO - 20:39:19: | oc2:y_34 | 0.8 | None | 2 | float | INFO - 20:39:19: +----------+-------------+-------+-------------+-------+ INFO - 20:39:19: Solving optimization problem with algorithm LHS: INFO - 20:39:19: 5%|▌ | 1/20 [00:00<00:00, 158.46 it/sec, obj=-437] INFO - 20:39:19: 10%|█ | 2/20 [00:00<00:00, 281.92 it/sec, obj=-540] INFO - 20:39:19: 15%|█▌ | 3/20 [00:00<00:00, 392.64 it/sec, obj=-342] INFO - 20:39:19: 20%|██ | 4/20 [00:00<00:00, 489.90 it/sec, obj=-561] INFO - 20:39:19: 25%|██▌ | 5/20 [00:00<00:00, 577.20 it/sec, obj=-422] INFO - 20:39:19: 30%|███ | 6/20 [00:00<00:00, 652.98 it/sec, obj=-394] INFO - 20:39:19: 35%|███▌ | 7/20 [00:00<00:00, 722.92 it/sec, obj=-332] INFO - 20:39:19: 40%|████ | 8/20 [00:00<00:00, 784.28 it/sec, obj=-450] INFO - 20:39:19: 45%|████▌ | 9/20 [00:00<00:00, 841.55 it/sec, obj=-496] INFO - 20:39:19: 50%|█████ | 10/20 [00:00<00:00, 893.05 it/sec, obj=-535] INFO - 20:39:19: 55%|█████▌ | 11/20 [00:00<00:00, 941.85 it/sec, obj=-359] INFO - 20:39:19: 60%|██████ | 12/20 [00:00<00:00, 985.83 it/sec, obj=-679] INFO - 20:39:19: 65%|██████▌ | 13/20 [00:00<00:00, 1027.55 it/sec, obj=-452] INFO - 20:39:19: 70%|███████ | 14/20 [00:00<00:00, 1064.80 it/sec, obj=-390] INFO - 20:39:19: 75%|███████▌ | 15/20 [00:00<00:00, 1100.37 it/sec, obj=-307] INFO - 20:39:19: 80%|████████ | 16/20 [00:00<00:00, 1131.13 it/sec, obj=-451] INFO - 20:39:19: 85%|████████▌ | 17/20 [00:00<00:00, 1142.48 it/sec, obj=-370] INFO - 20:39:19: 90%|█████████ | 18/20 [00:00<00:00, 1169.02 it/sec, obj=-492] INFO - 20:39:19: 95%|█████████▌| 19/20 [00:00<00:00, 1194.12 it/sec, obj=-373] INFO - 20:39:19: 100%|██████████| 20/20 [00:00<00:00, 1219.45 it/sec, obj=-679] INFO - 20:39:19: Optimization result: INFO - 20:39:19: Optimizer info: INFO - 20:39:19: Status: None INFO - 20:39:19: Message: None INFO - 20:39:19: Number of calls to the objective function by the optimizer: 0 INFO - 20:39:19: Solution: INFO - 20:39:19: Objective: -679.194677915797 INFO - 20:39:19: Design space: INFO - 20:39:19: +----------+-------------+--------------------+-------------+-------+ INFO - 20:39:19: | Name | Lower bound | Value | Upper bound | Type | INFO - 20:39:19: +----------+-------------+--------------------+-------------+-------+ INFO - 20:39:19: | oc1:y_34 | 0.8 | 0.830888541534102 | 2 | float | INFO - 20:39:19: | oc2:y_34 | 0.8 | 0.9211557680119258 | 2 | float | INFO - 20:39:19: +----------+-------------+--------------------+-------------+-------+ INFO - 20:39:19: *** End DOEScenario execution (time: 0:00:00.019148) *** .. GENERATED FROM PYTHON SOURCE LINES 111-113 Plot the optimization history view ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. GENERATED FROM PYTHON SOURCE LINES 113-114 .. 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.302 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 `_