.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/scenario/plot_doe_scenario.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_scenario_plot_doe_scenario.py: Create a DOE Scenario ===================== .. GENERATED FROM PYTHON SOURCE LINES 28-42 .. code-block:: default from __future__ import division, unicode_literals from gemseo.api import ( configure_logger, create_design_space, create_discipline, create_scenario, get_available_doe_algorithms, get_available_post_processings, ) configure_logger() .. rst-class:: sphx-glr-script-out Out: .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 43-64 Let :math:`(P)` be a simple optimization problem: .. math:: (P) = \left\{ \begin{aligned} & \underset{x\in\mathbb{N}^2}{\text{minimize}} & & f(x) = x_1 + x_2 \\ & \text{subject to} & & -5 \leq x \leq 5 \end{aligned} \right. In this example, we will see how to use |g| to solve this problem :math:`(P)` by means of a Design Of Experiments (DOE) Define the discipline --------------------- Firstly, by means of the :meth:`~gemseo.api.create_discipline` API function, we create an :class:`.MDODiscipline` of :class:`.AnalyticDiscipline` type from a Python function: .. GENERATED FROM PYTHON SOURCE LINES 64-68 .. code-block:: default expressions_dict = {"y": "x1+x2"} discipline = create_discipline("AnalyticDiscipline", expressions_dict=expressions_dict) .. GENERATED FROM PYTHON SOURCE LINES 69-77 Now, we want to minimize this :class:`.MDODiscipline` over a design of experiments (DOE). Define the design space ----------------------- For that, by means of the :meth:`~gemseo.api.create_design_space` API function, we define the :class:`.DesignSpace` :math:`[-5, 5]\times[-5, 5]` by using its :meth:`.DesignSpace.add_variable` method. .. GENERATED FROM PYTHON SOURCE LINES 77-82 .. code-block:: default design_space = create_design_space() design_space.add_variable("x1", 1, l_b=-5, u_b=5, var_type="integer") design_space.add_variable("x2", 1, l_b=-5, u_b=5, var_type="integer") .. GENERATED FROM PYTHON SOURCE LINES 83-88 Define the DOE scenario ----------------------- Then, by means of the :meth:`~gemseo.api.create_scenario` API function, we define a :class:`.DOEScenario` from the :class:`.MDODiscipline` and the :class:`.DesignSpace` defined above: .. GENERATED FROM PYTHON SOURCE LINES 88-93 .. code-block:: default scenario = create_scenario( discipline, "DisciplinaryOpt", "y", design_space, scenario_type="DOE" ) .. GENERATED FROM PYTHON SOURCE LINES 94-101 Execute the DOE scenario ------------------------ Lastly, we solve the :class:`.OptimizationProblem` included in the :class:`.DOEScenario` defined above by minimizing the objective function over a design of experiments included in the :class:`.DesignSpace`. Precisely, we choose a `full factorial design `_ of size :math:`11^2`: .. GENERATED FROM PYTHON SOURCE LINES 101-104 .. code-block:: default scenario.execute({"algo": "fullfact", "n_samples": 11 ** 2}) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none INFO - 12:56:28: INFO - 12:56:28: *** Start DOE Scenario execution *** INFO - 12:56:28: DOEScenario INFO - 12:56:28: Disciplines: AnalyticDiscipline INFO - 12:56:28: MDOFormulation: DisciplinaryOpt INFO - 12:56:28: Algorithm: fullfact INFO - 12:56:28: Optimization problem: INFO - 12:56:28: Minimize: y(x1, x2) INFO - 12:56:28: With respect to: x1, x2 INFO - 12:56:28: Full factorial design required. Number of samples along each direction for a design vector of size 2 with 121 samples: 11 INFO - 12:56:28: Final number of samples for DOE = 121 vs 121 requested INFO - 12:56:28: DOE sampling: 0%| | 0/121 [00:00Examples .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.093 seconds) .. _sphx_glr_download_examples_scenario_plot_doe_scenario.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_doe_scenario.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_doe_scenario.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_