Note
Go to the end to download the full example code
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:
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:08:21:
INFO - 13:08:21: *** Start DOEScenario execution ***
INFO - 13:08:21: DOEScenario
INFO - 13:08:21: Disciplines: AnalyticDiscipline
INFO - 13:08:21: MDO formulation: DisciplinaryOpt
INFO - 13:08:21: Optimization problem:
INFO - 13:08:21: minimize y(x1, x2)
INFO - 13:08:21: with respect to x1, x2
INFO - 13:08:21: over the design space:
INFO - 13:08:21: +------+-------------+-------+-------------+---------+
INFO - 13:08:21: | Name | Lower bound | Value | Upper bound | Type |
INFO - 13:08:21: +------+-------------+-------+-------------+---------+
INFO - 13:08:21: | x1 | -5 | None | 5 | integer |
INFO - 13:08:21: | x2 | -5 | None | 5 | integer |
INFO - 13:08:21: +------+-------------+-------+-------------+---------+
INFO - 13:08:21: Solving optimization problem with algorithm fullfact:
INFO - 13:08:21: 1%| | 1/121 [00:00<00:00, 328.89 it/sec, obj=-10]
INFO - 13:08:21: 2%|▏ | 2/121 [00:00<00:00, 506.13 it/sec, obj=-9]
INFO - 13:08:21: 2%|▏ | 3/121 [00:00<00:00, 645.64 it/sec, obj=-8]
INFO - 13:08:21: 3%|▎ | 4/121 [00:00<00:00, 756.28 it/sec, obj=-7]
INFO - 13:08:21: 4%|▍ | 5/121 [00:00<00:00, 835.52 it/sec, obj=-6]
INFO - 13:08:21: 5%|▍ | 6/121 [00:00<00:00, 906.06 it/sec, obj=-5]
INFO - 13:08:21: 6%|▌ | 7/121 [00:00<00:00, 962.22 it/sec, obj=-4]
INFO - 13:08:21: 7%|▋ | 8/121 [00:00<00:00, 1012.17 it/sec, obj=-3]
INFO - 13:08:21: 7%|▋ | 9/121 [00:00<00:00, 1054.32 it/sec, obj=-2]
INFO - 13:08:21: 8%|▊ | 10/121 [00:00<00:00, 1091.04 it/sec, obj=-1]
INFO - 13:08:21: 9%|▉ | 11/121 [00:00<00:00, 1115.83 it/sec, obj=0]
INFO - 13:08:21: 10%|▉ | 12/121 [00:00<00:00, 1143.62 it/sec, obj=-9]
INFO - 13:08:21: 11%|█ | 13/121 [00:00<00:00, 1165.78 it/sec, obj=-8]
INFO - 13:08:21: 12%|█▏ | 14/121 [00:00<00:00, 1188.26 it/sec, obj=-7]
INFO - 13:08:21: 12%|█▏ | 15/121 [00:00<00:00, 1208.69 it/sec, obj=-6]
INFO - 13:08:21: 13%|█▎ | 16/121 [00:00<00:00, 1209.30 it/sec, obj=-5]
INFO - 13:08:21: 14%|█▍ | 17/121 [00:00<00:00, 1221.38 it/sec, obj=-4]
INFO - 13:08:21: 15%|█▍ | 18/121 [00:00<00:00, 1236.53 it/sec, obj=-3]
INFO - 13:08:21: 16%|█▌ | 19/121 [00:00<00:00, 1248.81 it/sec, obj=-2]
INFO - 13:08:21: 17%|█▋ | 20/121 [00:00<00:00, 1261.86 it/sec, obj=-1]
INFO - 13:08:21: 17%|█▋ | 21/121 [00:00<00:00, 1274.31 it/sec, obj=0]
INFO - 13:08:21: 18%|█▊ | 22/121 [00:00<00:00, 1285.88 it/sec, obj=1]
INFO - 13:08:21: 19%|█▉ | 23/121 [00:00<00:00, 1293.34 it/sec, obj=-8]
INFO - 13:08:21: 20%|█▉ | 24/121 [00:00<00:00, 1303.00 it/sec, obj=-7]
INFO - 13:08:21: 21%|██ | 25/121 [00:00<00:00, 1310.65 it/sec, obj=-6]
INFO - 13:08:21: 21%|██▏ | 26/121 [00:00<00:00, 1319.12 it/sec, obj=-5]
INFO - 13:08:21: 22%|██▏ | 27/121 [00:00<00:00, 1327.37 it/sec, obj=-4]
INFO - 13:08:21: 23%|██▎ | 28/121 [00:00<00:00, 1335.48 it/sec, obj=-3]
INFO - 13:08:21: 24%|██▍ | 29/121 [00:00<00:00, 1339.31 it/sec, obj=-2]
INFO - 13:08:21: 25%|██▍ | 30/121 [00:00<00:00, 1345.92 it/sec, obj=-1]
INFO - 13:08:21: 26%|██▌ | 31/121 [00:00<00:00, 1351.19 it/sec, obj=0]
INFO - 13:08:21: 26%|██▋ | 32/121 [00:00<00:00, 1357.31 it/sec, obj=1]
INFO - 13:08:21: 27%|██▋ | 33/121 [00:00<00:00, 1363.49 it/sec, obj=2]
INFO - 13:08:21: 28%|██▊ | 34/121 [00:00<00:00, 1369.23 it/sec, obj=-7]
INFO - 13:08:21: 29%|██▉ | 35/121 [00:00<00:00, 1372.71 it/sec, obj=-6]
INFO - 13:08:21: 30%|██▉ | 36/121 [00:00<00:00, 1377.41 it/sec, obj=-5]
INFO - 13:08:21: 31%|███ | 37/121 [00:00<00:00, 1381.13 it/sec, obj=-4]
INFO - 13:08:21: 31%|███▏ | 38/121 [00:00<00:00, 1385.44 it/sec, obj=-3]
INFO - 13:08:21: 32%|███▏ | 39/121 [00:00<00:00, 1389.90 it/sec, obj=-2]
INFO - 13:08:21: 33%|███▎ | 40/121 [00:00<00:00, 1394.15 it/sec, obj=-1]
INFO - 13:08:21: 34%|███▍ | 41/121 [00:00<00:00, 1398.24 it/sec, obj=0]
INFO - 13:08:21: 35%|███▍ | 42/121 [00:00<00:00, 1400.13 it/sec, obj=1]
INFO - 13:08:21: 36%|███▌ | 43/121 [00:00<00:00, 1403.81 it/sec, obj=2]
INFO - 13:08:21: 36%|███▋ | 44/121 [00:00<00:00, 1406.37 it/sec, obj=3]
INFO - 13:08:21: 37%|███▋ | 45/121 [00:00<00:00, 1409.85 it/sec, obj=-6]
INFO - 13:08:21: 38%|███▊ | 46/121 [00:00<00:00, 1413.33 it/sec, obj=-5]
INFO - 13:08:21: 39%|███▉ | 47/121 [00:00<00:00, 1416.65 it/sec, obj=-4]
INFO - 13:08:21: 40%|███▉ | 48/121 [00:00<00:00, 1416.08 it/sec, obj=-3]
INFO - 13:08:21: 40%|████ | 49/121 [00:00<00:00, 1418.84 it/sec, obj=-2]
INFO - 13:08:21: 41%|████▏ | 50/121 [00:00<00:00, 1420.51 it/sec, obj=-1]
INFO - 13:08:21: 42%|████▏ | 51/121 [00:00<00:00, 1423.39 it/sec, obj=0]
INFO - 13:08:21: 43%|████▎ | 52/121 [00:00<00:00, 1426.29 it/sec, obj=1]
INFO - 13:08:21: 44%|████▍ | 53/121 [00:00<00:00, 1427.72 it/sec, obj=2]
INFO - 13:08:21: 45%|████▍ | 54/121 [00:00<00:00, 1428.65 it/sec, obj=3]
INFO - 13:08:21: 45%|████▌ | 55/121 [00:00<00:00, 1431.14 it/sec, obj=4]
INFO - 13:08:21: 46%|████▋ | 56/121 [00:00<00:00, 1433.00 it/sec, obj=-5]
INFO - 13:08:21: 47%|████▋ | 57/121 [00:00<00:00, 1435.37 it/sec, obj=-4]
INFO - 13:08:21: 48%|████▊ | 58/121 [00:00<00:00, 1437.80 it/sec, obj=-3]
INFO - 13:08:21: 49%|████▉ | 59/121 [00:00<00:00, 1440.20 it/sec, obj=-2]
INFO - 13:08:21: 50%|████▉ | 60/121 [00:00<00:00, 1440.15 it/sec, obj=-1]
INFO - 13:08:21: 50%|█████ | 61/121 [00:00<00:00, 1441.91 it/sec, obj=0]
INFO - 13:08:21: 51%|█████ | 62/121 [00:00<00:00, 1443.02 it/sec, obj=1]
INFO - 13:08:21: 52%|█████▏ | 63/121 [00:00<00:00, 1444.93 it/sec, obj=2]
INFO - 13:08:21: 53%|█████▎ | 64/121 [00:00<00:00, 1446.92 it/sec, obj=3]
INFO - 13:08:21: 54%|█████▎ | 65/121 [00:00<00:00, 1448.93 it/sec, obj=4]
INFO - 13:08:21: 55%|█████▍ | 66/121 [00:00<00:00, 1449.53 it/sec, obj=5]
INFO - 13:08:21: 55%|█████▌ | 67/121 [00:00<00:00, 1451.11 it/sec, obj=-4]
INFO - 13:08:21: 56%|█████▌ | 68/121 [00:00<00:00, 1452.25 it/sec, obj=-3]
INFO - 13:08:21: 57%|█████▋ | 69/121 [00:00<00:00, 1454.01 it/sec, obj=-2]
INFO - 13:08:21: 58%|█████▊ | 70/121 [00:00<00:00, 1455.72 it/sec, obj=-1]
INFO - 13:08:21: 59%|█████▊ | 71/121 [00:00<00:00, 1457.50 it/sec, obj=0]
INFO - 13:08:21: 60%|█████▉ | 72/121 [00:00<00:00, 1459.11 it/sec, obj=1]
INFO - 13:08:21: 60%|██████ | 73/121 [00:00<00:00, 1459.42 it/sec, obj=2]
INFO - 13:08:21: 61%|██████ | 74/121 [00:00<00:00, 1461.02 it/sec, obj=3]
INFO - 13:08:21: 62%|██████▏ | 75/121 [00:00<00:00, 1461.79 it/sec, obj=4]
INFO - 13:08:21: 63%|██████▎ | 76/121 [00:00<00:00, 1463.24 it/sec, obj=5]
INFO - 13:08:21: 64%|██████▎ | 77/121 [00:00<00:00, 1464.72 it/sec, obj=6]
INFO - 13:08:21: 64%|██████▍ | 78/121 [00:00<00:00, 1466.19 it/sec, obj=-3]
INFO - 13:08:21: 65%|██████▌ | 79/121 [00:00<00:00, 1466.45 it/sec, obj=-2]
INFO - 13:08:21: 66%|██████▌ | 80/121 [00:00<00:00, 1467.75 it/sec, obj=-1]
INFO - 13:08:21: 67%|██████▋ | 81/121 [00:00<00:00, 1468.44 it/sec, obj=0]
INFO - 13:08:21: 68%|██████▊ | 82/121 [00:00<00:00, 1469.72 it/sec, obj=1]
INFO - 13:08:21: 69%|██████▊ | 83/121 [00:00<00:00, 1471.09 it/sec, obj=2]
INFO - 13:08:21: 69%|██████▉ | 84/121 [00:00<00:00, 1472.15 it/sec, obj=3]
INFO - 13:08:21: 70%|███████ | 85/121 [00:00<00:00, 1471.88 it/sec, obj=4]
INFO - 13:08:21: 71%|███████ | 86/121 [00:00<00:00, 1473.04 it/sec, obj=5]
INFO - 13:08:21: 72%|███████▏ | 87/121 [00:00<00:00, 1473.68 it/sec, obj=6]
INFO - 13:08:21: 73%|███████▎ | 88/121 [00:00<00:00, 1474.83 it/sec, obj=7]
INFO - 13:08:21: 74%|███████▎ | 89/121 [00:00<00:00, 1476.06 it/sec, obj=-2]
INFO - 13:08:21: 74%|███████▍ | 90/121 [00:00<00:00, 1470.54 it/sec, obj=-1]
INFO - 13:08:21: 75%|███████▌ | 91/121 [00:00<00:00, 1468.83 it/sec, obj=0]
INFO - 13:08:21: 76%|███████▌ | 92/121 [00:00<00:00, 1469.73 it/sec, obj=1]
INFO - 13:08:21: 77%|███████▋ | 93/121 [00:00<00:00, 1469.97 it/sec, obj=2]
INFO - 13:08:21: 78%|███████▊ | 94/121 [00:00<00:00, 1470.99 it/sec, obj=3]
INFO - 13:08:21: 79%|███████▊ | 95/121 [00:00<00:00, 1471.98 it/sec, obj=4]
INFO - 13:08:21: 79%|███████▉ | 96/121 [00:00<00:00, 1473.07 it/sec, obj=5]
INFO - 13:08:21: 80%|████████ | 97/121 [00:00<00:00, 1473.20 it/sec, obj=6]
INFO - 13:08:21: 81%|████████ | 98/121 [00:00<00:00, 1474.17 it/sec, obj=7]
INFO - 13:08:21: 82%|████████▏ | 99/121 [00:00<00:00, 1474.69 it/sec, obj=8]
INFO - 13:08:21: 83%|████████▎ | 100/121 [00:00<00:00, 1475.62 it/sec, obj=-1]
INFO - 13:08:21: 83%|████████▎ | 101/121 [00:00<00:00, 1476.56 it/sec, obj=0]
INFO - 13:08:21: 84%|████████▍ | 102/121 [00:00<00:00, 1477.60 it/sec, obj=1]
INFO - 13:08:21: 85%|████████▌ | 103/121 [00:00<00:00, 1477.59 it/sec, obj=2]
INFO - 13:08:21: 86%|████████▌ | 104/121 [00:00<00:00, 1478.42 it/sec, obj=3]
INFO - 13:08:21: 87%|████████▋ | 105/121 [00:00<00:00, 1478.88 it/sec, obj=4]
INFO - 13:08:21: 88%|████████▊ | 106/121 [00:00<00:00, 1479.75 it/sec, obj=5]
INFO - 13:08:21: 88%|████████▊ | 107/121 [00:00<00:00, 1480.67 it/sec, obj=6]
INFO - 13:08:21: 89%|████████▉ | 108/121 [00:00<00:00, 1481.59 it/sec, obj=7]
INFO - 13:08:21: 90%|█████████ | 109/121 [00:00<00:00, 1478.58 it/sec, obj=8]
INFO - 13:08:21: 91%|█████████ | 110/121 [00:00<00:00, 1479.28 it/sec, obj=9]
INFO - 13:08:21: 92%|█████████▏| 111/121 [00:00<00:00, 1479.65 it/sec, obj=0]
INFO - 13:08:21: 93%|█████████▎| 112/121 [00:00<00:00, 1480.43 it/sec, obj=1]
INFO - 13:08:21: 93%|█████████▎| 113/121 [00:00<00:00, 1481.27 it/sec, obj=2]
INFO - 13:08:21: 94%|█████████▍| 114/121 [00:00<00:00, 1482.10 it/sec, obj=3]
INFO - 13:08:21: 95%|█████████▌| 115/121 [00:00<00:00, 1482.10 it/sec, obj=4]
INFO - 13:08:21: 96%|█████████▌| 116/121 [00:00<00:00, 1482.78 it/sec, obj=5]
INFO - 13:08:21: 97%|█████████▋| 117/121 [00:00<00:00, 1482.95 it/sec, obj=6]
INFO - 13:08:21: 98%|█████████▊| 118/121 [00:00<00:00, 1483.66 it/sec, obj=7]
INFO - 13:08:21: 98%|█████████▊| 119/121 [00:00<00:00, 1484.40 it/sec, obj=8]
INFO - 13:08:21: 99%|█████████▉| 120/121 [00:00<00:00, 1485.14 it/sec, obj=9]
INFO - 13:08:21: 100%|██████████| 121/121 [00:00<00:00, 1485.93 it/sec, obj=10]
INFO - 13:08:21: Optimization result:
INFO - 13:08:21: Optimizer info:
INFO - 13:08:21: Status: None
INFO - 13:08:21: Message: None
INFO - 13:08:21: Number of calls to the objective function by the optimizer: 121
INFO - 13:08:21: Solution:
INFO - 13:08:21: Objective: -10.0
INFO - 13:08:21: Design space:
INFO - 13:08:21: +------+-------------+-------+-------------+---------+
INFO - 13:08:21: | Name | Lower bound | Value | Upper bound | Type |
INFO - 13:08:21: +------+-------------+-------+-------------+---------+
INFO - 13:08:21: | x1 | -5 | -5 | 5 | integer |
INFO - 13:08:21: | x2 | -5 | -5 | 5 | integer |
INFO - 13:08:21: +------+-------------+-------+-------------+---------+
INFO - 13:08:21: *** End DOEScenario execution (time: 0:00:00.094365) ***
{'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', 'Halton', 'LHS', 'MC', 'PoissonDisk', 'Sobol']
Available post-processing¶
In order to get the list of available post-processing algorithms, use:
get_available_post_processings()
['Animation', 'BasicHistory', 'Compromise', 'ConstraintsHistory', 'Correlations', 'DataVersusModel', '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.110 seconds)