.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/scalable/plot_problem.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_scalable_plot_problem.py: Scalable problem ================ We want to solve the Aerostructure MDO problem by means of the :class:`.MDF` formulation with a higher dimension for the sweep parameter. For that, we use the :class:`.ScalableProblem` class. .. GENERATED FROM PYTHON SOURCE LINES 30-40 .. code-block:: Python from __future__ import annotations from gemseo import create_discipline from gemseo import create_scenario from gemseo.problems.mdo.aerostructure.aerostructure_design_space import ( AerostructureDesignSpace, ) from gemseo.problems.mdo.scalable.data_driven.problem import ScalableProblem .. GENERATED FROM PYTHON SOURCE LINES 41-47 Define the design problem ------------------------- In a first step, we define the design problem in terms of objective function (to maximize or minimize), design variables (local and global) and constraints (equality and inequality). .. GENERATED FROM PYTHON SOURCE LINES 47-53 .. code-block:: Python design_variables = ["thick_airfoils", "thick_panels", "sweep"] objective_function = "range" eq_constraints = ["c_rf"] ineq_constraints = ["c_lift"] maximize_objective = True .. GENERATED FROM PYTHON SOURCE LINES 54-58 Create the disciplinary datasets -------------------------------- Then, we create the disciplinary :class:`.BaseFullCache` datasets based on a :class:`.DiagonalDOE`. .. GENERATED FROM PYTHON SOURCE LINES 58-76 .. code-block:: Python disciplines = create_discipline(["Aerodynamics", "Structure", "Mission"]) datasets = [] for discipline in disciplines: design_space = AerostructureDesignSpace() design_space.filter(discipline.io.input_grammar.names) output_names = iter(discipline.io.output_grammar.names) scenario = create_scenario( discipline, next(output_names), design_space, formulation_name="DisciplinaryOpt", scenario_type="DOE", ) for output_name in output_names: scenario.add_observable(output_name) scenario.execute(algo_name="DiagonalDOE", n_samples=10) datasets.append(scenario.to_dataset(name=discipline.name, opt_naming=False)) .. rst-class:: sphx-glr-script-out .. code-block:: none INFO - 16:21:38: *** Start DOEScenario execution *** INFO - 16:21:38: DOEScenario INFO - 16:21:38: Disciplines: Aerodynamics INFO - 16:21:38: MDO formulation: DisciplinaryOpt INFO - 16:21:38: Optimization problem: INFO - 16:21:38: minimize drag(thick_airfoils, sweep, displ) INFO - 16:21:38: with respect to displ, sweep, thick_airfoils INFO - 16:21:38: over the design space: INFO - 16:21:38: +----------------+-------------+-------+-------------+-------+ INFO - 16:21:38: | Name | Lower bound | Value | Upper bound | Type | INFO - 16:21:38: +----------------+-------------+-------+-------------+-------+ INFO - 16:21:38: | thick_airfoils | 5 | 15 | 25 | float | INFO - 16:21:38: | sweep | 10 | 25 | 35 | float | INFO - 16:21:38: | displ | -1000 | -700 | 1000 | float | INFO - 16:21:38: +----------------+-------------+-------+-------------+-------+ INFO - 16:21:38: Solving optimization problem with algorithm DiagonalDOE: INFO - 16:21:38: 10%|█ | 1/10 [00:00<00:00, 390.53 it/sec, feas=True, obj=422] INFO - 16:21:38: 20%|██ | 2/10 [00:00<00:00, 665.08 it/sec, feas=True, obj=336] INFO - 16:21:38: 30%|███ | 3/10 [00:00<00:00, 886.50 it/sec, feas=True, obj=250] INFO - 16:21:38: 40%|████ | 4/10 [00:00<00:00, 1068.88 it/sec, feas=True, obj=166] INFO - 16:21:38: 50%|█████ | 5/10 [00:00<00:00, 1211.39 it/sec, feas=True, obj=82.3] INFO - 16:21:38: 60%|██████ | 6/10 [00:00<00:00, 1345.48 it/sec, feas=True, obj=-0.0983] INFO - 16:21:38: 70%|███████ | 7/10 [00:00<00:00, 1455.42 it/sec, feas=True, obj=-81.6] INFO - 16:21:38: 80%|████████ | 8/10 [00:00<00:00, 1557.99 it/sec, feas=True, obj=-162] INFO - 16:21:38: 90%|█████████ | 9/10 [00:00<00:00, 1650.22 it/sec, feas=True, obj=-242] INFO - 16:21:38: 100%|██████████| 10/10 [00:00<00:00, 1704.59 it/sec, feas=True, obj=-320] INFO - 16:21:38: Optimization result: INFO - 16:21:38: Optimizer info: INFO - 16:21:38: Status: None INFO - 16:21:38: Message: None INFO - 16:21:38: Solution: INFO - 16:21:38: Objective: -319.99905478395067 INFO - 16:21:38: Design space: INFO - 16:21:38: +----------------+-------------+-------+-------------+-------+ INFO - 16:21:38: | Name | Lower bound | Value | Upper bound | Type | INFO - 16:21:38: +----------------+-------------+-------+-------------+-------+ INFO - 16:21:38: | thick_airfoils | 5 | 25 | 25 | float | INFO - 16:21:38: | sweep | 10 | 35 | 35 | float | INFO - 16:21:38: | displ | -1000 | 1000 | 1000 | float | INFO - 16:21:38: +----------------+-------------+-------+-------------+-------+ INFO - 16:21:38: *** End DOEScenario execution *** INFO - 16:21:38: *** Start DOEScenario execution *** INFO - 16:21:38: DOEScenario INFO - 16:21:38: Disciplines: Structure INFO - 16:21:38: MDO formulation: DisciplinaryOpt INFO - 16:21:38: Optimization problem: INFO - 16:21:38: minimize mass(thick_panels, sweep, forces) INFO - 16:21:38: with respect to forces, sweep, thick_panels INFO - 16:21:38: over the design space: INFO - 16:21:38: +--------------+-------------+-------+-------------+-------+ INFO - 16:21:38: | Name | Lower bound | Value | Upper bound | Type | INFO - 16:21:38: +--------------+-------------+-------+-------------+-------+ INFO - 16:21:38: | thick_panels | 1 | 3 | 20 | float | INFO - 16:21:38: | sweep | 10 | 25 | 35 | float | INFO - 16:21:38: | forces | -1000 | 400 | 1000 | float | INFO - 16:21:38: +--------------+-------------+-------+-------------+-------+ INFO - 16:21:38: Solving optimization problem with algorithm DiagonalDOE: INFO - 16:21:38: 10%|█ | 1/10 [00:00<00:00, 393.24 it/sec, feas=True, obj=100] INFO - 16:21:38: 20%|██ | 2/10 [00:00<00:00, 671.30 it/sec, feas=True, obj=4.48e+4] INFO - 16:21:38: 30%|███ | 3/10 [00:00<00:00, 883.45 it/sec, feas=True, obj=8.94e+4] INFO - 16:21:38: 40%|████ | 4/10 [00:00<00:00, 1060.77 it/sec, feas=True, obj=1.34e+5] INFO - 16:21:38: 50%|█████ | 5/10 [00:00<00:00, 1209.71 it/sec, feas=True, obj=1.79e+5] INFO - 16:21:38: 60%|██████ | 6/10 [00:00<00:00, 1331.45 it/sec, feas=True, obj=2.23e+5] INFO - 16:21:38: 70%|███████ | 7/10 [00:00<00:00, 1435.00 it/sec, feas=True, obj=2.68e+5] INFO - 16:21:38: 80%|████████ | 8/10 [00:00<00:00, 1520.78 it/sec, feas=True, obj=3.13e+5] INFO - 16:21:38: 90%|█████████ | 9/10 [00:00<00:00, 1599.86 it/sec, feas=True, obj=3.57e+5] INFO - 16:21:38: 100%|██████████| 10/10 [00:00<00:00, 1659.01 it/sec, feas=True, obj=4.02e+5] INFO - 16:21:38: Optimization result: INFO - 16:21:38: Optimizer info: INFO - 16:21:38: Status: None INFO - 16:21:38: Message: None INFO - 16:21:38: Solution: INFO - 16:21:38: Objective: 100.08573388203513 INFO - 16:21:38: Design space: INFO - 16:21:38: +--------------+-------------+-------+-------------+-------+ INFO - 16:21:38: | Name | Lower bound | Value | Upper bound | Type | INFO - 16:21:38: +--------------+-------------+-------+-------------+-------+ INFO - 16:21:38: | thick_panels | 1 | 1 | 20 | float | INFO - 16:21:38: | sweep | 10 | 10 | 35 | float | INFO - 16:21:38: | forces | -1000 | -1000 | 1000 | float | INFO - 16:21:38: +--------------+-------------+-------+-------------+-------+ INFO - 16:21:38: *** End DOEScenario execution *** INFO - 16:21:38: *** Start DOEScenario execution *** INFO - 16:21:38: DOEScenario INFO - 16:21:38: Disciplines: Mission INFO - 16:21:38: MDO formulation: DisciplinaryOpt INFO - 16:21:38: Optimization problem: INFO - 16:21:38: minimize range(drag, lift, mass, reserve_fact) INFO - 16:21:38: with respect to drag, lift, mass, reserve_fact INFO - 16:21:38: over the design space: INFO - 16:21:38: +--------------+-------------+--------+-------------+-------+ INFO - 16:21:38: | Name | Lower bound | Value | Upper bound | Type | INFO - 16:21:38: +--------------+-------------+--------+-------------+-------+ INFO - 16:21:38: | drag | 100 | 340 | 1000 | float | INFO - 16:21:38: | lift | 0.1 | 0.5 | 1 | float | INFO - 16:21:38: | mass | 100000 | 100000 | 500000 | float | INFO - 16:21:38: | reserve_fact | -1000 | 0 | 1000 | float | INFO - 16:21:38: +--------------+-------------+--------+-------------+-------+ INFO - 16:21:38: Solving optimization problem with algorithm DiagonalDOE: INFO - 16:21:38: 10%|█ | 1/10 [00:00<00:00, 437.45 it/sec, feas=True, obj=8e+3+0j] INFO - 16:21:38: 20%|██ | 2/10 [00:00<00:00, 733.08 it/sec, feas=True, obj=5.54e+3+0j] INFO - 16:21:38: 30%|███ | 3/10 [00:00<00:00, 962.07 it/sec, feas=True, obj=4.24e+3+0j] INFO - 16:21:38: 40%|████ | 4/10 [00:00<00:00, 1150.23 it/sec, feas=True, obj=3.43e+3+0j] INFO - 16:21:38: 50%|█████ | 5/10 [00:00<00:00, 1294.86 it/sec, feas=True, obj=2.88e+3+0j] INFO - 16:21:38: 60%|██████ | 6/10 [00:00<00:00, 1424.86 it/sec, feas=True, obj=2.48e+3+0j] INFO - 16:21:38: 70%|███████ | 7/10 [00:00<00:00, 1527.82 it/sec, feas=True, obj=2.18e+3+0j] INFO - 16:21:38: 80%|████████ | 8/10 [00:00<00:00, 1624.28 it/sec, feas=True, obj=1.95e+3+0j] INFO - 16:21:38: 90%|█████████ | 9/10 [00:00<00:00, 1711.88 it/sec, feas=True, obj=1.76e+3+0j] INFO - 16:21:38: 100%|██████████| 10/10 [00:00<00:00, 1756.19 it/sec, feas=True, obj=(1600+0j)] INFO - 16:21:38: Optimization result: INFO - 16:21:38: Optimizer info: INFO - 16:21:38: Status: None INFO - 16:21:38: Message: None INFO - 16:21:38: Solution: INFO - 16:21:38: Objective: (1600+0j) INFO - 16:21:38: Design space: INFO - 16:21:38: +--------------+-------------+--------+-------------+-------+ INFO - 16:21:38: | Name | Lower bound | Value | Upper bound | Type | INFO - 16:21:38: +--------------+-------------+--------+-------------+-------+ INFO - 16:21:38: | drag | 100 | 1000 | 1000 | float | INFO - 16:21:38: | lift | 0.1 | 1 | 1 | float | INFO - 16:21:38: | mass | 100000 | 500000 | 500000 | float | INFO - 16:21:38: | reserve_fact | -1000 | 1000 | 1000 | float | INFO - 16:21:38: +--------------+-------------+--------+-------------+-------+ INFO - 16:21:38: *** End DOEScenario execution *** .. GENERATED FROM PYTHON SOURCE LINES 77-82 Instantiate a scalable problem ------------------------------ In a third stage, we instantiate a :class:`.ScalableProblem` from these disciplinary datasets and from the definition of the MDO problem. We also increase the dimension of the sweep parameter. .. GENERATED FROM PYTHON SOURCE LINES 82-93 .. code-block:: Python problem = ScalableProblem( datasets, design_variables, objective_function, eq_constraints, ineq_constraints, maximize_objective, sizes={"sweep": 2}, ) print(problem) .. rst-class:: sphx-glr-script-out .. code-block:: none MDO problem Disciplines: Aerodynamics, Structure, Mission Design variables: thick_airfoils, thick_panels, sweep Objective function: range (to maximize) Inequality constraints: c_lift Equality constraints: c_rf Sizes: displ (1), sweep (2), thick_airfoils (1), drag (1), forces (1), lift (1), thick_panels (1), mass (1), reserve_fact (1), c_lift (1), c_rf (1), range (1) .. GENERATED FROM PYTHON SOURCE LINES 94-100 .. note:: We could also provide options to the :class:`.ScalableModel` objects by means of the constructor of :class:`.ScalableProblem`, e.g. ``fill_factor`` in the frame of the :class:`.ScalableDiagonalModel`. In this example, we use the standard ones. .. GENERATED FROM PYTHON SOURCE LINES 102-105 Visualize the N2 chart ---------------------- We can see the coupling between disciplines through this N2 chart: .. GENERATED FROM PYTHON SOURCE LINES 105-107 .. code-block:: Python problem.plot_n2_chart(save=False, show=True) .. image-sg:: /examples/scalable/images/sphx_glr_plot_problem_001.png :alt: plot problem :srcset: /examples/scalable/images/sphx_glr_plot_problem_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 108-113 Create an MDO scenario ---------------------- Lastly, we create an :class:`.MDOScenario` with the :class:`.MDF` formulation and start the optimization at equilibrium, thus ensuring the feasibility of the first iterate. .. GENERATED FROM PYTHON SOURCE LINES 113-115 .. code-block:: Python scenario = problem.create_scenario("MDF", start_at_equilibrium=True) .. rst-class:: sphx-glr-script-out .. code-block:: none INFO - 16:21:38: Build a preliminary MDA to start at equilibrium .. GENERATED FROM PYTHON SOURCE LINES 116-122 .. note:: We could also provide options for the scalable models to the constructor of :class:`.ScalableProblem`, e.g. ``fill_factor`` in the frame of the :class:`.ScalableDiagonalModel`. In this example, we use the standard ones. .. GENERATED FROM PYTHON SOURCE LINES 124-127 Once the scenario is created, we can execute it as any scenario. Here, we use the ``NLOPT_SLSQP`` optimization algorithm with no more than 100 iterations. .. GENERATED FROM PYTHON SOURCE LINES 127-129 .. code-block:: Python scenario.execute(algo_name="NLOPT_SLSQP", max_iter=100) .. rst-class:: sphx-glr-script-out .. code-block:: none INFO - 16:21:38: *** Start MDOScenario execution *** INFO - 16:21:38: MDOScenario INFO - 16:21:38: Disciplines: sdm_Aerodynamics sdm_Mission sdm_Structure INFO - 16:21:38: MDO formulation: MDF INFO - 16:21:38: Optimization problem: INFO - 16:21:38: minimize -range(thick_airfoils, thick_panels, sweep) INFO - 16:21:38: with respect to sweep, thick_airfoils, thick_panels INFO - 16:21:38: under the equality constraints INFO - 16:21:38: c_rf(thick_airfoils, thick_panels, sweep) = 0.49642016361892943 INFO - 16:21:38: under the inequality constraints INFO - 16:21:38: c_lift(thick_airfoils, thick_panels, sweep) <= [0.74554856] INFO - 16:21:38: over the design space: INFO - 16:21:38: +----------------+-------------+-------+-------------+-------+ INFO - 16:21:38: | Name | Lower bound | Value | Upper bound | Type | INFO - 16:21:38: +----------------+-------------+-------+-------------+-------+ INFO - 16:21:38: | thick_airfoils | 0 | 0.5 | 1 | float | INFO - 16:21:38: | thick_panels | 0 | 0.5 | 1 | float | INFO - 16:21:38: | sweep[0] | 0 | 0.5 | 1 | float | INFO - 16:21:38: | sweep[1] | 0 | 0.5 | 1 | float | INFO - 16:21:38: +----------------+-------------+-------+-------------+-------+ INFO - 16:21:38: Solving optimization problem with algorithm NLOPT_SLSQP: INFO - 16:21:38: 1%| | 1/100 [00:00<00:01, 57.96 it/sec, feas=True, obj=-0.168] INFO - 16:21:38: 2%|▏ | 2/100 [00:00<00:01, 53.55 it/sec, feas=True, obj=-0.172] INFO - 16:21:39: 3%|▎ | 3/100 [00:00<00:02, 40.08 it/sec, feas=True, obj=-0.2] INFO - 16:21:39: 4%|▍ | 4/100 [00:00<00:02, 41.63 it/sec, feas=True, obj=-0.302] INFO - 16:21:39: 5%|▌ | 5/100 [00:00<00:02, 42.02 it/sec, feas=True, obj=-0.302] INFO - 16:21:39: 6%|▌ | 6/100 [00:00<00:02, 41.39 it/sec, feas=True, obj=-0.303] INFO - 16:21:39: 7%|▋ | 7/100 [00:00<00:02, 41.89 it/sec, feas=True, obj=-0.304] INFO - 16:21:39: 8%|▊ | 8/100 [00:00<00:02, 42.28 it/sec, feas=True, obj=-0.309] INFO - 16:21:39: 9%|▉ | 9/100 [00:00<00:02, 42.58 it/sec, feas=True, obj=-0.309] INFO - 16:21:39: 10%|█ | 10/100 [00:00<00:02, 42.57 it/sec, feas=True, obj=-0.309] INFO - 16:21:39: 11%|█ | 11/100 [00:00<00:02, 42.97 it/sec, feas=True, obj=-0.309] INFO - 16:21:39: Optimization result: INFO - 16:21:39: Optimizer info: INFO - 16:21:39: Status: None INFO - 16:21:39: Message: Successive iterates of the objective function are closer than ftol_rel or ftol_abs. GEMSEO stopped the driver. INFO - 16:21:39: Solution: INFO - 16:21:39: The solution is feasible. INFO - 16:21:39: Objective: -0.3093760989443489 INFO - 16:21:39: Standardized constraints: INFO - 16:21:39: [c_lift+offset] = [-0.42031165] INFO - 16:21:39: [c_rf-0.49642016361892943] = 0.0 INFO - 16:21:39: Design space: INFO - 16:21:39: +----------------+-------------+--------------------+-------------+-------+ INFO - 16:21:39: | Name | Lower bound | Value | Upper bound | Type | INFO - 16:21:39: +----------------+-------------+--------------------+-------------+-------+ INFO - 16:21:39: | thick_airfoils | 0 | 0.300477022842664 | 1 | float | INFO - 16:21:39: | thick_panels | 0 | 0.9999999999999986 | 1 | float | INFO - 16:21:39: | sweep[0] | 0 | 1 | 1 | float | INFO - 16:21:39: | sweep[1] | 0 | 0.9999999999999999 | 1 | float | INFO - 16:21:39: +----------------+-------------+--------------------+-------------+-------+ INFO - 16:21:39: *** End MDOScenario execution *** .. GENERATED FROM PYTHON SOURCE LINES 130-132 We can post-process the results. Here, we use the standard :class:`.OptHistoryView`. .. GENERATED FROM PYTHON SOURCE LINES 132-133 .. code-block:: Python scenario.post_process(post_name="OptHistoryView", save=False, show=True) .. rst-class:: sphx-glr-horizontal * .. image-sg:: /examples/scalable/images/sphx_glr_plot_problem_002.png :alt: Evolution of the optimization variables :srcset: /examples/scalable/images/sphx_glr_plot_problem_002.png :class: sphx-glr-multi-img * .. image-sg:: /examples/scalable/images/sphx_glr_plot_problem_003.png :alt: Evolution of the objective value :srcset: /examples/scalable/images/sphx_glr_plot_problem_003.png :class: sphx-glr-multi-img * .. image-sg:: /examples/scalable/images/sphx_glr_plot_problem_004.png :alt: Evolution of the distance to the optimum :srcset: /examples/scalable/images/sphx_glr_plot_problem_004.png :class: sphx-glr-multi-img * .. image-sg:: /examples/scalable/images/sphx_glr_plot_problem_005.png :alt: Evolution of the inequality constraints :srcset: /examples/scalable/images/sphx_glr_plot_problem_005.png :class: sphx-glr-multi-img * .. image-sg:: /examples/scalable/images/sphx_glr_plot_problem_006.png :alt: Evolution of the equality constraints :srcset: /examples/scalable/images/sphx_glr_plot_problem_006.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.972 seconds) .. _sphx_glr_download_examples_scalable_plot_problem.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_problem.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_problem.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_problem.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_