.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/mdo/plot_opt_as_mdo.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_mdo_plot_opt_as_mdo.py: Make a monodisciplinary optimization problem multidisciplinary ============================================================== Introduction ------------ The :class:`.OptAsMDOScenario` is a class to make a monodisciplinary optimization problem multidisciplinary :cite:`AzizAlaoui2025`. The only requirement is that the discipline has at least three scalar inputs and at least one output. This scenario can be used to enrich a catalog of benchmark MDO problems, based on the observation that MDO benchmark problems are far less numerous than optimization problems. This example illustrates it in the case of the minimization of the 3-dimensional Rosenbrock function .. math:: f(z) = 100(z_2-z_1^2)^2 + (1-z_1)^2 + 100(z_1-z_0^2)^2 + (1-z_0)^2 over the hypercube :math:`[-1,1]^3`. The unique solution of this minimization problem is the design point :math:`z^*=(1,1,1)` at which :math:`f` is zero. .. GENERATED FROM PYTHON SOURCE LINES 43-57 .. code-block:: Python from __future__ import annotations from numpy import array from gemseo import configure_logger from gemseo import create_design_space from gemseo import create_discipline from gemseo import create_scenario from gemseo import generate_coupling_graph from gemseo.problems.mdo.opt_as_mdo_scenario import OptAsMDOScenario configure_logger() .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 58-62 Material -------- First, we create the discipline implementing the Rosenbrock function: .. GENERATED FROM PYTHON SOURCE LINES 62-67 .. code-block:: Python discipline = create_discipline( "AnalyticDiscipline", expressions={"f": "100*(z_2-z_1**2)**2+(1-z_1)**2+100*(z_1-z_0**2)**2+(1-z_0)**2"}, name="Rosenbrock", ) .. GENERATED FROM PYTHON SOURCE LINES 68-69 as well as the design space: .. GENERATED FROM PYTHON SOURCE LINES 69-73 .. code-block:: Python design_space = create_design_space() design_space.add_variable("z_0", lower_bound=-1, upper_bound=1) design_space.add_variable("z_1", lower_bound=-1, upper_bound=1) design_space.add_variable("z_2", lower_bound=-1, upper_bound=1) .. GENERATED FROM PYTHON SOURCE LINES 74-76 and choose :math:`x^{(0)}=(-0.25, 0.75, -0.9)` as the starting point of the optimization: .. GENERATED FROM PYTHON SOURCE LINES 76-79 .. code-block:: Python initial_point = array([-0.25, 0.75, -0.9]) design_space.set_current_value(initial_point) .. GENERATED FROM PYTHON SOURCE LINES 80-84 Optimization problem -------------------- Then, we define the optimization problem: .. GENERATED FROM PYTHON SOURCE LINES 84-87 .. code-block:: Python opt_scenario = create_scenario( [discipline], "f", design_space, formulation_name="DisciplinaryOpt" ) .. GENERATED FROM PYTHON SOURCE LINES 88-89 and solve it using the SLSQP algorithm: .. GENERATED FROM PYTHON SOURCE LINES 89-90 .. code-block:: Python opt_scenario.execute(algo_name="NLOPT_SLSQP", max_iter=100) .. rst-class:: sphx-glr-script-out .. code-block:: none INFO - 20:38:26: *** Start MDOScenario execution *** INFO - 20:38:26: MDOScenario INFO - 20:38:26: Disciplines: Rosenbrock INFO - 20:38:26: MDO formulation: DisciplinaryOpt INFO - 20:38:26: Optimization problem: INFO - 20:38:26: minimize f(z_0, z_1, z_2) INFO - 20:38:26: with respect to z_0, z_1, z_2 INFO - 20:38:26: over the design space: INFO - 20:38:26: +------+-------------+-------+-------------+-------+ INFO - 20:38:26: | Name | Lower bound | Value | Upper bound | Type | INFO - 20:38:26: +------+-------------+-------+-------------+-------+ INFO - 20:38:26: | z_0 | -1 | -0.25 | 1 | float | INFO - 20:38:26: | z_1 | -1 | 0.75 | 1 | float | INFO - 20:38:26: | z_2 | -1 | -0.9 | 1 | float | INFO - 20:38:26: +------+-------------+-------+-------------+-------+ INFO - 20:38:26: Solving optimization problem with algorithm NLOPT_SLSQP: INFO - 20:38:26: 1%| | 1/100 [00:00<00:00, 404.78 it/sec, obj=263] INFO - 20:38:26: 2%|▏ | 2/100 [00:00<00:00, 568.95 it/sec, obj=408] INFO - 20:38:26: 3%|▎ | 3/100 [00:00<00:00, 815.33 it/sec, obj=20.2] INFO - 20:38:26: 4%|▍ | 4/100 [00:00<00:00, 824.84 it/sec, obj=168] INFO - 20:38:26: 5%|▌ | 5/100 [00:00<00:00, 1003.71 it/sec, obj=8.91] INFO - 20:38:26: 6%|▌ | 6/100 [00:00<00:00, 992.54 it/sec, obj=395] INFO - 20:38:26: 7%|▋ | 7/100 [00:00<00:00, 1133.29 it/sec, obj=4.06] INFO - 20:38:26: 8%|▊ | 8/100 [00:00<00:00, 1109.05 it/sec, obj=151] INFO - 20:38:26: 9%|▉ | 9/100 [00:00<00:00, 1226.17 it/sec, obj=3.31] INFO - 20:38:26: 10%|█ | 10/100 [00:00<00:00, 1183.66 it/sec, obj=2.09] INFO - 20:38:26: 11%|█ | 11/100 [00:00<00:00, 1218.95 it/sec, obj=2.02] INFO - 20:38:26: 12%|█▏ | 12/100 [00:00<00:00, 1254.43 it/sec, obj=1.97] INFO - 20:38:26: 13%|█▎ | 13/100 [00:00<00:00, 1283.63 it/sec, obj=1.92] INFO - 20:38:26: 14%|█▍ | 14/100 [00:00<00:00, 1311.22 it/sec, obj=1.85] INFO - 20:38:26: 15%|█▌ | 15/100 [00:00<00:00, 1336.62 it/sec, obj=1.73] INFO - 20:38:26: 16%|█▌ | 16/100 [00:00<00:00, 1358.78 it/sec, obj=1.3] INFO - 20:38:26: 17%|█▋ | 17/100 [00:00<00:00, 1378.53 it/sec, obj=0.995] INFO - 20:38:26: 18%|█▊ | 18/100 [00:00<00:00, 1396.50 it/sec, obj=0.721] INFO - 20:38:26: 19%|█▉ | 19/100 [00:00<00:00, 1416.59 it/sec, obj=0.625] INFO - 20:38:26: 20%|██ | 20/100 [00:00<00:00, 1438.87 it/sec, obj=6.19] INFO - 20:38:26: 21%|██ | 21/100 [00:00<00:00, 1498.20 it/sec, obj=0.491] INFO - 20:38:26: 22%|██▏ | 22/100 [00:00<00:00, 1461.75 it/sec, obj=5.86] INFO - 20:38:26: 23%|██▎ | 23/100 [00:00<00:00, 1515.62 it/sec, obj=0.403] INFO - 20:38:26: 24%|██▍ | 24/100 [00:00<00:00, 1482.00 it/sec, obj=0.87] INFO - 20:38:26: 25%|██▌ | 25/100 [00:00<00:00, 1532.00 it/sec, obj=0.279] INFO - 20:38:26: 26%|██▌ | 26/100 [00:00<00:00, 1494.46 it/sec, obj=0.243] INFO - 20:38:26: 27%|██▋ | 27/100 [00:00<00:00, 1509.04 it/sec, obj=0.244] INFO - 20:38:26: 28%|██▊ | 28/100 [00:00<00:00, 1554.60 it/sec, obj=0.224] INFO - 20:38:26: 29%|██▉ | 29/100 [00:00<00:00, 1519.62 it/sec, obj=0.171] INFO - 20:38:26: 30%|███ | 30/100 [00:00<00:00, 1534.30 it/sec, obj=0.276] INFO - 20:38:26: 31%|███ | 31/100 [00:00<00:00, 1574.46 it/sec, obj=0.117] INFO - 20:38:26: 32%|███▏ | 32/100 [00:00<00:00, 1539.99 it/sec, obj=0.0792] INFO - 20:38:26: 33%|███▎ | 33/100 [00:00<00:00, 1547.92 it/sec, obj=0.0624] INFO - 20:38:26: 34%|███▍ | 34/100 [00:00<00:00, 1554.24 it/sec, obj=0.0366] INFO - 20:38:26: 35%|███▌ | 35/100 [00:00<00:00, 1562.14 it/sec, obj=0.0298] INFO - 20:38:26: 36%|███▌ | 36/100 [00:00<00:00, 1568.60 it/sec, obj=0.0164] INFO - 20:38:26: 37%|███▋ | 37/100 [00:00<00:00, 1576.60 it/sec, obj=0.0103] INFO - 20:38:26: 38%|███▊ | 38/100 [00:00<00:00, 1583.07 it/sec, obj=0.00429] INFO - 20:38:26: 39%|███▉ | 39/100 [00:00<00:00, 1590.62 it/sec, obj=0.00128] INFO - 20:38:26: 40%|████ | 40/100 [00:00<00:00, 1596.69 it/sec, obj=0.000368] INFO - 20:38:26: 41%|████ | 41/100 [00:00<00:00, 1603.21 it/sec, obj=2.77e-5] INFO - 20:38:26: 42%|████▏ | 42/100 [00:00<00:00, 1607.34 it/sec, obj=6.38e-7] INFO - 20:38:26: 43%|████▎ | 43/100 [00:00<00:00, 1612.69 it/sec, obj=1.32e-9] INFO - 20:38:26: 44%|████▍ | 44/100 [00:00<00:00, 1618.53 it/sec, obj=9.1e-12] INFO - 20:38:26: 45%|████▌ | 45/100 [00:00<00:00, 1623.69 it/sec, obj=6.58e-14] INFO - 20:38:26: 46%|████▌ | 46/100 [00:00<00:00, 1629.56 it/sec, obj=1.58e-21] INFO - 20:38:26: 47%|████▋ | 47/100 [00:00<00:00, 1632.21 it/sec, obj=Not evaluated] INFO - 20:38:26: Optimization result: INFO - 20:38:26: Optimizer info: INFO - 20:38:26: Status: None INFO - 20:38:26: Message: Successive iterates of the design variables are closer than xtol_rel or xtol_abs. GEMSEO stopped the driver. INFO - 20:38:26: Number of calls to the objective function by the optimizer: 0 INFO - 20:38:26: Solution: INFO - 20:38:26: Objective: 1.584054020051718e-21 INFO - 20:38:26: Design space: INFO - 20:38:26: +------+-------------+--------------------+-------------+-------+ INFO - 20:38:26: | Name | Lower bound | Value | Upper bound | Type | INFO - 20:38:26: +------+-------------+--------------------+-------------+-------+ INFO - 20:38:26: | z_0 | -1 | 1 | 1 | float | INFO - 20:38:26: | z_1 | -1 | 0.9999999999996698 | 1 | float | INFO - 20:38:26: | z_2 | -1 | 0.9999999999953735 | 1 | float | INFO - 20:38:26: +------+-------------+--------------------+-------------+-------+ INFO - 20:38:26: *** End MDOScenario execution *** .. GENERATED FROM PYTHON SOURCE LINES 91-101 We can see that the numerical solution corresponds to the analytical one. MDO problem ----------- Now, we use the :class:`.OptAsMDOScenario` to rewrite this optimization problem as an MDO problem with two strongly coupled disciplines. First, we reset the design space to the initial point: .. GENERATED FROM PYTHON SOURCE LINES 101-102 .. code-block:: Python design_space.set_current_value(initial_point) .. GENERATED FROM PYTHON SOURCE LINES 103-105 and create the :class:`.OptAsMDOScenario`, orchestrated by an MDF formulation: .. GENERATED FROM PYTHON SOURCE LINES 105-106 .. code-block:: Python mdo_scenario = OptAsMDOScenario(discipline, "f", design_space, formulation_name="MDF") .. GENERATED FROM PYTHON SOURCE LINES 107-109 Then, we can see that the design variables have been renamed: .. GENERATED FROM PYTHON SOURCE LINES 109-110 .. code-block:: Python design_space .. raw:: html
Design space:
Name Lower bound Value Upper bound Type
x_0 -1 -0.25 1 float
x_1 -1 0.75 1 float
x_2 -1 -0.9 1 float


