.. 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 :ref:`Go to the end ` 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-39 .. code-block:: Python from __future__ import annotations from gemseo import configure_logger from gemseo import create_design_space from gemseo import create_discipline from gemseo import create_scenario from gemseo import get_available_doe_algorithms from gemseo import get_available_post_processings configure_logger() .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 40-61 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 :func:`.create_discipline` API function, we create an :class:`.MDODiscipline` of :class:`.AnalyticDiscipline` type from a Python function: .. GENERATED FROM PYTHON SOURCE LINES 62-66 .. code-block:: Python expressions = {"y": "x1+x2"} discipline = create_discipline("AnalyticDiscipline", expressions=expressions) .. GENERATED FROM PYTHON SOURCE LINES 67-75 Now, we want to minimize this :class:`.MDODiscipline` over a design of experiments (DOE). Define the design space ----------------------- For that, by means of the :func:`.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 75-80 .. code-block:: Python design_space = create_design_space() design_space.add_variable("x1", l_b=-5, u_b=5, var_type="integer") design_space.add_variable("x2", l_b=-5, u_b=5, var_type="integer") .. GENERATED FROM PYTHON SOURCE LINES 81-86 Define the DOE scenario ----------------------- Then, by means of the :func:`.create_scenario` API function, we define a :class:`.DOEScenario` from the :class:`.MDODiscipline` and the :class:`.DesignSpace` defined above: .. GENERATED FROM PYTHON SOURCE LINES 86-91 .. code-block:: Python scenario = create_scenario( discipline, "DisciplinaryOpt", "y", design_space, scenario_type="DOE" ) .. GENERATED FROM PYTHON SOURCE LINES 92-99 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 99-102 .. code-block:: Python scenario.execute({"algo": "fullfact", "n_samples": 11**2}) .. rst-class:: sphx-glr-script-out .. code-block:: none INFO - 13:54:39: INFO - 13:54:39: *** Start DOEScenario execution *** INFO - 13:54:39: DOEScenario INFO - 13:54:39: Disciplines: AnalyticDiscipline INFO - 13:54:39: MDO formulation: DisciplinaryOpt INFO - 13:54:39: Optimization problem: INFO - 13:54:39: minimize y(x1, x2) INFO - 13:54:39: with respect to x1, x2 INFO - 13:54:39: over the design space: INFO - 13:54:39: +------+-------------+-------+-------------+---------+ INFO - 13:54:39: | Name | Lower bound | Value | Upper bound | Type | INFO - 13:54:39: +------+-------------+-------+-------------+---------+ INFO - 13:54:39: | x1 | -5 | None | 5 | integer | INFO - 13:54:39: | x2 | -5 | None | 5 | integer | INFO - 13:54:39: +------+-------------+-------+-------------+---------+ INFO - 13:54:39: Solving optimization problem with algorithm fullfact: INFO - 13:54:39: 1%| | 1/121 [00:00<00:00, 403.45 it/sec, obj=-10] INFO - 13:54:39: 2%|▏ | 2/121 [00:00<00:00, 635.21 it/sec, obj=-9] INFO - 13:54:39: 2%|▏ | 3/121 [00:00<00:00, 797.80 it/sec, obj=-8] INFO - 13:54:39: 3%|▎ | 4/121 [00:00<00:00, 918.65 it/sec, obj=-7] INFO - 13:54:39: 4%|▍ | 5/121 [00:00<00:00, 1010.58 it/sec, obj=-6] INFO - 13:54:39: 5%|▍ | 6/121 [00:00<00:00, 1083.10 it/sec, obj=-5] INFO - 13:54:39: 6%|▌ | 7/121 [00:00<00:00, 1130.32 it/sec, obj=-4] INFO - 13:54:39: 7%|▋ | 8/121 [00:00<00:00, 1177.43 it/sec, obj=-3] INFO - 13:54:39: 7%|▋ | 9/121 [00:00<00:00, 1218.84 it/sec, obj=-2] INFO - 13:54:39: 8%|▊ | 10/121 [00:00<00:00, 1254.54 it/sec, obj=-1] INFO - 13:54:39: 9%|▉ | 11/121 [00:00<00:00, 1285.66 it/sec, obj=0] INFO - 13:54:39: 10%|▉ | 12/121 [00:00<00:00, 1312.87 it/sec, obj=-9] INFO - 13:54:39: 11%|█ | 13/121 [00:00<00:00, 1336.81 it/sec, obj=-8] INFO - 13:54:39: 12%|█▏ | 14/121 [00:00<00:00, 1351.16 it/sec, obj=-7] INFO - 13:54:39: 12%|█▏ | 15/121 [00:00<00:00, 1369.49 it/sec, obj=-6] INFO - 13:54:39: 13%|█▎ | 16/121 [00:00<00:00, 1386.92 it/sec, obj=-5] INFO - 13:54:39: 14%|█▍ | 17/121 [00:00<00:00, 1402.34 it/sec, obj=-4] INFO - 13:54:39: 15%|█▍ | 18/121 [00:00<00:00, 1416.06 it/sec, obj=-3] INFO - 13:54:39: 16%|█▌ | 19/121 [00:00<00:00, 1428.53 it/sec, obj=-2] INFO - 13:54:39: 17%|█▋ | 20/121 [00:00<00:00, 1439.83 it/sec, obj=-1] INFO - 13:54:39: 17%|█▋ | 21/121 [00:00<00:00, 1431.97 it/sec, obj=0] INFO - 13:54:39: 18%|█▊ | 22/121 [00:00<00:00, 1440.40 it/sec, obj=1] INFO - 13:54:39: 19%|█▉ | 23/121 [00:00<00:00, 1449.14 it/sec, obj=-8] INFO - 13:54:39: 20%|█▉ | 24/121 [00:00<00:00, 1457.75 it/sec, obj=-7] INFO - 13:54:39: 21%|██ | 25/121 [00:00<00:00, 1465.62 it/sec, obj=-6] INFO - 13:54:39: 21%|██▏ | 26/121 [00:00<00:00, 1473.46 it/sec, obj=-5] INFO - 13:54:39: 22%|██▏ | 27/121 [00:00<00:00, 1476.98 it/sec, obj=-4] INFO - 13:54:39: 23%|██▎ | 28/121 [00:00<00:00, 1483.30 it/sec, obj=-3] INFO - 13:54:39: 24%|██▍ | 29/121 [00:00<00:00, 1489.95 it/sec, obj=-2] INFO - 13:54:39: 25%|██▍ | 30/121 [00:00<00:00, 1495.94 it/sec, obj=-1] INFO - 13:54:39: 26%|██▌ | 31/121 [00:00<00:00, 1501.72 it/sec, obj=0] INFO - 13:54:39: 26%|██▋ | 32/121 [00:00<00:00, 1507.03 it/sec, obj=1] INFO - 13:54:39: 27%|██▋ | 33/121 [00:00<00:00, 1512.15 it/sec, obj=2] INFO - 13:54:39: 28%|██▊ | 34/121 [00:00<00:00, 1512.05 it/sec, obj=-7] INFO - 13:54:39: 29%|██▉ | 35/121 [00:00<00:00, 1515.88 it/sec, obj=-6] INFO - 13:54:39: 30%|██▉ | 36/121 [00:00<00:00, 1520.12 it/sec, obj=-5] INFO - 13:54:39: 31%|███ | 37/121 [00:00<00:00, 1524.27 it/sec, obj=-4] INFO - 13:54:39: 31%|███▏ | 38/121 [00:00<00:00, 1524.63 it/sec, obj=-3] INFO - 13:54:39: 32%|███▏ | 39/121 [00:00<00:00, 1528.51 it/sec, obj=-2] INFO - 13:54:39: 33%|███▎ | 40/121 [00:00<00:00, 1529.85 it/sec, obj=-1] INFO - 13:54:39: 34%|███▍ | 41/121 [00:00<00:00, 1532.90 it/sec, obj=0] INFO - 13:54:39: 35%|███▍ | 42/121 [00:00<00:00, 1536.35 it/sec, obj=1] INFO - 13:54:39: 36%|███▌ | 43/121 [00:00<00:00, 1539.50 it/sec, obj=2] INFO - 13:54:39: 36%|███▋ | 44/121 [00:00<00:00, 1542.87 it/sec, obj=3] INFO - 13:54:39: 37%|███▋ | 45/121 [00:00<00:00, 1546.00 it/sec, obj=-6] INFO - 13:54:39: 38%|███▊ | 46/121 [00:00<00:00, 1549.04 it/sec, obj=-5] INFO - 13:54:39: 39%|███▉ | 47/121 [00:00<00:00, 1549.50 it/sec, obj=-4] INFO - 13:54:39: 40%|███▉ | 48/121 [00:00<00:00, 1552.02 it/sec, obj=-3] INFO - 13:54:39: 40%|████ | 49/121 [00:00<00:00, 1554.68 it/sec, obj=-2] INFO - 13:54:39: 41%|████▏ | 50/121 [00:00<00:00, 1555.54 it/sec, obj=-1] INFO - 13:54:39: 42%|████▏ | 51/121 [00:00<00:00, 1555.45 it/sec, obj=0] INFO - 13:54:39: 43%|████▎ | 52/121 [00:00<00:00, 1557.38 it/sec, obj=1] INFO - 13:54:39: 44%|████▍ | 53/121 [00:00<00:00, 1558.40 it/sec, obj=2] INFO - 13:54:39: 45%|████▍ | 54/121 [00:00<00:00, 1559.70 it/sec, obj=3] INFO - 13:54:39: 45%|████▌ | 55/121 [00:00<00:00, 1561.82 it/sec, obj=4] INFO - 13:54:39: 46%|████▋ | 56/121 [00:00<00:00, 1564.18 it/sec, obj=-5] INFO - 13:54:39: 47%|████▋ | 57/121 [00:00<00:00, 1566.54 it/sec, obj=-4] INFO - 13:54:39: 48%|████▊ | 58/121 [00:00<00:00, 1568.70 it/sec, obj=-3] INFO - 13:54:39: 49%|████▉ | 59/121 [00:00<00:00, 1570.93 it/sec, obj=-2] INFO - 13:54:39: 50%|████▉ | 60/121 [00:00<00:00, 1571.13 it/sec, obj=-1] INFO - 13:54:39: 50%|█████ | 61/121 [00:00<00:00, 1572.69 it/sec, obj=0] INFO - 13:54:39: 51%|█████ | 62/121 [00:00<00:00, 1574.50 it/sec, obj=1] INFO - 13:54:39: 52%|█████▏ | 63/121 [00:00<00:00, 1576.31 it/sec, obj=2] INFO - 13:54:39: 53%|█████▎ | 64/121 [00:00<00:00, 1578.07 it/sec, obj=3] INFO - 13:54:39: 54%|█████▎ | 65/121 [00:00<00:00, 1579.78 it/sec, obj=4] INFO - 13:54:39: 55%|█████▍ | 66/121 [00:00<00:00, 1581.33 it/sec, obj=5] INFO - 13:54:39: 55%|█████▌ | 67/121 [00:00<00:00, 1581.06 it/sec, obj=-4] INFO - 13:54:39: 56%|█████▌ | 68/121 [00:00<00:00, 1581.43 it/sec, obj=-3] INFO - 13:54:39: 57%|█████▋ | 69/121 [00:00<00:00, 1582.87 it/sec, obj=-2] INFO - 13:54:39: 58%|█████▊ | 70/121 [00:00<00:00, 1584.35 it/sec, obj=-1] INFO - 13:54:39: 59%|█████▊ | 71/121 [00:00<00:00, 1585.78 it/sec, obj=0] INFO - 13:54:39: 60%|█████▉ | 72/121 [00:00<00:00, 1587.25 it/sec, obj=1] INFO - 13:54:39: 60%|██████ | 73/121 [00:00<00:00, 1587.61 it/sec, obj=2] INFO - 13:54:39: 61%|██████ | 74/121 [00:00<00:00, 1587.91 it/sec, obj=3] INFO - 13:54:39: 62%|██████▏ | 75/121 [00:00<00:00, 1589.14 it/sec, obj=4] INFO - 13:54:39: 63%|██████▎ | 76/121 [00:00<00:00, 1590.52 it/sec, obj=5] INFO - 13:54:39: 64%|██████▎ | 77/121 [00:00<00:00, 1591.81 it/sec, obj=6] INFO - 13:54:39: 64%|██████▍ | 78/121 [00:00<00:00, 1593.06 it/sec, obj=-3] INFO - 13:54:39: 65%|██████▌ | 79/121 [00:00<00:00, 1594.42 it/sec, obj=-2] INFO - 13:54:39: 66%|██████▌ | 80/121 [00:00<00:00, 1594.00 it/sec, obj=-1] INFO - 13:54:39: 67%|██████▋ | 81/121 [00:00<00:00, 1594.96 it/sec, obj=0] INFO - 13:54:39: 68%|██████▊ | 82/121 [00:00<00:00, 1596.15 it/sec, obj=1] INFO - 13:54:39: 69%|██████▊ | 83/121 [00:00<00:00, 1597.35 it/sec, obj=2] INFO - 13:54:39: 69%|██████▉ | 84/121 [00:00<00:00, 1598.52 it/sec, obj=3] INFO - 13:54:39: 70%|███████ | 85/121 [00:00<00:00, 1599.65 it/sec, obj=4] INFO - 13:54:39: 71%|███████ | 86/121 [00:00<00:00, 1600.74 it/sec, obj=5] INFO - 13:54:39: 72%|███████▏ | 87/121 [00:00<00:00, 1597.43 it/sec, obj=6] INFO - 13:54:39: 73%|███████▎ | 88/121 [00:00<00:00, 1598.17 it/sec, obj=7] INFO - 13:54:39: 74%|███████▎ | 89/121 [00:00<00:00, 1599.05 it/sec, obj=-2] INFO - 13:54:39: 74%|███████▍ | 90/121 [00:00<00:00, 1599.98 it/sec, obj=-1] INFO - 13:54:39: 75%|███████▌ | 91/121 [00:00<00:00, 1601.03 it/sec, obj=0] INFO - 13:54:39: 76%|███████▌ | 92/121 [00:00<00:00, 1602.02 it/sec, obj=1] INFO - 13:54:39: 77%|███████▋ | 93/121 [00:00<00:00, 1602.23 it/sec, obj=2] INFO - 13:54:39: 78%|███████▊ | 94/121 [00:00<00:00, 1602.58 it/sec, obj=3] INFO - 13:54:39: 79%|███████▊ | 95/121 [00:00<00:00, 1603.44 it/sec, obj=4] INFO - 13:54:39: 79%|███████▉ | 96/121 [00:00<00:00, 1604.43 it/sec, obj=5] INFO - 13:54:39: 80%|████████ | 97/121 [00:00<00:00, 1605.39 it/sec, obj=6] INFO - 13:54:39: 81%|████████ | 98/121 [00:00<00:00, 1606.40 it/sec, obj=7] INFO - 13:54:39: 82%|████████▏ | 99/121 [00:00<00:00, 1607.36 it/sec, obj=8] INFO - 13:54:39: 83%|████████▎ | 100/121 [00:00<00:00, 1607.13 it/sec, obj=-1] INFO - 13:54:39: 83%|████████▎ | 101/121 [00:00<00:00, 1607.79 it/sec, obj=0] INFO - 13:54:39: 84%|████████▍ | 102/121 [00:00<00:00, 1608.66 it/sec, obj=1] INFO - 13:54:39: 85%|████████▌ | 103/121 [00:00<00:00, 1609.48 it/sec, obj=2] INFO - 13:54:39: 86%|████████▌ | 104/121 [00:00<00:00, 1610.32 it/sec, obj=3] INFO - 13:54:39: 87%|████████▋ | 105/121 [00:00<00:00, 1611.12 it/sec, obj=4] INFO - 13:54:39: 88%|████████▊ | 106/121 [00:00<00:00, 1611.90 it/sec, obj=5] INFO - 13:54:39: 88%|████████▊ | 107/121 [00:00<00:00, 1611.62 it/sec, obj=6] INFO - 13:54:39: 89%|████████▉ | 108/121 [00:00<00:00, 1612.32 it/sec, obj=7] INFO - 13:54:39: 90%|█████████ | 109/121 [00:00<00:00, 1613.01 it/sec, obj=8] INFO - 13:54:39: 91%|█████████ | 110/121 [00:00<00:00, 1613.71 it/sec, obj=9] INFO - 13:54:39: 92%|█████████▏| 111/121 [00:00<00:00, 1614.50 it/sec, obj=0] INFO - 13:54:39: 93%|█████████▎| 112/121 [00:00<00:00, 1615.25 it/sec, obj=1] INFO - 13:54:39: 93%|█████████▎| 113/121 [00:00<00:00, 1615.44 it/sec, obj=2] INFO - 13:54:39: 94%|█████████▍| 114/121 [00:00<00:00, 1615.60 it/sec, obj=3] INFO - 13:54:39: 95%|█████████▌| 115/121 [00:00<00:00, 1613.51 it/sec, obj=4] INFO - 13:54:39: 96%|█████████▌| 116/121 [00:00<00:00, 1612.29 it/sec, obj=5] INFO - 13:54:39: 97%|█████████▋| 117/121 [00:00<00:00, 1607.76 it/sec, obj=6] INFO - 13:54:39: 98%|█████████▊| 118/121 [00:00<00:00, 1608.01 it/sec, obj=7] INFO - 13:54:39: 98%|█████████▊| 119/121 [00:00<00:00, 1607.97 it/sec, obj=8] INFO - 13:54:39: 99%|█████████▉| 120/121 [00:00<00:00, 1608.11 it/sec, obj=9] INFO - 13:54:39: 100%|██████████| 121/121 [00:00<00:00, 1608.63 it/sec, obj=10] INFO - 13:54:39: Optimization result: INFO - 13:54:39: Optimizer info: INFO - 13:54:39: Status: None INFO - 13:54:39: Message: None INFO - 13:54:39: Number of calls to the objective function by the optimizer: 121 INFO - 13:54:39: Solution: INFO - 13:54:39: Objective: -10.0 INFO - 13:54:39: Design space: INFO - 13:54:39: +------+-------------+-------+-------------+---------+ INFO - 13:54:39: | Name | Lower bound | Value | Upper bound | Type | INFO - 13:54:39: +------+-------------+-------+-------------+---------+ INFO - 13:54:39: | x1 | -5 | -5 | 5 | integer | INFO - 13:54:39: | x2 | -5 | -5 | 5 | integer | INFO - 13:54:39: +------+-------------+-------+-------------+---------+ INFO - 13:54:39: *** End DOEScenario execution (time: 0:00:00.087691) *** {'eval_jac': False, 'n_samples': 121, 'algo': 'fullfact'} .. GENERATED FROM PYTHON SOURCE LINES 103-105 The optimum results can be found in the execution log. It is also possible to access them with :attr:`.Scenario.optimization_result`: .. GENERATED FROM PYTHON SOURCE LINES 105-109 .. code-block:: Python optimization_result = scenario.optimization_result f"The solution of P is (x*, f(x*)) = ({optimization_result.x_opt}, {optimization_result.f_opt})" .. rst-class:: sphx-glr-script-out .. code-block:: none 'The solution of P is (x*, f(x*)) = ([-5. -5.], -10.0)' .. GENERATED FROM PYTHON SOURCE LINES 110-113 Available DOE algorithms ------------------------ In order to get the list of available DOE algorithms, use: .. GENERATED FROM PYTHON SOURCE LINES 113-115 .. code-block:: Python get_available_doe_algorithms() .. rst-class:: sphx-glr-script-out .. code-block:: none ['CustomDOE', 'DiagonalDOE', 'OT_SOBOL', 'OT_RANDOM', 'OT_HASELGROVE', 'OT_REVERSE_HALTON', 'OT_HALTON', 'OT_FAURE', 'OT_MONTE_CARLO', 'OT_FACTORIAL', 'OT_COMPOSITE', 'OT_AXIAL', 'OT_OPT_LHS', 'OT_LHS', 'OT_LHSC', 'OT_FULLFACT', 'OT_SOBOL_INDICES', 'fullfact', 'ff2n', 'pbdesign', 'bbdesign', 'ccdesign', 'lhs', 'Halton', 'LHS', 'MC', 'PoissonDisk', 'Sobol'] .. GENERATED FROM PYTHON SOURCE LINES 116-119 Available post-processing ------------------------- In order to get the list of available post-processing algorithms, use: .. GENERATED FROM PYTHON SOURCE LINES 119-121 .. code-block:: Python get_available_post_processings() .. rst-class:: sphx-glr-script-out .. code-block:: none ['Animation', 'BasicHistory', 'Compromise', 'ConstraintsHistory', 'Correlations', 'DataVersusModel', 'GradientSensitivity', 'HighTradeOff', 'MultiObjectiveDiagram', 'ObjConstrHist', 'OptHistoryView', 'ParallelCoordinates', 'ParetoFront', 'Petal', 'QuadApprox', 'Radar', 'RadarChart', 'Robustness', 'SOM', 'ScatterPareto', 'ScatterPlotMatrix', 'TopologyView', 'VariableInfluence'] .. GENERATED FROM PYTHON SOURCE LINES 122-128 You can also look at the examples: .. raw:: html
Examples
.. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.101 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-jupyter :download:`Download Jupyter notebook: plot_doe_scenario.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_doe_scenario.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_