.. 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 Click :ref:`here ` 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 32-46 .. code-block:: default from __future__ import absolute_import, division, print_function, unicode_literals from future import standard_library from gemseo.api import configure_logger, create_discipline, create_scenario from gemseo.problems.aerostructure.aerostructure_design_space import ( AerostructureDesignSpace, ) from gemseo.problems.scalable.problem import ScalableProblem configure_logger() standard_library.install_aliases() .. GENERATED FROM PYTHON SOURCE LINES 47-53 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 53-59 .. code-block:: default 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 60-64 Create the disciplinary datasets -------------------------------- Then, we create the disciplinary :class:`.AbstractFullCache` datasets based on a :class:`.DiagonalDOE`. .. GENERATED FROM PYTHON SOURCE LINES 64-75 .. code-block:: default disciplines = create_discipline(["Aerodynamics", "Structure", "Mission"]) for discipline in disciplines: discipline.set_cache_policy(discipline.MEMORY_FULL_CACHE) design_space = AerostructureDesignSpace() design_space.filter(discipline.get_input_data_names()) output = next(iter(discipline.get_output_data_names())) scenario = create_scenario( discipline, "DisciplinaryOpt", output, design_space, scenario_type="DOE" ) scenario.execute({"algo": "DiagonalDOE", "n_samples": 10}) .. GENERATED FROM PYTHON SOURCE LINES 76-81 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 81-93 .. code-block:: default datasets = [discipline.cache for discipline in disciplines] problem = ScalableProblem( datasets, design_variables, objective_function, eq_constraints, ineq_constraints, maximize_objective, sizes={"sweep": 2}, ) print(problem) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none /home/docs/checkouts/readthedocs.org/user_builds/gemseo/conda/3.0.3/lib/python3.8/site-packages/scipy/interpolate/fitpack2.py:611: ComplexWarning: Casting complex values to real discards the imaginary part self._data = dfitpack.fpcurf0(x, y, k, w=w, xb=bbox[0], 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: sweep (2), thick_airfoils (1), displ (1), drag (1), forces (1), lift (1), thick_panels (1), mass (1), reserve_fact (1), range (1), c_lift (1), c_rf (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. :code:`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:: default problem.plot_n2_chart(save=False, show=True) .. image:: /examples/scalable/images/sphx_glr_plot_problem_001.png :alt: plot problem :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 108-113 Create a MDO scenario --------------------- Lastly, we create a :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:: default scenario = problem.create_scenario("MDF", start_at_equilibrium=True) .. GENERATED FROM PYTHON SOURCE LINES 116-119 Once the scenario is created, we can execute it as any scenario. Here, we use the :code:`NLOPT_SLSQP` optimization algorithm with no more than 100 iterations. .. GENERATED FROM PYTHON SOURCE LINES 119-121 .. code-block:: default scenario.execute({"algo": "NLOPT_SLSQP", "max_iter": 100}) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none {'algo': 'NLOPT_SLSQP', 'max_iter': 100} .. GENERATED FROM PYTHON SOURCE LINES 122-124 We can post-process the results. Here, we use the standard :class:`.OptHistoryView`. .. GENERATED FROM PYTHON SOURCE LINES 124-125 .. code-block:: default scenario.post_process("OptHistoryView", save=False, show=True) .. rst-class:: sphx-glr-horizontal * .. image:: /examples/scalable/images/sphx_glr_plot_problem_002.png :alt: Evolution of the optimization variables :class: sphx-glr-multi-img * .. image:: /examples/scalable/images/sphx_glr_plot_problem_003.png :alt: Evolution of the objective value :class: sphx-glr-multi-img * .. image:: /examples/scalable/images/sphx_glr_plot_problem_004.png :alt: Distance to the optimum :class: sphx-glr-multi-img * .. image:: /examples/scalable/images/sphx_glr_plot_problem_005.png :alt: Hessian diagonal approximation :class: sphx-glr-multi-img * .. image:: /examples/scalable/images/sphx_glr_plot_problem_006.png :alt: Evolution of the inequality constraints :class: sphx-glr-multi-img * .. image:: /examples/scalable/images/sphx_glr_plot_problem_007.png :alt: Evolution of the equality constraints :class: sphx-glr-multi-img .. rst-class:: sphx-glr-script-out Out: .. code-block:: none /home/docs/checkouts/readthedocs.org/user_builds/gemseo/conda/3.0.3/lib/python3.8/site-packages/gemseo/post/opt_history_view.py:312: UserWarning: FixedFormatter should only be used together with FixedLocator ax1.set_yticklabels(y_labels) /home/docs/checkouts/readthedocs.org/user_builds/gemseo/conda/3.0.3/lib/python3.8/site-packages/gemseo/post/opt_history_view.py:716: MatplotlibDeprecationWarning: default base will change from np.e to 10 in 3.4. To suppress this warning specify the base keyword argument. norm=SymLogNorm(linthresh=linthresh, vmin=-vmax, vmax=vmax), /home/docs/checkouts/readthedocs.org/user_builds/gemseo/conda/3.0.3/lib/python3.8/site-packages/gemseo/post/opt_history_view.py:626: MatplotlibDeprecationWarning: default base will change from np.e to 10 in 3.4. To suppress this warning specify the base keyword argument. norm=SymLogNorm(linthresh=1.0, vmin=-vmax, vmax=vmax), /home/docs/checkouts/readthedocs.org/user_builds/gemseo/conda/3.0.3/lib/python3.8/site-packages/gemseo/post/opt_history_view.py:619: MatplotlibDeprecationWarning: Passing parameters norm and vmin/vmax simultaneously is deprecated since 3.3 and will become an error two minor releases later. Please pass vmin/vmax directly to the norm when creating it. im1 = ax1.imshow( .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 1.995 seconds) .. _sphx_glr_download_examples_scalable_plot_problem.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_problem.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_problem.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_