.. GENERATED FROM PYTHON SOURCE LINES 111-119 This renaming is based on the convention: - the first design variable is the global design variable and is named :math:`x_0`, - the :math:`(1+i)`-th design variable is the local design variable specific to the :math:`i`-th strongly coupled discipline and is named :math:`x_{1+i}`. We can also have a look to the coupling graph: .. GENERATED FROM PYTHON SOURCE LINES 119-120 .. code-block:: Python generate_coupling_graph(mdo_scenario.disciplines, file_path="") .. raw:: html
%3 L L Rosenbrock Rosenbrock L->Rosenbrock z_0, z_1, z_2 Rosenbrock->_Rosenbrock f D1 D1 D1->L y_1 D2 D2 D1->D2 y_1 D2->L y_2 D2->D1 y_2


.. GENERATED FROM PYTHON SOURCE LINES 121-131 and see that there are two strongly coupled disciplines :math:`D_1` and :math:`D_2`, connected by the coupling variables :math:`y_1` and :math:`y_2`. These disciplines are weakly coupled to a downstream link discipline :math:`L`, which is weakly coupled to the downstream original discipline. Let us note that the link discipline computes the values of the design variables in the original optimization problem from the values of the design and coupling variables in the MDO problem. Lastly, we solve this scenario using the SLSQP algorithm: .. GENERATED FROM PYTHON SOURCE LINES 131-133 .. code-block:: Python mdo_scenario.set_differentiation_method(method="finite_differences") mdo_scenario.execute(algo_name="NLOPT_SLSQP", max_iter=100) .. rst-class:: sphx-glr-script-out .. code-block:: none INFO - 20:38:26: *** Start OptAsMDOScenario execution *** INFO - 20:38:26: OptAsMDOScenario INFO - 20:38:26: Disciplines: D1 D2 L Rosenbrock INFO - 20:38:26: MDO formulation: MDF INFO - 20:38:26: Optimization problem: INFO - 20:38:26: minimize f(x_0, x_1, x_2) INFO - 20:38:26: with respect to x_0, x_1, x_2 INFO - 20:38:26: over the design space: INFO - 20:38:26: +------+-------------+-------+-------------+-------+ INFO - 20:38:26: | Name | Lower bound | Value | Upper bound | Type | INFO - 20:38:26: +------+-------------+-------+-------------+-------+ INFO - 20:38:26: | x_0 | -1 | -0.25 | 1 | float | INFO - 20:38:26: | x_1 | -1 | 0.75 | 1 | float | INFO - 20:38:26: | x_2 | -1 | -0.9 | 1 | float | INFO - 20:38:26: +------+-------------+-------+-------------+-------+ INFO - 20:38:26: Solving optimization problem with algorithm NLOPT_SLSQP: INFO - 20:38:26: 1%| | 1/100 [00:00<00:00, 104.55 it/sec, obj=263] INFO - 20:38:26: 2%|▏ | 2/100 [00:00<00:01, 64.44 it/sec, obj=408] INFO - 20:38:26: 3%|▎ | 3/100 [00:00<00:01, 95.89 it/sec, obj=20.2] WARNING - 20:38:26: All components of the normalized vector should be between 0 and 1; upper bounds violated: [1.000001]. WARNING - 20:38:26: All components of the normalized vector should be between 0 and 1; upper bounds violated: [1.000001]. INFO - 20:38:26: 4%|▍ | 4/100 [00:00<00:01, 76.31 it/sec, obj=168] INFO - 20:38:26: 5%|▌ | 5/100 [00:00<00:01, 94.96 it/sec, obj=8.91] INFO - 20:38:26: 6%|▌ | 6/100 [00:00<00:01, 81.98 it/sec, obj=395] INFO - 20:38:26: 7%|▋ | 7/100 [00:00<00:00, 95.32 it/sec, obj=4.06] WARNING - 20:38:26: All components of the normalized vector should be between 0 and 1; upper bounds violated: [1.000001]. INFO - 20:38:26: 8%|▊ | 8/100 [00:00<00:01, 84.14 it/sec, obj=151] INFO - 20:38:26: 9%|▉ | 9/100 [00:00<00:00, 94.41 it/sec, obj=3.31] INFO - 20:38:26: 10%|█ | 10/100 [00:00<00:01, 81.29 it/sec, obj=2.09] INFO - 20:38:26: 11%|█ | 11/100 [00:00<00:01, 81.71 it/sec, obj=2.02] INFO - 20:38:26: 12%|█▏ | 12/100 [00:00<00:01, 81.63 it/sec, obj=1.97] INFO - 20:38:26: 13%|█▎ | 13/100 [00:00<00:01, 82.17 it/sec, obj=1.92] INFO - 20:38:26: 14%|█▍ | 14/100 [00:00<00:01, 82.54 it/sec, obj=1.85] INFO - 20:38:26: 15%|█▌ | 15/100 [00:00<00:01, 82.49 it/sec, obj=1.73] INFO - 20:38:26: 16%|█▌ | 16/100 [00:00<00:01, 82.67 it/sec, obj=1.3] INFO - 20:38:26: 17%|█▋ | 17/100 [00:00<00:01, 82.81 it/sec, obj=0.996] INFO - 20:38:26: 18%|█▊ | 18/100 [00:00<00:00, 82.94 it/sec, obj=0.721] WARNING - 20:38:26: All components of the normalized vector should be between 0 and 1; upper bounds violated: [1.000001]. INFO - 20:38:26: 19%|█▉ | 19/100 [00:00<00:00, 83.03 it/sec, obj=0.6] INFO - 20:38:26: 20%|██ | 20/100 [00:00<00:00, 85.55 it/sec, obj=6.26] INFO - 20:38:26: 21%|██ | 21/100 [00:00<00:00, 89.75 it/sec, obj=0.473] INFO - 20:38:26: 22%|██▏ | 22/100 [00:00<00:00, 86.48 it/sec, obj=6.1] INFO - 20:38:26: 23%|██▎ | 23/100 [00:00<00:00, 90.32 it/sec, obj=0.394] INFO - 20:38:26: 24%|██▍ | 24/100 [00:00<00:00, 86.94 it/sec, obj=0.665] INFO - 20:38:26: 25%|██▌ | 25/100 [00:00<00:00, 90.48 it/sec, obj=0.28] INFO - 20:38:26: 26%|██▌ | 26/100 [00:00<00:00, 85.46 it/sec, obj=0.242] INFO - 20:38:26: 27%|██▋ | 27/100 [00:00<00:00, 85.54 it/sec, obj=0.207] INFO - 20:38:26: 28%|██▊ | 28/100 [00:00<00:00, 85.56 it/sec, obj=0.142] INFO - 20:38:26: 29%|██▉ | 29/100 [00:00<00:00, 85.59 it/sec, obj=0.091] INFO - 20:38:26: 30%|███ | 30/100 [00:00<00:00, 85.57 it/sec, obj=0.0673] INFO - 20:38:26: 31%|███ | 31/100 [00:00<00:00, 85.44 it/sec, obj=0.0512] INFO - 20:38:26: 32%|███▏ | 32/100 [00:00<00:00, 85.36 it/sec, obj=0.029] INFO - 20:38:26: 33%|███▎ | 33/100 [00:00<00:00, 85.45 it/sec, obj=0.0164] INFO - 20:38:26: 34%|███▍ | 34/100 [00:00<00:00, 85.41 it/sec, obj=0.00786] INFO - 20:38:26: 35%|███▌ | 35/100 [00:00<00:00, 85.28 it/sec, obj=0.00314] INFO - 20:38:26: 36%|███▌ | 36/100 [00:00<00:00, 85.22 it/sec, obj=0.00103] INFO - 20:38:26: 37%|███▋ | 37/100 [00:00<00:00, 85.15 it/sec, obj=0.000147] INFO - 20:38:26: 38%|███▊ | 38/100 [00:00<00:00, 85.08 it/sec, obj=1.19e-5] INFO - 20:38:26: 39%|███▉ | 39/100 [00:00<00:00, 85.11 it/sec, obj=9.5e-7] INFO - 20:38:26: 40%|████ | 40/100 [00:00<00:00, 85.08 it/sec, obj=6.41e-7] INFO - 20:38:26: 41%|████ | 41/100 [00:00<00:00, 86.24 it/sec, obj=6.45e-7] INFO - 20:38:26: 42%|████▏ | 42/100 [00:00<00:00, 88.30 it/sec, obj=6.41e-7] INFO - 20:38:26: 43%|████▎ | 43/100 [00:00<00:00, 89.87 it/sec, obj=6.41e-7] INFO - 20:38:26: 44%|████▍ | 44/100 [00:00<00:00, 91.41 it/sec, obj=6.41e-7] INFO - 20:38:26: 45%|████▌ | 45/100 [00:00<00:00, 92.94 it/sec, obj=6.41e-7] INFO - 20:38:26: 46%|████▌ | 46/100 [00:00<00:00, 94.46 it/sec, obj=6.41e-7] INFO - 20:38:26: 47%|████▋ | 47/100 [00:00<00:00, 95.96 it/sec, obj=6.41e-7] INFO - 20:38:26: 48%|████▊ | 48/100 [00:00<00:00, 97.45 it/sec, obj=6.41e-7] INFO - 20:38:26: 49%|████▉ | 49/100 [00:00<00:00, 98.89 it/sec, obj=6.41e-7] INFO - 20:38:26: Optimization result: INFO - 20:38:26: Optimizer info: INFO - 20:38:26: Status: None INFO - 20:38:26: Message: Successive iterates of the design variables are closer than xtol_rel or xtol_abs. GEMSEO stopped the driver. INFO - 20:38:26: Number of calls to the objective function by the optimizer: 0 INFO - 20:38:26: Solution: INFO - 20:38:26: Objective: 6.40943911289712e-07 INFO - 20:38:26: Design space: INFO - 20:38:26: +------+-------------+--------------------+-------------+-------+ INFO - 20:38:26: | Name | Lower bound | Value | Upper bound | Type | INFO - 20:38:26: +------+-------------+--------------------+-------------+-------+ INFO - 20:38:26: | x_0 | -1 | 0.9996445136827841 | 1 | float | INFO - 20:38:26: | x_1 | -1 | 0.999284303839403 | 1 | float | INFO - 20:38:26: | x_2 | -1 | 0.9985690703536887 | 1 | float | INFO - 20:38:26: +------+-------------+--------------------+-------------+-------+ INFO - 20:38:26: *** End OptAsMDOScenario execution *** .. GENERATED FROM PYTHON SOURCE LINES 134-135 We can see that the numerical solution corresponds to the analytical one. .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.852 seconds) .. _sphx_glr_download_examples_mdo_plot_opt_as_mdo.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_opt_as_mdo.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_opt_as_mdo.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_opt_as_mdo.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_