.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/scalable/scalable_tm.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_scalable_scalable_tm.py: Scalable problem of Tedford and Martins, 2010 ============================================= .. GENERATED FROM PYTHON SOURCE LINES 26-43 .. code-block:: default from __future__ import annotations from gemseo.api import configure_logger from gemseo.api import generate_n2_plot from gemseo.problems.scalable.parametric.core.design_space import TMDesignSpace from gemseo.problems.scalable.parametric.disciplines import TMMainDiscipline from gemseo.problems.scalable.parametric.disciplines import TMSubDiscipline from gemseo.problems.scalable.parametric.problem import TMScalableProblem from gemseo.problems.scalable.parametric.study import TMParamSS from gemseo.problems.scalable.parametric.study import TMParamSSPost from gemseo.problems.scalable.parametric.study import TMScalableStudy from numpy import array from numpy.random import rand configure_logger() .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 44-54 Disciplines ----------- We define two strongly coupled disciplines and a weakly coupled discipline, with: - 2 shared design parameters, - 2 local design parameters for the first discipline, - 3 local design parameters for the second discipline, - 3 coupling variables for the first discipline, - 2 coupling variables for the second discipline. .. GENERATED FROM PYTHON SOURCE LINES 54-57 .. code-block:: default sizes = {"x_shared": 2, "x_local_0": 2, "x_local_1": 3, "y_0": 3, "y_1": 2} .. GENERATED FROM PYTHON SOURCE LINES 58-64 We use any values for the coefficients and the default values of the design parameters and coupling variables. Strongly coupled disciplines ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Here is the first strongly coupled discipline. .. GENERATED FROM PYTHON SOURCE LINES 64-79 .. code-block:: default default_inputs = { "x_shared": rand(sizes["x_shared"]), "x_local_0": rand(sizes["x_local_0"]), "y_1": rand(sizes["y_1"]), } index = 0 c_shared = rand(sizes["y_0"], sizes["x_shared"]) c_local = rand(sizes["y_0"], sizes["x_local_0"]) c_coupling = {"y_1": rand(sizes["y_0"], sizes["y_1"])} disc0 = TMSubDiscipline(index, c_shared, c_local, c_coupling, default_inputs) print(disc0.name) print(disc0.get_input_data_names()) print(disc0.get_output_data_names()) .. rst-class:: sphx-glr-script-out .. code-block:: none SubModel_0 ['x_local_0', 'x_shared', 'y_1'] ['y_0'] .. GENERATED FROM PYTHON SOURCE LINES 80-85 .. code-block:: console TM_Discipline_0 dict_keys(['x_shared', 'x_local_0', 'y_1']) dict_keys(['y_0']) .. GENERATED FROM PYTHON SOURCE LINES 88-89 Here is the second one, strongly coupled with the first one. .. GENERATED FROM PYTHON SOURCE LINES 89-104 .. code-block:: default default_inputs = { "x_shared": rand(sizes["x_shared"]), "x_local_1": rand(sizes["x_local_1"]), "y_0": rand(sizes["y_0"]), } index = 1 c_shared = rand(sizes["y_1"], sizes["x_shared"]) c_local = rand(sizes["y_1"], sizes["x_local_1"]) c_coupling = {"y_0": rand(sizes["y_1"], sizes["y_0"])} disc1 = TMSubDiscipline(index, c_shared, c_local, c_coupling, default_inputs) print(disc1.name) print(disc1.get_input_data_names()) print(disc1.get_output_data_names()) .. rst-class:: sphx-glr-script-out .. code-block:: none SubModel_1 ['x_local_1', 'x_shared', 'y_0'] ['y_1'] .. GENERATED FROM PYTHON SOURCE LINES 105-110 .. code-block:: console TM_Discipline_1 dict_keys(['x_shared', 'x_local_1', 'y_0']) dict_keys(['y_1']) .. GENERATED FROM PYTHON SOURCE LINES 112-115 Weakly coupled discipline ^^^^^^^^^^^^^^^^^^^^^^^^^ Here is the discipline weakly coupled to the previous ones. .. GENERATED FROM PYTHON SOURCE LINES 115-127 .. code-block:: default c_constraint = [array([1.0, 2.0]), array([3.0, 4.0, 5.0])] default_inputs = { "x_shared": array([0.5]), "y_0": array([2.0, 3.0]), "y_1": array([4.0, 5.0, 6.0]), } system = TMMainDiscipline(c_constraint, default_inputs) print(system.name) print(system.get_input_data_names()) print(system.get_output_data_names()) .. rst-class:: sphx-glr-script-out .. code-block:: none MainModel ['x_shared', 'y_0', 'y_1'] ['cstr_0', 'cstr_1', 'obj'] .. GENERATED FROM PYTHON SOURCE LINES 128-133 .. code-block:: console TM_System dict_keys(['x_shared', 'y_0', 'y_1']) dict_keys(['obj', 'cstr_0', 'cstr_1']) .. GENERATED FROM PYTHON SOURCE LINES 135-138 Coupling chart ^^^^^^^^^^^^^^ We can represent these three disciplines by means of an N2 chart. .. GENERATED FROM PYTHON SOURCE LINES 138-140 .. code-block:: default generate_n2_plot([disc0, disc1, system], save=False, show=True) .. image-sg:: /examples/scalable/images/sphx_glr_scalable_tm_001.png :alt: scalable tm :srcset: /examples/scalable/images/sphx_glr_scalable_tm_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 141-142 .. image:: /_images/scalable_tm/N2chart.png .. GENERATED FROM PYTHON SOURCE LINES 144-148 Design space ------------ We define the design space from the sizes of the shared design parameters, local parameters and coupling variables. .. GENERATED FROM PYTHON SOURCE LINES 148-155 .. code-block:: default n_shared = sizes["x_shared"] n_local = [sizes["x_local_0"], sizes["x_local_1"]] n_coupling = [sizes["y_0"], sizes["y_1"]] design_space = TMDesignSpace(n_shared, n_local, n_coupling) print(design_space) .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 156-175 .. code-block:: console Design Space: +-----------+-------------+-------+-------------+-------+ | name | lower_bound | value | upper_bound | type | +-----------+-------------+-------+-------------+-------+ | x_local_0 | 0 | 0.5 | 1 | float | | x_local_0 | 0 | 0.5 | 1 | float | | x_local_1 | 0 | 0.5 | 1 | float | | x_local_1 | 0 | 0.5 | 1 | float | | x_local_1 | 0 | 0.5 | 1 | float | | x_shared | 0 | 0.5 | 1 | float | | x_shared | 0 | 0.5 | 1 | float | | y_0 | 0 | 0.5 | 1 | float | | y_0 | 0 | 0.5 | 1 | float | | y_0 | 0 | 0.5 | 1 | float | | y_1 | 0 | 0.5 | 1 | float | | y_1 | 0 | 0.5 | 1 | float | +-----------+-------------+-------+-------------+-------+ .. GENERATED FROM PYTHON SOURCE LINES 177-187 Scalable problem ---------------- We define a scalable problem based on two strongly coupled disciplines and a weakly one, with the following properties: - 3 shared design parameters, - 2 local design parameters for the first strongly coupled discipline, - 2 coupling variables for the first strongly coupled discipline, - 4 local design parameters for the second strongly coupled discipline, - 3 coupling variables for the second strongly coupled discipline. .. GENERATED FROM PYTHON SOURCE LINES 187-195 .. code-block:: default problem = TMScalableProblem(3, [2, 4], [2, 3]) print(problem) print(problem.get_design_space()) print(problem.get_default_inputs()) .. rst-class:: sphx-glr-script-out .. code-block:: none Scalable problem .... MainModel ........ Inputs: ............ x_shared (3) ............ y_0 (2) ............ y_1 (3) ........ Outputs: ............ cstr_0 (2) ............ cstr_1 (3) ............ obj (1) .... SubModel_0 ........ Inputs: ............ x_local_0 (2) ............ x_shared (3) ............ y_1 (3) ........ Outputs: ............ y_0 (2) .... SubModel_1 ........ Inputs: ............ x_local_1 (4) ............ x_shared (3) ............ y_0 (2) ........ Outputs: ............ y_1 (3) +------------------------------------------------------------------------------+ | Parameter space | +-----------+-------------+-------+-------------+-------+----------------------+ | name | lower_bound | value | upper_bound | type | Initial distribution | +-----------+-------------+-------+-------------+-------+----------------------+ | x_local_0 | 0 | 0.5 | 1 | float | | | x_local_0 | 0 | 0.5 | 1 | float | | | x_local_1 | 0 | 0.5 | 1 | float | | | x_local_1 | 0 | 0.5 | 1 | float | | | x_local_1 | 0 | 0.5 | 1 | float | | | x_local_1 | 0 | 0.5 | 1 | float | | | x_shared | 0 | 0.5 | 1 | float | | | x_shared | 0 | 0.5 | 1 | float | | | x_shared | 0 | 0.5 | 1 | float | | | y_0 | 0 | 0.5 | 1 | float | | | y_0 | 0 | 0.5 | 1 | float | | | y_1 | 0 | 0.5 | 1 | float | | | y_1 | 0 | 0.5 | 1 | float | | | y_1 | 0 | 0.5 | 1 | float | | +-----------+-------------+-------+-------------+-------+----------------------+ {'x_shared': array([0.5, 0.5, 0.5]), 'x_local_0': array([0.5, 0.5]), 'y_0': array([0.5, 0.5]), 'cstr_0': array([0.5, 0.5]), 'u_local_0': array([0., 0.]), 'x_local_1': array([0.5, 0.5, 0.5, 0.5]), 'y_1': array([0.5, 0.5, 0.5]), 'cstr_1': array([0.5, 0.5, 0.5]), 'u_local_1': array([0., 0., 0.])} .. GENERATED FROM PYTHON SOURCE LINES 196-246 .. code-block:: console Scalable problem > TM_System >> Inputs: | x_shared (3) | y_0 (2) | y_1 (3) >> Outputs: | cstr_0 (2) | cstr_1 (3) | obj (1) > TM_Discipline_0 >> Inputs: | x_local_0 (2) | x_shared (3) | y_1 (3) >> Outputs: | y_0 (2) > TM_Discipline_1 >> Inputs: | x_local_1 (4) | x_shared (3) | y_0 (2) >> Outputs: | y_1 (3) Design Space: +-----------+-------------+-------+-------------+-------+ | name | lower_bound | value | upper_bound | type | +-----------+-------------+-------+-------------+-------+ | x_local_0 | 0 | 0.5 | 1 | float | | x_local_0 | 0 | 0.5 | 1 | float | | x_local_1 | 0 | 0.5 | 1 | float | | x_local_1 | 0 | 0.5 | 1 | float | | x_local_1 | 0 | 0.5 | 1 | float | | x_local_1 | 0 | 0.5 | 1 | float | | x_shared | 0 | 0.5 | 1 | float | | x_shared | 0 | 0.5 | 1 | float | | x_shared | 0 | 0.5 | 1 | float | | y_0 | 0 | 0.5 | 1 | float | | y_0 | 0 | 0.5 | 1 | float | | y_1 | 0 | 0.5 | 1 | float | | y_1 | 0 | 0.5 | 1 | float | | y_1 | 0 | 0.5 | 1 | float | +-----------+-------------+-------+-------------+-------+ {'x_shared': array([0.5, 0.5, 0.5]), 'x_local_0': array([0.5, 0.5]), 'y_0': array([0.5, 0.5]), 'cstr_0': array([0.5]), 'x_local_1': array([0.5, 0.5, 0.5, 0.5]), 'y_1': array([0.5, 0.5, 0.5]), 'cstr_1': array([0.5])} .. GENERATED FROM PYTHON SOURCE LINES 248-256 Scalable study -------------- We define a scalable study based on two strongly coupled disciplines and a weakly one, with the following properties: - 3 shared design parameters, - 2 local design parameters for each strongly coupled discipline, - 3 coupling variables for each strongly coupled discipline. .. GENERATED FROM PYTHON SOURCE LINES 256-259 .. code-block:: default study = TMScalableStudy(n_disciplines=2, n_shared=3, n_local=2, n_coupling=3) print(study) .. rst-class:: sphx-glr-script-out .. code-block:: none Scalable study .... 2 disciplines .... 3 shared design parameters .... 2 local design parameters per discipline .... 3 coupling variables per discipline .. GENERATED FROM PYTHON SOURCE LINES 260-267 .. code-block:: console Scalable study > 2 disciplines > 3 shared design parameters > 2 local design parameters per discipline > 3 coupling variables per discipline .. GENERATED FROM PYTHON SOURCE LINES 269-270 Then, we run MDF and IDF formulations: .. GENERATED FROM PYTHON SOURCE LINES 270-273 .. code-block:: default study.run_formulation("MDF") study.run_formulation("IDF") .. rst-class:: sphx-glr-horizontal * .. image-sg:: /examples/scalable/images/sphx_glr_scalable_tm_002.png :alt: scalable tm :srcset: /examples/scalable/images/sphx_glr_scalable_tm_002.png :class: sphx-glr-multi-img * .. image-sg:: /examples/scalable/images/sphx_glr_scalable_tm_003.png :alt: scalable tm :srcset: /examples/scalable/images/sphx_glr_scalable_tm_003.png :class: sphx-glr-multi-img .. rst-class:: sphx-glr-script-out .. code-block:: none INFO - 16:56:41: Make the starting point feasible. INFO - 16:56:41: INFO - 16:56:41: *** Start MDOScenario execution *** INFO - 16:56:41: MDOScenario INFO - 16:56:41: Disciplines: MainModel SubModel_0 SubModel_1 INFO - 16:56:41: MDO formulation: MDF INFO - 16:56:41: Optimization problem: INFO - 16:56:41: minimize obj(x_local_0, x_local_1, x_shared) INFO - 16:56:41: with respect to x_local_0, x_local_1, x_shared INFO - 16:56:41: subject to constraints: INFO - 16:56:41: cstr_0(x_local_0, x_local_1, x_shared) <= [ 0.65250671 -2.8453087 -4.16343355] INFO - 16:56:41: cstr_1(x_local_0, x_local_1, x_shared) <= [0.85268891 0.52747299 0.62341835] INFO - 16:56:41: over the design space: INFO - 16:56:41: | Parameter space | INFO - 16:56:41: +-----------+-------------+-------+-------------+-------+----------------------+ INFO - 16:56:41: | name | lower_bound | value | upper_bound | type | Initial distribution | INFO - 16:56:41: +-----------+-------------+-------+-------------+-------+----------------------+ INFO - 16:56:41: | x_local_0 | 0 | 0.5 | 1 | float | | INFO - 16:56:41: | x_local_0 | 0 | 0.5 | 1 | float | | INFO - 16:56:41: | x_local_1 | 0 | 0.5 | 1 | float | | INFO - 16:56:41: | x_local_1 | 0 | 0.5 | 1 | float | | INFO - 16:56:41: | x_shared | 0 | 0.5 | 1 | float | | INFO - 16:56:41: | x_shared | 0 | 0.5 | 1 | float | | INFO - 16:56:41: | x_shared | 0 | 0.5 | 1 | float | | INFO - 16:56:41: +-----------+-------------+-------+-------------+-------+----------------------+ INFO - 16:56:41: Solving optimization problem with algorithm NLOPT_SLSQP: INFO - 16:56:41: ... 0%| | 0/100 [00:00 2 disciplines > 3 shared design parameters > 2 local design parameters per discipline > 3 coupling variables per discipline MDO formulations > MDF >> TM_System = 9 calls / 7 linearizations / 3.29e-03 seconds >> TM_Discipline_0 = 132 calls / 7 linearizations / 2.19e-02 seconds >> TM_Discipline_1 = 124 calls / 7 linearizations / 2.04e-02 seconds >> mda = 7 calls / 7 linearizations / 2.68e-01 seconds >> mdo_chain = 7 calls / 0 linearizations / 1.20e-01 seconds >> sub_mda = 7 calls / 0 linearizations / 1.16e-01 seconds >> scenario = 1 calls / 0 linearizations / 3.35e-01 seconds > IDF >> TM_System = 12 calls / 9 linearizations / 2.98e-03 seconds >> TM_Discipline_0 = 12 calls / 9 linearizations / 2.19e-03 seconds >> TM_Discipline_1 = 11 calls / 9 linearizations / 2.01e-03 seconds >> mda = 0 calls / 0 linearizations / 0.00e+00 seconds >> mdo_chain = 0 calls / 0 linearizations / 0.00e+00 seconds >> sub_mda = 0 calls / 0 linearizations / 0.00e+00 seconds >> scenario = 1 calls / 0 linearizations / 7.60e-02 seconds .. GENERATED FROM PYTHON SOURCE LINES 305-306 or plot the execution time: .. GENERATED FROM PYTHON SOURCE LINES 306-308 .. code-block:: default study.plot_exec_time() .. image-sg:: /examples/scalable/images/sphx_glr_scalable_tm_004.png :alt: scalable tm :srcset: /examples/scalable/images/sphx_glr_scalable_tm_004.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 309-310 .. image:: /_images/scalable_tm/exec_time.png .. GENERATED FROM PYTHON SOURCE LINES 312-321 Parametric scalability study ---------------------------- We define a parametric scalability study based on two strongly coupled disciplines and a weakly one, with the following properties: - 3 shared design parameters, - 2 coupling variables for each strongly coupled discipline, - 1, 5 or 25 local design parameters for each strongly coupled discipline, .. GENERATED FROM PYTHON SOURCE LINES 321-324 .. code-block:: default study = TMParamSS(n_disciplines=2, n_shared=3, n_local=[1, 5, 25], n_coupling=2) print(study) .. rst-class:: sphx-glr-script-out .. code-block:: none Parametric scalable study > 2 disciplines > 3 shared design parameters > 1, 5 or 25 local design parameters per discipline > 2 coupling variables per discipline .. GENERATED FROM PYTHON SOURCE LINES 325-332 .. code-block:: console Parametric scalable study > 2 disciplines > 3 shared design parameters > 1, 5 or 25 local design parameters per discipline > 2 coupling variables per discipline .. GENERATED FROM PYTHON SOURCE LINES 334-335 Then, we run MDF and IDF formulations: .. GENERATED FROM PYTHON SOURCE LINES 335-338 .. code-block:: default study.run_formulation("MDF") study.run_formulation("IDF") .. rst-class:: sphx-glr-horizontal * .. image-sg:: /examples/scalable/images/sphx_glr_scalable_tm_005.png :alt: scalable tm :srcset: /examples/scalable/images/sphx_glr_scalable_tm_005.png :class: sphx-glr-multi-img * .. image-sg:: /examples/scalable/images/sphx_glr_scalable_tm_006.png :alt: scalable tm :srcset: /examples/scalable/images/sphx_glr_scalable_tm_006.png :class: sphx-glr-multi-img * .. image-sg:: /examples/scalable/images/sphx_glr_scalable_tm_007.png :alt: scalable tm :srcset: /examples/scalable/images/sphx_glr_scalable_tm_007.png :class: sphx-glr-multi-img * .. image-sg:: /examples/scalable/images/sphx_glr_scalable_tm_008.png :alt: scalable tm :srcset: /examples/scalable/images/sphx_glr_scalable_tm_008.png :class: sphx-glr-multi-img * .. image-sg:: /examples/scalable/images/sphx_glr_scalable_tm_009.png :alt: scalable tm :srcset: /examples/scalable/images/sphx_glr_scalable_tm_009.png :class: sphx-glr-multi-img * .. image-sg:: /examples/scalable/images/sphx_glr_scalable_tm_010.png :alt: scalable tm :srcset: /examples/scalable/images/sphx_glr_scalable_tm_010.png :class: sphx-glr-multi-img .. rst-class:: sphx-glr-script-out .. code-block:: none INFO - 16:56:50: Make the starting point feasible. INFO - 16:56:50: INFO - 16:56:50: *** Start MDOScenario execution *** INFO - 16:56:50: MDOScenario INFO - 16:56:50: Disciplines: MainModel SubModel_0 SubModel_1 INFO - 16:56:50: MDO formulation: MDF INFO - 16:56:50: Optimization problem: INFO - 16:56:50: minimize obj(x_local_0, x_local_1, x_shared) INFO - 16:56:50: with respect to x_local_0, x_local_1, x_shared INFO - 16:56:50: subject to constraints: INFO - 16:56:50: cstr_0(x_local_0, x_local_1, x_shared) <= [0.88589544 0.88821903] INFO - 16:56:50: cstr_1(x_local_0, x_local_1, x_shared) <= [-0.17585898 -1.56050583] INFO - 16:56:50: over the design space: INFO - 16:56:50: | Parameter space | INFO - 16:56:50: +-----------+-------------+-------+-------------+-------+----------------------+ INFO - 16:56:50: | name | lower_bound | value | upper_bound | type | Initial distribution | INFO - 16:56:50: +-----------+-------------+-------+-------------+-------+----------------------+ INFO - 16:56:50: | x_local_0 | 0 | 0.5 | 1 | float | | INFO - 16:56:50: | x_local_1 | 0 | 0.5 | 1 | float | | INFO - 16:56:50: | x_shared | 0 | 0.5 | 1 | float | | INFO - 16:56:50: | x_shared | 0 | 0.5 | 1 | float | | INFO - 16:56:50: | x_shared | 0 | 0.5 | 1 | float | | INFO - 16:56:50: +-----------+-------------+-------+-------------+-------+----------------------+ INFO - 16:56:50: Solving optimization problem with algorithm NLOPT_SLSQP: INFO - 16:56:50: ... 0%| | 0/100 [00:00` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: scalable_tm.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_