.. 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-44 .. code-block:: Python from __future__ import annotations from gemseo import configure_logger from gemseo import create_discipline from gemseo import create_scenario from gemseo.problems.aerostructure.aerostructure_design_space import ( AerostructureDesignSpace, ) from gemseo.problems.mdo.scalable.data_driven.problem import ScalableProblem configure_logger() .. rst-class:: sphx-glr-script-out .. code-block:: pytb Traceback (most recent call last): File "/home/docs/checkouts/readthedocs.org/user_builds/gemseo/checkouts/develop/doc_src/_examples/scalable/plot_problem.py", line 36, in from gemseo.problems.aerostructure.aerostructure_design_space import ( ModuleNotFoundError: No module named 'gemseo.problems.aerostructure' .. GENERATED FROM PYTHON SOURCE LINES 45-51 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 51-57 .. 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 58-62 Create the disciplinary datasets -------------------------------- Then, we create the disciplinary :class:`.AbstractFullCache` datasets based on a :class:`.DiagonalDOE`. .. GENERATED FROM PYTHON SOURCE LINES 62-80 .. code-block:: Python disciplines = create_discipline(["Aerodynamics", "Structure", "Mission"]) datasets = [] for discipline in disciplines: design_space = AerostructureDesignSpace() design_space.filter(discipline.get_input_data_names()) output_names = iter(discipline.get_output_data_names()) scenario = create_scenario( discipline, "DisciplinaryOpt", next(output_names), design_space, scenario_type="DOE", ) for output_name in output_names: scenario.add_observable(output_name) scenario.execute({"algo": "DiagonalDOE", "n_samples": 10}) datasets.append(scenario.to_dataset(name=discipline.name, opt_naming=False)) .. GENERATED FROM PYTHON SOURCE LINES 81-86 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 86-97 .. code-block:: Python problem = ScalableProblem( datasets, design_variables, objective_function, eq_constraints, ineq_constraints, maximize_objective, sizes={"sweep": 2}, ) print(problem) .. GENERATED FROM PYTHON SOURCE LINES 98-104 .. 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 106-109 Visualize the N2 chart ---------------------- We can see the coupling between disciplines through this N2 chart: .. GENERATED FROM PYTHON SOURCE LINES 109-111 .. code-block:: Python problem.plot_n2_chart(save=False, show=True) .. GENERATED FROM PYTHON SOURCE LINES 112-117 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 117-119 .. code-block:: Python scenario = problem.create_scenario("MDF", start_at_equilibrium=True) .. GENERATED FROM PYTHON SOURCE LINES 120-126 .. 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 128-131 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 131-133 .. code-block:: Python scenario.execute({"algo": "NLOPT_SLSQP", "max_iter": 100}) .. GENERATED FROM PYTHON SOURCE LINES 134-136 We can post-process the results. Here, we use the standard :class:`.OptHistoryView`. .. GENERATED FROM PYTHON SOURCE LINES 136-137 .. code-block:: Python scenario.post_process("OptHistoryView", save=False, show=True) .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.001 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 ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_