.. 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 26-38 .. code-block:: default from __future__ import annotations from gemseo.api import configure_logger from gemseo.api import create_design_space from gemseo.api import create_discipline from gemseo.api import create_scenario from gemseo.api import get_available_doe_algorithms from gemseo.api import get_available_post_processings configure_logger() .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 39-60 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 61-65 .. code-block:: default expressions = {"y": "x1+x2"} discipline = create_discipline("AnalyticDiscipline", expressions=expressions) .. GENERATED FROM PYTHON SOURCE LINES 66-74 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 74-79 .. 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 80-85 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 85-90 .. code-block:: default scenario = create_scenario( discipline, "DisciplinaryOpt", "y", design_space, scenario_type="DOE" ) .. GENERATED FROM PYTHON SOURCE LINES 91-98 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 98-101 .. code-block:: default scenario.execute({"algo": "fullfact", "n_samples": 11**2}) .. rst-class:: sphx-glr-script-out .. code-block:: none INFO - 14:46:11: INFO - 14:46:11: *** Start DOEScenario execution *** INFO - 14:46:11: DOEScenario INFO - 14:46:11: Disciplines: AnalyticDiscipline INFO - 14:46:11: MDO formulation: DisciplinaryOpt INFO - 14:46:11: Optimization problem: INFO - 14:46:11: minimize y(x1, x2) INFO - 14:46:11: with respect to x1, x2 INFO - 14:46:11: over the design space: INFO - 14:46:11: +------+-------------+-------+-------------+---------+ INFO - 14:46:11: | name | lower_bound | value | upper_bound | type | INFO - 14:46:11: +------+-------------+-------+-------------+---------+ INFO - 14:46:11: | x1 | -5 | None | 5 | integer | INFO - 14:46:11: | x2 | -5 | None | 5 | integer | INFO - 14:46:11: +------+-------------+-------+-------------+---------+ INFO - 14:46:11: Solving optimization problem with algorithm fullfact: INFO - 14:46:11: ... 0%| | 0/121 [00:00Examples .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.065 seconds) .. _sphx_glr_download_examples_scenario_plot_doe_scenario.py: .. only:: html .. container:: sphx-glr-footer 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 `_