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 - 13:51:11:
    INFO - 13:51:11: *** Start DOEScenario execution ***
    INFO - 13:51:11: DOEScenario
    INFO - 13:51:11:    Disciplines: AnalyticDiscipline
    INFO - 13:51:11:    MDO formulation: DisciplinaryOpt
    INFO - 13:51:11: Optimization problem:
    INFO - 13:51:11:    minimize y(x1, x2)
    INFO - 13:51:11:    with respect to x1, x2
    INFO - 13:51:11:    over the design space:
    INFO - 13:51:11:    +------+-------------+-------+-------------+---------+
    INFO - 13:51:11:    | name | lower_bound | value | upper_bound | type    |
    INFO - 13:51:11:    +------+-------------+-------+-------------+---------+
    INFO - 13:51:11:    | x1   |      -5     |  None |      5      | integer |
    INFO - 13:51:11:    | x2   |      -5     |  None |      5      | integer |
    INFO - 13:51:11:    +------+-------------+-------+-------------+---------+
    INFO - 13:51:11: Solving optimization problem with algorithm fullfact:
    INFO - 13:51:11: ...   0%|          | 0/121 [00:00<?, ?it]
    INFO - 13:51:11: ...   1%|          | 1/121 [00:00<00:00, 324.18 it/sec, obj=-10]
    INFO - 13:51:11: ...   2%|▏         | 2/121 [00:00<00:00, 492.32 it/sec, obj=-9]
    INFO - 13:51:11: ...   2%|▏         | 3/121 [00:00<00:00, 605.82 it/sec, obj=-8]
    INFO - 13:51:11: ...   3%|▎         | 4/121 [00:00<00:00, 697.25 it/sec, obj=-7]
    INFO - 13:51:11: ...   4%|▍         | 5/121 [00:00<00:00, 763.52 it/sec, obj=-6]
    INFO - 13:51:11: ...   5%|▍         | 6/121 [00:00<00:00, 821.90 it/sec, obj=-5]
    INFO - 13:51:11: ...   6%|▌         | 7/121 [00:00<00:00, 870.37 it/sec, obj=-4]
    INFO - 13:51:11: ...   7%|▋         | 8/121 [00:00<00:00, 908.47 it/sec, obj=-3]
    INFO - 13:51:11: ...   7%|▋         | 9/121 [00:00<00:00, 942.66 it/sec, obj=-2]
    INFO - 13:51:11: ...   8%|▊         | 10/121 [00:00<00:00, 965.78 it/sec, obj=-1]
    INFO - 13:51:11: ...   9%|▉         | 11/121 [00:00<00:00, 991.14 it/sec, obj=0]
    INFO - 13:51:11: ...  10%|▉         | 12/121 [00:00<00:00, 1013.52 it/sec, obj=-9]
    INFO - 13:51:11: ...  11%|█         | 13/121 [00:00<00:00, 1031.91 it/sec, obj=-8]
    INFO - 13:51:11: ...  12%|█▏        | 14/121 [00:00<00:00, 1049.74 it/sec, obj=-7]
    INFO - 13:51:11: ...  12%|█▏        | 15/121 [00:00<00:00, 1062.78 it/sec, obj=-6]
    INFO - 13:51:11: ...  13%|█▎        | 16/121 [00:00<00:00, 1076.19 it/sec, obj=-5]
    INFO - 13:51:11: ...  14%|█▍        | 17/121 [00:00<00:00, 1087.78 it/sec, obj=-4]
    INFO - 13:51:11: ...  15%|█▍        | 18/121 [00:00<00:00, 1096.66 it/sec, obj=-3]
    INFO - 13:51:11: ...  16%|█▌        | 19/121 [00:00<00:00, 1106.60 it/sec, obj=-2]
    INFO - 13:51:11: ...  17%|█▋        | 20/121 [00:00<00:00, 1114.10 it/sec, obj=-1]
    INFO - 13:51:11: ...  17%|█▋        | 21/121 [00:00<00:00, 1120.70 it/sec, obj=0]
    INFO - 13:51:11: ...  18%|█▊        | 22/121 [00:00<00:00, 1127.58 it/sec, obj=1]
    INFO - 13:51:11: ...  19%|█▉        | 23/121 [00:00<00:00, 1131.91 it/sec, obj=-8]
    INFO - 13:51:11: ...  20%|█▉        | 24/121 [00:00<00:00, 1138.38 it/sec, obj=-7]
    INFO - 13:51:11: ...  21%|██        | 25/121 [00:00<00:00, 1144.25 it/sec, obj=-6]
    INFO - 13:51:11: ...  21%|██▏       | 26/121 [00:00<00:00, 1148.53 it/sec, obj=-5]
    INFO - 13:51:11: ...  22%|██▏       | 27/121 [00:00<00:00, 1154.37 it/sec, obj=-4]
    INFO - 13:51:11: ...  23%|██▎       | 28/121 [00:00<00:00, 1160.10 it/sec, obj=-3]
    INFO - 13:51:11: ...  24%|██▍       | 29/121 [00:00<00:00, 1164.46 it/sec, obj=-2]
    INFO - 13:51:11: ...  25%|██▍       | 30/121 [00:00<00:00, 1168.99 it/sec, obj=-1]
    INFO - 13:51:11: ...  26%|██▌       | 31/121 [00:00<00:00, 1172.26 it/sec, obj=0]
    INFO - 13:51:11: ...  26%|██▋       | 32/121 [00:00<00:00, 1176.87 it/sec, obj=1]
    INFO - 13:51:11: ...  27%|██▋       | 33/121 [00:00<00:00, 1180.76 it/sec, obj=2]
    INFO - 13:51:11: ...  28%|██▊       | 34/121 [00:00<00:00, 1183.87 it/sec, obj=-7]
    INFO - 13:51:11: ...  29%|██▉       | 35/121 [00:00<00:00, 1186.50 it/sec, obj=-6]
    INFO - 13:51:11: ...  30%|██▉       | 36/121 [00:00<00:00, 1188.42 it/sec, obj=-5]
    INFO - 13:51:11: ...  31%|███       | 37/121 [00:00<00:00, 1191.94 it/sec, obj=-4]
    INFO - 13:51:11: ...  31%|███▏      | 38/121 [00:00<00:00, 1194.91 it/sec, obj=-3]
    INFO - 13:51:11: ...  32%|███▏      | 39/121 [00:00<00:00, 1197.33 it/sec, obj=-2]
    INFO - 13:51:11: ...  33%|███▎      | 40/121 [00:00<00:00, 1200.52 it/sec, obj=-1]
    INFO - 13:51:11: ...  34%|███▍      | 41/121 [00:00<00:00, 1201.65 it/sec, obj=0]
    INFO - 13:51:11: ...  35%|███▍      | 42/121 [00:00<00:00, 1204.36 it/sec, obj=1]
    INFO - 13:51:11: ...  36%|███▌      | 43/121 [00:00<00:00, 1206.74 it/sec, obj=2]
    INFO - 13:51:11: ...  36%|███▋      | 44/121 [00:00<00:00, 1208.83 it/sec, obj=3]
    INFO - 13:51:11: ...  37%|███▋      | 45/121 [00:00<00:00, 1211.54 it/sec, obj=-6]
    INFO - 13:51:11: ...  38%|███▊      | 46/121 [00:00<00:00, 1214.16 it/sec, obj=-5]
    INFO - 13:51:11: ...  39%|███▉      | 47/121 [00:00<00:00, 1215.14 it/sec, obj=-4]
    INFO - 13:51:11: ...  40%|███▉      | 48/121 [00:00<00:00, 1217.16 it/sec, obj=-3]
    INFO - 13:51:11: ...  40%|████      | 49/121 [00:00<00:00, 1219.25 it/sec, obj=-2]
    INFO - 13:51:11: ...  41%|████▏     | 50/121 [00:00<00:00, 1221.43 it/sec, obj=-1]
    INFO - 13:51:11: ...  42%|████▏     | 51/121 [00:00<00:00, 1223.94 it/sec, obj=0]
    INFO - 13:51:11: ...  43%|████▎     | 52/121 [00:00<00:00, 1225.30 it/sec, obj=1]
    INFO - 13:51:11: ...  44%|████▍     | 53/121 [00:00<00:00, 1227.38 it/sec, obj=2]
    INFO - 13:51:11: ...  45%|████▍     | 54/121 [00:00<00:00, 1229.47 it/sec, obj=3]
    INFO - 13:51:11: ...  45%|████▌     | 55/121 [00:00<00:00, 1230.76 it/sec, obj=4]
    INFO - 13:51:11: ...  46%|████▋     | 56/121 [00:00<00:00, 1232.07 it/sec, obj=-5]
    INFO - 13:51:11: ...  47%|████▋     | 57/121 [00:00<00:00, 1232.79 it/sec, obj=-4]
    INFO - 13:51:11: ...  48%|████▊     | 58/121 [00:00<00:00, 1234.62 it/sec, obj=-3]
    INFO - 13:51:11: ...  49%|████▉     | 59/121 [00:00<00:00, 1236.15 it/sec, obj=-2]
    INFO - 13:51:11: ...  50%|████▉     | 60/121 [00:00<00:00, 1237.46 it/sec, obj=-1]
    INFO - 13:51:11: ...  50%|█████     | 61/121 [00:00<00:00, 1239.13 it/sec, obj=0]
    INFO - 13:51:11: ...  51%|█████     | 62/121 [00:00<00:00, 1240.10 it/sec, obj=1]
    INFO - 13:51:11: ...  52%|█████▏    | 63/121 [00:00<00:00, 1241.69 it/sec, obj=2]
    INFO - 13:51:11: ...  53%|█████▎    | 64/121 [00:00<00:00, 1243.34 it/sec, obj=3]
    INFO - 13:51:11: ...  54%|█████▎    | 65/121 [00:00<00:00, 1244.60 it/sec, obj=4]
    INFO - 13:51:11: ...  55%|█████▍    | 66/121 [00:00<00:00, 1246.07 it/sec, obj=5]
    INFO - 13:51:11: ...  55%|█████▌    | 67/121 [00:00<00:00, 1247.55 it/sec, obj=-4]
    INFO - 13:51:11: ...  56%|█████▌    | 68/121 [00:00<00:00, 1248.13 it/sec, obj=-3]
    INFO - 13:51:11: ...  57%|█████▋    | 69/121 [00:00<00:00, 1249.50 it/sec, obj=-2]
    INFO - 13:51:11: ...  58%|█████▊    | 70/121 [00:00<00:00, 1250.85 it/sec, obj=-1]
    INFO - 13:51:11: ...  59%|█████▊    | 71/121 [00:00<00:00, 1251.77 it/sec, obj=0]
    INFO - 13:51:11: ...  60%|█████▉    | 72/121 [00:00<00:00, 1253.01 it/sec, obj=1]
    INFO - 13:51:11: ...  60%|██████    | 73/121 [00:00<00:00, 1253.27 it/sec, obj=2]
    INFO - 13:51:11: ...  61%|██████    | 74/121 [00:00<00:00, 1254.55 it/sec, obj=3]
    INFO - 13:51:11: ...  62%|██████▏   | 75/121 [00:00<00:00, 1255.70 it/sec, obj=4]
    INFO - 13:51:11: ...  63%|██████▎   | 76/121 [00:00<00:00, 1256.34 it/sec, obj=5]
    INFO - 13:51:11: ...  64%|██████▎   | 77/121 [00:00<00:00, 1257.20 it/sec, obj=6]
    INFO - 13:51:11: ...  64%|██████▍   | 78/121 [00:00<00:00, 1257.70 it/sec, obj=-3]
    INFO - 13:51:11: ...  65%|██████▌   | 79/121 [00:00<00:00, 1258.79 it/sec, obj=-2]
    INFO - 13:51:11: ...  66%|██████▌   | 80/121 [00:00<00:00, 1259.88 it/sec, obj=-1]
    INFO - 13:51:11: ...  67%|██████▋   | 81/121 [00:00<00:00, 1260.53 it/sec, obj=0]
    INFO - 13:51:11: ...  68%|██████▊   | 82/121 [00:00<00:00, 1261.32 it/sec, obj=1]
    INFO - 13:51:11: ...  69%|██████▊   | 83/121 [00:00<00:00, 1262.25 it/sec, obj=2]
    INFO - 13:51:11: ...  69%|██████▉   | 84/121 [00:00<00:00, 1259.81 it/sec, obj=3]
    INFO - 13:51:11: ...  70%|███████   | 85/121 [00:00<00:00, 1260.75 it/sec, obj=4]
    INFO - 13:51:11: ...  71%|███████   | 86/121 [00:00<00:00, 1261.46 it/sec, obj=5]
    INFO - 13:51:11: ...  72%|███████▏  | 87/121 [00:00<00:00, 1262.28 it/sec, obj=6]
    INFO - 13:51:11: ...  73%|███████▎  | 88/121 [00:00<00:00, 1263.04 it/sec, obj=7]
    INFO - 13:51:11: ...  74%|███████▎  | 89/121 [00:00<00:00, 1263.33 it/sec, obj=-2]
    INFO - 13:51:11: ...  74%|███████▍  | 90/121 [00:00<00:00, 1264.10 it/sec, obj=-1]
    INFO - 13:51:11: ...  75%|███████▌  | 91/121 [00:00<00:00, 1264.95 it/sec, obj=0]
    INFO - 13:51:11: ...  76%|███████▌  | 92/121 [00:00<00:00, 1265.32 it/sec, obj=1]
    INFO - 13:51:11: ...  77%|███████▋  | 93/121 [00:00<00:00, 1265.92 it/sec, obj=2]
    INFO - 13:51:11: ...  78%|███████▊  | 94/121 [00:00<00:00, 1265.90 it/sec, obj=3]
    INFO - 13:51:11: ...  79%|███████▊  | 95/121 [00:00<00:00, 1266.60 it/sec, obj=4]
    INFO - 13:51:11: ...  79%|███████▉  | 96/121 [00:00<00:00, 1267.23 it/sec, obj=5]
    INFO - 13:51:11: ...  80%|████████  | 97/121 [00:00<00:00, 1267.66 it/sec, obj=6]
    INFO - 13:51:11: ...  81%|████████  | 98/121 [00:00<00:00, 1268.33 it/sec, obj=7]
    INFO - 13:51:11: ...  82%|████████▏ | 99/121 [00:00<00:00, 1268.53 it/sec, obj=8]
    INFO - 13:51:11: ...  83%|████████▎ | 100/121 [00:00<00:00, 1269.20 it/sec, obj=-1]
    INFO - 13:51:11: ...  83%|████████▎ | 101/121 [00:00<00:00, 1269.91 it/sec, obj=0]
    INFO - 13:51:11: ...  84%|████████▍ | 102/121 [00:00<00:00, 1270.13 it/sec, obj=1]
    INFO - 13:51:11: ...  85%|████████▌ | 103/121 [00:00<00:00, 1270.77 it/sec, obj=2]
    INFO - 13:51:11: ...  86%|████████▌ | 104/121 [00:00<00:00, 1271.46 it/sec, obj=3]
    INFO - 13:51:11: ...  87%|████████▋ | 105/121 [00:00<00:00, 1271.44 it/sec, obj=4]
    INFO - 13:51:11: ...  88%|████████▊ | 106/121 [00:00<00:00, 1272.08 it/sec, obj=5]
    INFO - 13:51:11: ...  88%|████████▊ | 107/121 [00:00<00:00, 1272.75 it/sec, obj=6]
    INFO - 13:51:11: ...  89%|████████▉ | 108/121 [00:00<00:00, 1272.96 it/sec, obj=7]
    INFO - 13:51:11: ...  90%|█████████ | 109/121 [00:00<00:00, 1273.56 it/sec, obj=8]
    INFO - 13:51:11: ...  91%|█████████ | 110/121 [00:00<00:00, 1273.60 it/sec, obj=9]
    INFO - 13:51:11: ...  92%|█████████▏| 111/121 [00:00<00:00, 1274.30 it/sec, obj=0]
    INFO - 13:51:11: ...  93%|█████████▎| 112/121 [00:00<00:00, 1274.97 it/sec, obj=1]
    INFO - 13:51:11: ...  93%|█████████▎| 113/121 [00:00<00:00, 1275.19 it/sec, obj=2]
    INFO - 13:51:11: ...  94%|█████████▍| 114/121 [00:00<00:00, 1275.76 it/sec, obj=3]
    INFO - 13:51:11: ...  95%|█████████▌| 115/121 [00:00<00:00, 1275.87 it/sec, obj=4]
    INFO - 13:51:11: ...  96%|█████████▌| 116/121 [00:00<00:00, 1276.41 it/sec, obj=5]
    INFO - 13:51:11: ...  97%|█████████▋| 117/121 [00:00<00:00, 1276.84 it/sec, obj=6]
    INFO - 13:51:11: ...  98%|█████████▊| 118/121 [00:00<00:00, 1277.11 it/sec, obj=7]
    INFO - 13:51:11: ...  98%|█████████▊| 119/121 [00:00<00:00, 1277.63 it/sec, obj=8]
    INFO - 13:51:11: ...  99%|█████████▉| 120/121 [00:00<00:00, 1278.13 it/sec, obj=9]
    INFO - 13:51:11: ... 100%|██████████| 121/121 [00:00<00:00, 1277.96 it/sec, obj=10]
    INFO - 13:51:11: Optimization result:
    INFO - 13:51:11:    Optimizer info:
    INFO - 13:51:11:       Status: None
    INFO - 13:51:11:       Message: None
    INFO - 13:51:11:       Number of calls to the objective function by the optimizer: 121
    INFO - 13:51:11:    Solution:
    INFO - 13:51:11:       Objective: -10.0
    INFO - 13:51:11:       Design space:
    INFO - 13:51:11:       +------+-------------+-------+-------------+---------+
    INFO - 13:51:11:       | name | lower_bound | value | upper_bound | type    |
    INFO - 13:51:11:       +------+-------------+-------+-------------+---------+
    INFO - 13:51:11:       | x1   |      -5     |   -5  |      5      | integer |
    INFO - 13:51:11:       | x2   |      -5     |   -5  |      5      | integer |
    INFO - 13:51:11:       +------+-------------+-------+-------------+---------+
    INFO - 13:51:11: *** End DOEScenario execution (time: 0:00:00.107250) ***

{'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.122 seconds)

Gallery generated by Sphinx-Gallery