Create a DOE Scenario

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()
<RootLogger root (INFO)>

Let \((P)\) be a simple optimization problem:

\[\begin{split}(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.\end{split}\]

In this example, we will see how to use GEMSEO to solve this problem \((P)\) by means of a Design Of Experiments (DOE)

Define the discipline

Firstly, by means of the create_discipline() API function, we create an MDODiscipline of AnalyticDiscipline type from a Python function:

expressions = {"y": "x1+x2"}
discipline = create_discipline("AnalyticDiscipline", expressions=expressions)

Now, we want to minimize this MDODiscipline over a design of experiments (DOE).

Define the design space

For that, by means of the create_design_space() API function, we define the DesignSpace \([-5, 5]\times[-5, 5]\) by using its DesignSpace.add_variable() method.

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")

Define the DOE scenario

Then, by means of the create_scenario() API function, we define a DOEScenario from the MDODiscipline and the DesignSpace defined above:

scenario = create_scenario(
    discipline, "DisciplinaryOpt", "y", design_space, scenario_type="DOE"
)

Execute the DOE scenario

Lastly, we solve the OptimizationProblem included in the DOEScenario defined above by minimizing the objective function over a design of experiments included in the DesignSpace. Precisely, we choose a full factorial design of size \(11^2\):

scenario.execute({"algo": "fullfact", "n_samples": 11**2})
    INFO - 08:23:29:
    INFO - 08:23:29: *** Start DOEScenario execution ***
    INFO - 08:23:29: DOEScenario
    INFO - 08:23:29:    Disciplines: AnalyticDiscipline
    INFO - 08:23:29:    MDO formulation: DisciplinaryOpt
    INFO - 08:23:29: Optimization problem:
    INFO - 08:23:29:    minimize y(x1, x2)
    INFO - 08:23:29:    with respect to x1, x2
    INFO - 08:23:29:    over the design space:
    INFO - 08:23:29:    +------+-------------+-------+-------------+---------+
    INFO - 08:23:29:    | name | lower_bound | value | upper_bound | type    |
    INFO - 08:23:29:    +------+-------------+-------+-------------+---------+
    INFO - 08:23:29:    | x1   |      -5     |  None |      5      | integer |
    INFO - 08:23:29:    | x2   |      -5     |  None |      5      | integer |
    INFO - 08:23:29:    +------+-------------+-------+-------------+---------+
    INFO - 08:23:29: Solving optimization problem with algorithm fullfact:
    INFO - 08:23:29: ...   0%|          | 0/121 [00:00<?, ?it]
    INFO - 08:23:29: ...   1%|          | 1/121 [00:00<00:00, 389.08 it/sec, obj=-10]
    INFO - 08:23:29: ...   2%|▏         | 2/121 [00:00<00:00, 610.12 it/sec, obj=-9]
    INFO - 08:23:29: ...   2%|▏         | 3/121 [00:00<00:00, 760.02 it/sec, obj=-8]
    INFO - 08:23:29: ...   3%|▎         | 4/121 [00:00<00:00, 868.52 it/sec, obj=-7]
    INFO - 08:23:29: ...   4%|▍         | 5/121 [00:00<00:00, 941.31 it/sec, obj=-6]
    INFO - 08:23:29: ...   5%|▍         | 6/121 [00:00<00:00, 999.48 it/sec, obj=-5]
    INFO - 08:23:29: ...   6%|▌         | 7/121 [00:00<00:00, 1049.70 it/sec, obj=-4]
    INFO - 08:23:29: ...   7%|▋         | 8/121 [00:00<00:00, 1090.60 it/sec, obj=-3]
    INFO - 08:23:29: ...   7%|▋         | 9/121 [00:00<00:00, 1125.05 it/sec, obj=-2]
    INFO - 08:23:29: ...   8%|▊         | 10/121 [00:00<00:00, 1154.57 it/sec, obj=-1]
    INFO - 08:23:29: ...   9%|▉         | 11/121 [00:00<00:00, 1175.59 it/sec, obj=0]
    INFO - 08:23:29: ...  10%|▉         | 12/121 [00:00<00:00, 1195.19 it/sec, obj=-9]
    INFO - 08:23:29: ...  11%|█         | 13/121 [00:00<00:00, 1214.49 it/sec, obj=-8]
    INFO - 08:23:29: ...  12%|█▏        | 14/121 [00:00<00:00, 1231.19 it/sec, obj=-7]
    INFO - 08:23:29: ...  12%|█▏        | 15/121 [00:00<00:00, 1246.25 it/sec, obj=-6]
    INFO - 08:23:29: ...  13%|█▎        | 16/121 [00:00<00:00, 1260.36 it/sec, obj=-5]
    INFO - 08:23:29: ...  14%|█▍        | 17/121 [00:00<00:00, 1268.04 it/sec, obj=-4]
    INFO - 08:23:29: ...  15%|█▍        | 18/121 [00:00<00:00, 1277.34 it/sec, obj=-3]
    INFO - 08:23:29: ...  16%|█▌        | 19/121 [00:00<00:00, 1287.45 it/sec, obj=-2]
    INFO - 08:23:29: ...  17%|█▋        | 20/121 [00:00<00:00, 1296.52 it/sec, obj=-1]
    INFO - 08:23:29: ...  17%|█▋        | 21/121 [00:00<00:00, 1305.05 it/sec, obj=0]
    INFO - 08:23:29: ...  18%|█▊        | 22/121 [00:00<00:00, 1310.98 it/sec, obj=1]
    INFO - 08:23:29: ...  19%|█▉        | 23/121 [00:00<00:00, 1317.76 it/sec, obj=-8]
    INFO - 08:23:29: ...  20%|█▉        | 24/121 [00:00<00:00, 1323.40 it/sec, obj=-7]
    INFO - 08:23:29: ...  21%|██        | 25/121 [00:00<00:00, 1329.84 it/sec, obj=-6]
    INFO - 08:23:29: ...  21%|██▏       | 26/121 [00:00<00:00, 1335.90 it/sec, obj=-5]
    INFO - 08:23:29: ...  22%|██▏       | 27/121 [00:00<00:00, 1341.48 it/sec, obj=-4]
    INFO - 08:23:29: ...  23%|██▎       | 28/121 [00:00<00:00, 1345.04 it/sec, obj=-3]
    INFO - 08:23:29: ...  24%|██▍       | 29/121 [00:00<00:00, 1350.01 it/sec, obj=-2]
    INFO - 08:23:29: ...  25%|██▍       | 30/121 [00:00<00:00, 1353.73 it/sec, obj=-1]
    INFO - 08:23:29: ...  26%|██▌       | 31/121 [00:00<00:00, 1358.12 it/sec, obj=0]
    INFO - 08:23:29: ...  26%|██▋       | 32/121 [00:00<00:00, 1362.38 it/sec, obj=1]
    INFO - 08:23:29: ...  27%|██▋       | 33/121 [00:00<00:00, 1366.41 it/sec, obj=2]
    INFO - 08:23:29: ...  28%|██▊       | 34/121 [00:00<00:00, 1368.56 it/sec, obj=-7]
    INFO - 08:23:29: ...  29%|██▉       | 35/121 [00:00<00:00, 1372.11 it/sec, obj=-6]
    INFO - 08:23:29: ...  30%|██▉       | 36/121 [00:00<00:00, 1374.79 it/sec, obj=-5]
    INFO - 08:23:29: ...  31%|███       | 37/121 [00:00<00:00, 1377.35 it/sec, obj=-4]
    INFO - 08:23:29: ...  31%|███▏      | 38/121 [00:00<00:00, 1380.23 it/sec, obj=-3]
    INFO - 08:23:29: ...  32%|███▏      | 39/121 [00:00<00:00, 1380.35 it/sec, obj=-2]
    INFO - 08:23:29: ...  33%|███▎      | 40/121 [00:00<00:00, 1381.84 it/sec, obj=-1]
    INFO - 08:23:29: ...  34%|███▍      | 41/121 [00:00<00:00, 1384.88 it/sec, obj=0]
    INFO - 08:23:29: ...  35%|███▍      | 42/121 [00:00<00:00, 1387.02 it/sec, obj=1]
    INFO - 08:23:29: ...  36%|███▌      | 43/121 [00:00<00:00, 1389.71 it/sec, obj=2]
    INFO - 08:23:29: ...  36%|███▋      | 44/121 [00:00<00:00, 1392.50 it/sec, obj=3]
    INFO - 08:23:29: ...  37%|███▋      | 45/121 [00:00<00:00, 1395.25 it/sec, obj=-6]
    INFO - 08:23:29: ...  38%|███▊      | 46/121 [00:00<00:00, 1396.20 it/sec, obj=-5]
    INFO - 08:23:29: ...  39%|███▉      | 47/121 [00:00<00:00, 1398.54 it/sec, obj=-4]
    INFO - 08:23:29: ...  40%|███▉      | 48/121 [00:00<00:00, 1400.20 it/sec, obj=-3]
    INFO - 08:23:29: ...  40%|████      | 49/121 [00:00<00:00, 1402.53 it/sec, obj=-2]
    INFO - 08:23:29: ...  41%|████▏     | 50/121 [00:00<00:00, 1404.73 it/sec, obj=-1]
    INFO - 08:23:29: ...  42%|████▏     | 51/121 [00:00<00:00, 1406.98 it/sec, obj=0]
    INFO - 08:23:29: ...  43%|████▎     | 52/121 [00:00<00:00, 1407.91 it/sec, obj=1]
    INFO - 08:23:29: ...  44%|████▍     | 53/121 [00:00<00:00, 1409.67 it/sec, obj=2]
    INFO - 08:23:29: ...  45%|████▍     | 54/121 [00:00<00:00, 1409.95 it/sec, obj=3]
    INFO - 08:23:29: ...  45%|████▌     | 55/121 [00:00<00:00, 1411.63 it/sec, obj=4]
    INFO - 08:23:29: ...  46%|████▋     | 56/121 [00:00<00:00, 1413.48 it/sec, obj=-5]
    INFO - 08:23:29: ...  47%|████▋     | 57/121 [00:00<00:00, 1415.17 it/sec, obj=-4]
    INFO - 08:23:29: ...  48%|████▊     | 58/121 [00:00<00:00, 1415.91 it/sec, obj=-3]
    INFO - 08:23:29: ...  49%|████▉     | 59/121 [00:00<00:00, 1417.60 it/sec, obj=-2]
    INFO - 08:23:29: ...  50%|████▉     | 60/121 [00:00<00:00, 1418.58 it/sec, obj=-1]
    INFO - 08:23:29: ...  50%|█████     | 61/121 [00:00<00:00, 1420.09 it/sec, obj=0]
    INFO - 08:23:29: ...  51%|█████     | 62/121 [00:00<00:00, 1421.63 it/sec, obj=1]
    INFO - 08:23:29: ...  52%|█████▏    | 63/121 [00:00<00:00, 1423.17 it/sec, obj=2]
    INFO - 08:23:29: ...  53%|█████▎    | 64/121 [00:00<00:00, 1423.65 it/sec, obj=3]
    INFO - 08:23:29: ...  54%|█████▎    | 65/121 [00:00<00:00, 1425.07 it/sec, obj=4]
    INFO - 08:23:29: ...  55%|█████▍    | 66/121 [00:00<00:00, 1425.93 it/sec, obj=5]
    INFO - 08:23:29: ...  55%|█████▌    | 67/121 [00:00<00:00, 1427.32 it/sec, obj=-4]
    INFO - 08:23:29: ...  56%|█████▌    | 68/121 [00:00<00:00, 1428.54 it/sec, obj=-3]
    INFO - 08:23:29: ...  57%|█████▋    | 69/121 [00:00<00:00, 1429.76 it/sec, obj=-2]
    INFO - 08:23:29: ...  58%|█████▊    | 70/121 [00:00<00:00, 1430.03 it/sec, obj=-1]
    INFO - 08:23:29: ...  59%|█████▊    | 71/121 [00:00<00:00, 1431.17 it/sec, obj=0]
    INFO - 08:23:29: ...  60%|█████▉    | 72/121 [00:00<00:00, 1431.88 it/sec, obj=1]
    INFO - 08:23:29: ...  60%|██████    | 73/121 [00:00<00:00, 1433.04 it/sec, obj=2]
    INFO - 08:23:29: ...  61%|██████    | 74/121 [00:00<00:00, 1434.17 it/sec, obj=3]
    INFO - 08:23:29: ...  62%|██████▏   | 75/121 [00:00<00:00, 1435.23 it/sec, obj=4]
    INFO - 08:23:29: ...  63%|██████▎   | 76/121 [00:00<00:00, 1435.39 it/sec, obj=5]
    INFO - 08:23:29: ...  64%|██████▎   | 77/121 [00:00<00:00, 1436.35 it/sec, obj=6]
    INFO - 08:23:29: ...  64%|██████▍   | 78/121 [00:00<00:00, 1435.82 it/sec, obj=-3]
    INFO - 08:23:29: ...  65%|██████▌   | 79/121 [00:00<00:00, 1436.79 it/sec, obj=-2]
    INFO - 08:23:29: ...  66%|██████▌   | 80/121 [00:00<00:00, 1437.82 it/sec, obj=-1]
    INFO - 08:23:29: ...  67%|██████▋   | 81/121 [00:00<00:00, 1438.84 it/sec, obj=0]
    INFO - 08:23:29: ...  68%|██████▊   | 82/121 [00:00<00:00, 1439.12 it/sec, obj=1]
    INFO - 08:23:29: ...  69%|██████▊   | 83/121 [00:00<00:00, 1440.03 it/sec, obj=2]
    INFO - 08:23:29: ...  69%|██████▉   | 84/121 [00:00<00:00, 1438.11 it/sec, obj=3]
    INFO - 08:23:29: ...  70%|███████   | 85/121 [00:00<00:00, 1438.97 it/sec, obj=4]
    INFO - 08:23:29: ...  71%|███████   | 86/121 [00:00<00:00, 1438.53 it/sec, obj=5]
    INFO - 08:23:29: ...  72%|███████▏  | 87/121 [00:00<00:00, 1439.36 it/sec, obj=6]
    INFO - 08:23:29: ...  73%|███████▎  | 88/121 [00:00<00:00, 1439.67 it/sec, obj=7]
    INFO - 08:23:29: ...  74%|███████▎  | 89/121 [00:00<00:00, 1440.60 it/sec, obj=-2]
    INFO - 08:23:29: ...  74%|███████▍  | 90/121 [00:00<00:00, 1440.98 it/sec, obj=-1]
    INFO - 08:23:29: ...  75%|███████▌  | 91/121 [00:00<00:00, 1441.93 it/sec, obj=0]
    INFO - 08:23:29: ...  76%|███████▌  | 92/121 [00:00<00:00, 1442.89 it/sec, obj=1]
    INFO - 08:23:29: ...  77%|███████▋  | 93/121 [00:00<00:00, 1443.73 it/sec, obj=2]
    INFO - 08:23:29: ...  78%|███████▊  | 94/121 [00:00<00:00, 1443.85 it/sec, obj=3]
    INFO - 08:23:29: ...  79%|███████▊  | 95/121 [00:00<00:00, 1444.58 it/sec, obj=4]
    INFO - 08:23:29: ...  79%|███████▉  | 96/121 [00:00<00:00, 1444.76 it/sec, obj=5]
    INFO - 08:23:29: ...  80%|████████  | 97/121 [00:00<00:00, 1445.40 it/sec, obj=6]
    INFO - 08:23:29: ...  81%|████████  | 98/121 [00:00<00:00, 1446.05 it/sec, obj=7]
    INFO - 08:23:29: ...  82%|████████▏ | 99/121 [00:00<00:00, 1446.77 it/sec, obj=8]
    INFO - 08:23:29: ...  83%|████████▎ | 100/121 [00:00<00:00, 1446.67 it/sec, obj=-1]
    INFO - 08:23:29: ...  83%|████████▎ | 101/121 [00:00<00:00, 1447.25 it/sec, obj=0]
    INFO - 08:23:29: ...  84%|████████▍ | 102/121 [00:00<00:00, 1447.47 it/sec, obj=1]
    INFO - 08:23:29: ...  85%|████████▌ | 103/121 [00:00<00:00, 1448.07 it/sec, obj=2]
    INFO - 08:23:29: ...  86%|████████▌ | 104/121 [00:00<00:00, 1448.78 it/sec, obj=3]
    INFO - 08:23:29: ...  87%|████████▋ | 105/121 [00:00<00:00, 1449.54 it/sec, obj=4]
    INFO - 08:23:29: ...  88%|████████▊ | 106/121 [00:00<00:00, 1449.69 it/sec, obj=5]
    INFO - 08:23:29: ...  88%|████████▊ | 107/121 [00:00<00:00, 1450.28 it/sec, obj=6]
    INFO - 08:23:29: ...  89%|████████▉ | 108/121 [00:00<00:00, 1450.54 it/sec, obj=7]
    INFO - 08:23:29: ...  90%|█████████ | 109/121 [00:00<00:00, 1451.05 it/sec, obj=8]
    INFO - 08:23:29: ...  91%|█████████ | 110/121 [00:00<00:00, 1451.66 it/sec, obj=9]
    INFO - 08:23:29: ...  92%|█████████▏| 111/121 [00:00<00:00, 1452.29 it/sec, obj=0]
    INFO - 08:23:29: ...  93%|█████████▎| 112/121 [00:00<00:00, 1452.37 it/sec, obj=1]
    INFO - 08:23:29: ...  93%|█████████▎| 113/121 [00:00<00:00, 1452.92 it/sec, obj=2]
    INFO - 08:23:29: ...  94%|█████████▍| 114/121 [00:00<00:00, 1453.11 it/sec, obj=3]
    INFO - 08:23:29: ...  95%|█████████▌| 115/121 [00:00<00:00, 1453.67 it/sec, obj=4]
    INFO - 08:23:29: ...  96%|█████████▌| 116/121 [00:00<00:00, 1454.21 it/sec, obj=5]
    INFO - 08:23:29: ...  97%|█████████▋| 117/121 [00:00<00:00, 1453.33 it/sec, obj=6]
    INFO - 08:23:29: ...  98%|█████████▊| 118/121 [00:00<00:00, 1453.26 it/sec, obj=7]
    INFO - 08:23:29: ...  98%|█████████▊| 119/121 [00:00<00:00, 1453.45 it/sec, obj=8]
    INFO - 08:23:29: ...  99%|█████████▉| 120/121 [00:00<00:00, 1453.92 it/sec, obj=9]
    INFO - 08:23:29: ... 100%|██████████| 121/121 [00:00<00:00, 1454.42 it/sec, obj=10]
    INFO - 08:23:29: Optimization result:
    INFO - 08:23:29:    Optimizer info:
    INFO - 08:23:29:       Status: None
    INFO - 08:23:29:       Message: None
    INFO - 08:23:29:       Number of calls to the objective function by the optimizer: 121
    INFO - 08:23:29:    Solution:
    INFO - 08:23:29:       Objective: -10.0
    INFO - 08:23:29:       Design space:
    INFO - 08:23:29:       +------+-------------+-------+-------------+---------+
    INFO - 08:23:29:       | name | lower_bound | value | upper_bound | type    |
    INFO - 08:23:29:       +------+-------------+-------+-------------+---------+
    INFO - 08:23:29:       | x1   |      -5     |   -5  |      5      | integer |
    INFO - 08:23:29:       | x2   |      -5     |   -5  |      5      | integer |
    INFO - 08:23:29:       +------+-------------+-------+-------------+---------+
    INFO - 08:23:29: *** End DOEScenario execution (time: 0:00:00.094239) ***

{'eval_jac': False, 'n_samples': 121, 'algo': 'fullfact'}

The optimum results can be found in the execution log. It is also possible to access them with Scenario.optimization_result:

optimization_result = scenario.optimization_result
f"The solution of P is (x*, f(x*)) = ({optimization_result.x_opt}, {optimization_result.f_opt})"
'The solution of P is (x*, f(x*)) = ([-5. -5.], -10.0)'

Available DOE algorithms

In order to get the list of available DOE algorithms, use:

get_available_doe_algorithms()
['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']

Available post-processing

In order to get the list of available post-processing algorithms, use:

get_available_post_processings()
['Animation', 'BasicHistory', 'Compromise', 'ConstraintsHistory', 'Correlations', 'GradientSensitivity', 'HighTradeOff', 'MultiObjectiveDiagram', 'ObjConstrHist', 'OptHistoryView', 'ParallelCoordinates', 'ParetoFront', 'Petal', 'QuadApprox', 'Radar', 'RadarChart', 'Robustness', 'SOM', 'ScatterPareto', 'ScatterPlotMatrix', 'TopologyView', 'VariableInfluence']

You can also look at the examples:

Total running time of the script: (0 minutes 0.106 seconds)

Gallery generated by Sphinx-Gallery