.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/scalable/scalable_study.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_study.py: Scalable study ============== We want to compare :class:`.IDF` and :class:`.MDF` formulations with respect to the problem dimension for the aerostructure problem. For that, we use the :class:`.ScalabilityStudy` and :class:`.PostScalabilityStudy` classes. .. GENERATED FROM PYTHON SOURCE LINES 32-46 .. code-block:: default from __future__ import division, unicode_literals from gemseo.api import configure_logger, create_discipline, create_scenario from gemseo.problems.aerostructure.aerostructure_design_space import ( AerostructureDesignSpace, ) from gemseo.problems.scalable.data_driven.api import ( create_scalability_study, plot_scalability_results, ) configure_logger() .. GENERATED FROM PYTHON SOURCE LINES 47-51 Create the disciplinary datasets -------------------------------- First of all, we create the disciplinary :class:`.AbstractFullCache` datasets based on a :class:`.DiagonalDOE`. .. GENERATED FROM PYTHON SOURCE LINES 51-65 .. code-block:: default datasets = {} disciplines = create_discipline(["Aerodynamics", "Structure", "Mission"]) for discipline in disciplines: discipline.set_cache_policy("MemoryFullCache") 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}) datasets[discipline.name] = discipline.cache.export_to_dataset() discipline.cache.clear() .. GENERATED FROM PYTHON SOURCE LINES 66-80 Define the design problem ------------------------- Then, we instantiate a :class:`.ScalabilityStudy` from the definition of the design problem, expressed in terms of objective function (to maximize or minimize), design variables (local and global) and constraints (equality and inequality). We can also specify the coupling variables that we could scale. Note that this information is only required by the scaling stage. Indeed, MDO formulations know perfectly how to automatically recognize the coupling variables. Lastly, we can specify some properties of the scalable methodology such as the fill factor describing the level of dependence between inputs and outputs. .. GENERATED FROM PYTHON SOURCE LINES 80-91 .. code-block:: default study = create_scalability_study( objective="range", design_variables=["thick_airfoils", "thick_panels", "sweep"], eq_constraints=["c_rf"], ineq_constraints=["c_lift"], maximize_objective=True, coupling_variables=["forces", "displ"], fill_factor=-1, ) .. GENERATED FROM PYTHON SOURCE LINES 92-94 Add the disciplinary datasets ----------------------------- .. GENERATED FROM PYTHON SOURCE LINES 94-98 .. code-block:: default study.add_discipline(datasets["Aerodynamics"]) study.add_discipline(datasets["Structure"]) study.add_discipline(datasets["Mission"]) .. GENERATED FROM PYTHON SOURCE LINES 99-111 Add the optimization strategies ------------------------------- Then, we define the different optimization strategies we want to compare: In this case, the strategies are: - :class:`.MDF` formulation with the :code:`"NLOPT_SLSQP"` optimization algorithm and no more than 100 iterations, - :class:`.IDF` formulation with the :code:`"NLOPT_SLSQP"` optimization algorithm and no more than 100 iterations, Note that in this case, we compare MDO formulations but we could easily compare optimization algorithms. .. GENERATED FROM PYTHON SOURCE LINES 111-114 .. code-block:: default study.add_optimization_strategy("NLOPT_SLSQP", 100, "MDF") study.add_optimization_strategy("NLOPT_SLSQP", 100, "IDF") .. GENERATED FROM PYTHON SOURCE LINES 115-144 Add the scaling strategy ------------------------ After that, we define the different scaling strategies for which we want to compare the optimization strategies. In this case, the strategies are: 1. All design parameters have a size equal to 1, 2. All design parameters have a size equal to 10, 3. All design parameters have a size equal to 20. To do that, we pass :code:`design_size=[1, 10, 20]` to the :meth:`.ScalabilityStudy.add_scaling_strategies` method. :code:`design_size` expects either: - a list of integer where the ith component is the size for the ith scaling strategy, - an integer changing the fixed size (if :code:`None`, use the original size). Note that we could also compare the optimization strategies while - varying the size of the different coupling variables (use :code:`coupling_size`), - varying the size of the different equality constraints (use :code:`eq_size`), - varying the size of the different inequality constraints (use :code:`ineq_size`), - varying the size of any variable (use :code:`variables`), where the corresponding arguments works in the same way as :code:`design_size`, except for :code:`variables` which expects a list of dictionary whose keys are variables names and values are variables sizes. In this way, we can use this argument to fine-tune a scaling strategy to very specific variables, e.g. local variables. .. GENERATED FROM PYTHON SOURCE LINES 144-146 .. code-block:: default study.add_scaling_strategies(design_size=[1, 10, 20]) .. GENERATED FROM PYTHON SOURCE LINES 147-154 Execute the scalable study -------------------------- Then, we execute the scalability study, i.e. to build and execute a :class:`.ScalableProblem` for each optimization strategy and each scaling strategy, and repeat it 10 times in order to get statistics on the results (because the :class:`.ScalableDiagonalModel` relies on stochastic features. .. GENERATED FROM PYTHON SOURCE LINES 154-156 .. code-block:: default study.execute(n_replicates=10) .. GENERATED FROM PYTHON SOURCE LINES 157-173 Look at the dependency matrices ------------------------------- Here are the dependency matrices obtained with the 1st replicate when :code:`design_size=10`. Aerodynamics ~~~~~~~~~~~~ .. image:: /_images/scalable_example/2_1_sdm_Aerodynamics_dependency-1.png Structure ~~~~~~~~~~~~ .. image:: /_images/scalable_example/2_1_sdm_Structure_dependency-1.png Mission ~~~~~~~ .. image:: /_images/scalable_example/2_1_sdm_Mission_dependency-1.png .. GENERATED FROM PYTHON SOURCE LINES 175-212 Look at optimization histories ------------------------------ Here are the optimization histories obtained with the 1st replicate when :code:`design_size=10`, where the left side represents the :class:`.MDF` formulation while the right one represents the :class:`.IDF` formulation. Objective function ~~~~~~~~~~~~~~~~~~ .. image:: /_images/scalable_example/MDF_2_1_obj_history-1.png :width: 45% .. image:: /_images/scalable_example/IDF_2_1_obj_history-1.png :width: 45% Design variables ~~~~~~~~~~~~~~~~ .. image:: /_images/scalable_example/MDF_2_1_variables_history-1.png :width: 45% .. image:: /_images/scalable_example/IDF_2_1_variables_history-1.png :width: 45% Equality constraints ~~~~~~~~~~~~~~~~~~~~ .. image:: /_images/scalable_example/MDF_2_1_eq_constraints_history-1.png :width: 45% .. image:: /_images/scalable_example/IDF_2_1_eq_constraints_history-1.png :width: 45% Inequality constraints ~~~~~~~~~~~~~~~~~~~~~~ .. image:: /_images/scalable_example/MDF_2_1_ineq_constraints_history-1.png :width: 45% .. image:: /_images/scalable_example/IDF_2_1_ineq_constraints_history-1.png :width: 45% .. GENERATED FROM PYTHON SOURCE LINES 214-226 Post-process the results ------------------------ Lastly, we plot the results. Because of the replicates, the latter are not displayed as one line per optimization strategy w.r.t. scaling strategy, but as one series of boxplots per optimization strategy w.r.t. scaling strategy, where the boxplots represents the variability due to the 10 replicates. In this case, it seems that the :class:`.MDF` formulation is more expensive than the :class:`.IDF` one when the design space dimension increases while they seems to be the same when each design parameter has a size equal to 1. .. GENERATED FROM PYTHON SOURCE LINES 226-232 .. code-block:: default post = plot_scalability_results("study") post.labelize_scaling_strategy("Number of design parameters per type.") post.plot( xmargin=3.0, xticks=[1.0, 10.0, 20.0], xticks_labels=["1", "10", "20"], widths=1.0 ) .. GENERATED FROM PYTHON SOURCE LINES 233-235 .. image:: /_images/scalable_example/exec_time-1.png .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.000 seconds) .. _sphx_glr_download_examples_scalable_scalable_study.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: scalable_study.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: scalable_study.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_