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 - 08:59:09:
INFO - 08:59:09: *** Start DOEScenario execution ***
INFO - 08:59:09: DOEScenario
INFO - 08:59:09: Disciplines: AnalyticDiscipline
INFO - 08:59:09: MDO formulation: DisciplinaryOpt
INFO - 08:59:09: Optimization problem:
INFO - 08:59:09: minimize y(x1, x2)
INFO - 08:59:09: with respect to x1, x2
INFO - 08:59:09: over the design space:
INFO - 08:59:09: +------+-------------+-------+-------------+---------+
INFO - 08:59:09: | Name | Lower bound | Value | Upper bound | Type |
INFO - 08:59:09: +------+-------------+-------+-------------+---------+
INFO - 08:59:09: | x1 | -5 | None | 5 | integer |
INFO - 08:59:09: | x2 | -5 | None | 5 | integer |
INFO - 08:59:09: +------+-------------+-------+-------------+---------+
INFO - 08:59:09: Solving optimization problem with algorithm fullfact:
INFO - 08:59:09: 1%| | 1/121 [00:00<00:00, 341.36 it/sec, obj=-10]
INFO - 08:59:09: 2%|▏ | 2/121 [00:00<00:00, 540.54 it/sec, obj=-9]
INFO - 08:59:09: 2%|▏ | 3/121 [00:00<00:00, 679.28 it/sec, obj=-8]
INFO - 08:59:09: 3%|▎ | 4/121 [00:00<00:00, 791.94 it/sec, obj=-7]
INFO - 08:59:09: 4%|▍ | 5/121 [00:00<00:00, 880.93 it/sec, obj=-6]
INFO - 08:59:09: 5%|▍ | 6/121 [00:00<00:00, 950.05 it/sec, obj=-5]
INFO - 08:59:09: 6%|▌ | 7/121 [00:00<00:00, 1006.24 it/sec, obj=-4]
INFO - 08:59:09: 7%|▋ | 8/121 [00:00<00:00, 1055.90 it/sec, obj=-3]
INFO - 08:59:09: 7%|▋ | 9/121 [00:00<00:00, 1090.28 it/sec, obj=-2]
INFO - 08:59:09: 8%|▊ | 10/121 [00:00<00:00, 1126.11 it/sec, obj=-1]
INFO - 08:59:09: 9%|▉ | 11/121 [00:00<00:00, 1158.79 it/sec, obj=0]
INFO - 08:59:09: 10%|▉ | 12/121 [00:00<00:00, 1187.29 it/sec, obj=-9]
INFO - 08:59:09: 11%|█ | 13/121 [00:00<00:00, 1209.97 it/sec, obj=-8]
INFO - 08:59:09: 12%|█▏ | 14/121 [00:00<00:00, 1232.27 it/sec, obj=-7]
INFO - 08:59:09: 12%|█▏ | 15/121 [00:00<00:00, 1248.97 it/sec, obj=-6]
INFO - 08:59:09: 13%|█▎ | 16/121 [00:00<00:00, 1250.37 it/sec, obj=-5]
INFO - 08:59:09: 14%|█▍ | 17/121 [00:00<00:00, 1266.73 it/sec, obj=-4]
INFO - 08:59:09: 15%|█▍ | 18/121 [00:00<00:00, 1281.94 it/sec, obj=-3]
INFO - 08:59:09: 16%|█▌ | 19/121 [00:00<00:00, 1294.56 it/sec, obj=-2]
INFO - 08:59:09: 17%|█▋ | 20/121 [00:00<00:00, 1306.82 it/sec, obj=-1]
INFO - 08:59:09: 17%|█▋ | 21/121 [00:00<00:00, 1316.54 it/sec, obj=0]
INFO - 08:59:09: 18%|█▊ | 22/121 [00:00<00:00, 1327.31 it/sec, obj=1]
INFO - 08:59:09: 19%|█▉ | 23/121 [00:00<00:00, 1337.97 it/sec, obj=-8]
INFO - 08:59:09: 20%|█▉ | 24/121 [00:00<00:00, 1348.24 it/sec, obj=-7]
INFO - 08:59:09: 21%|██ | 25/121 [00:00<00:00, 1357.73 it/sec, obj=-6]
INFO - 08:59:09: 21%|██▏ | 26/121 [00:00<00:00, 1364.92 it/sec, obj=-5]
INFO - 08:59:09: 22%|██▏ | 27/121 [00:00<00:00, 1373.13 it/sec, obj=-4]
INFO - 08:59:09: 23%|██▎ | 28/121 [00:00<00:00, 1378.77 it/sec, obj=-3]
INFO - 08:59:09: 24%|██▍ | 29/121 [00:00<00:00, 1386.03 it/sec, obj=-2]
INFO - 08:59:09: 25%|██▍ | 30/121 [00:00<00:00, 1392.84 it/sec, obj=-1]
INFO - 08:59:09: 26%|██▌ | 31/121 [00:00<00:00, 1399.46 it/sec, obj=0]
INFO - 08:59:09: 26%|██▋ | 32/121 [00:00<00:00, 1404.69 it/sec, obj=1]
INFO - 08:59:09: 27%|██▋ | 33/121 [00:00<00:00, 1410.41 it/sec, obj=2]
INFO - 08:59:09: 28%|██▊ | 34/121 [00:00<00:00, 1413.93 it/sec, obj=-7]
INFO - 08:59:09: 29%|██▉ | 35/121 [00:00<00:00, 1418.79 it/sec, obj=-6]
INFO - 08:59:09: 30%|██▉ | 36/121 [00:00<00:00, 1423.61 it/sec, obj=-5]
INFO - 08:59:09: 31%|███ | 37/121 [00:00<00:00, 1428.53 it/sec, obj=-4]
INFO - 08:59:09: 31%|███▏ | 38/121 [00:00<00:00, 1432.92 it/sec, obj=-3]
INFO - 08:59:09: 32%|███▏ | 39/121 [00:00<00:00, 1436.28 it/sec, obj=-2]
INFO - 08:59:09: 33%|███▎ | 40/121 [00:00<00:00, 1440.39 it/sec, obj=-1]
INFO - 08:59:09: 34%|███▍ | 41/121 [00:00<00:00, 1442.55 it/sec, obj=0]
INFO - 08:59:09: 35%|███▍ | 42/121 [00:00<00:00, 1446.30 it/sec, obj=1]
INFO - 08:59:09: 36%|███▌ | 43/121 [00:00<00:00, 1450.10 it/sec, obj=2]
INFO - 08:59:09: 36%|███▋ | 44/121 [00:00<00:00, 1453.92 it/sec, obj=3]
INFO - 08:59:09: 37%|███▋ | 45/121 [00:00<00:00, 1456.72 it/sec, obj=-6]
INFO - 08:59:09: 38%|███▊ | 46/121 [00:00<00:00, 1460.27 it/sec, obj=-5]
INFO - 08:59:09: 39%|███▉ | 47/121 [00:00<00:00, 1461.00 it/sec, obj=-4]
INFO - 08:59:09: 40%|███▉ | 48/121 [00:00<00:00, 1463.92 it/sec, obj=-3]
INFO - 08:59:09: 40%|████ | 49/121 [00:00<00:00, 1467.00 it/sec, obj=-2]
INFO - 08:59:09: 41%|████▏ | 50/121 [00:00<00:00, 1469.89 it/sec, obj=-1]
INFO - 08:59:09: 42%|████▏ | 51/121 [00:00<00:00, 1472.06 it/sec, obj=0]
INFO - 08:59:09: 43%|████▎ | 52/121 [00:00<00:00, 1474.73 it/sec, obj=1]
INFO - 08:59:09: 44%|████▍ | 53/121 [00:00<00:00, 1477.50 it/sec, obj=2]
INFO - 08:59:09: 45%|████▍ | 54/121 [00:00<00:00, 1478.67 it/sec, obj=3]
INFO - 08:59:09: 45%|████▌ | 55/121 [00:00<00:00, 1480.98 it/sec, obj=4]
INFO - 08:59:09: 46%|████▋ | 56/121 [00:00<00:00, 1483.40 it/sec, obj=-5]
INFO - 08:59:09: 47%|████▋ | 57/121 [00:00<00:00, 1485.84 it/sec, obj=-4]
INFO - 08:59:09: 48%|████▊ | 58/121 [00:00<00:00, 1487.44 it/sec, obj=-3]
INFO - 08:59:09: 49%|████▉ | 59/121 [00:00<00:00, 1489.65 it/sec, obj=-2]
INFO - 08:59:09: 50%|████▉ | 60/121 [00:00<00:00, 1490.32 it/sec, obj=-1]
INFO - 08:59:09: 50%|█████ | 61/121 [00:00<00:00, 1492.22 it/sec, obj=0]
INFO - 08:59:09: 51%|█████ | 62/121 [00:00<00:00, 1494.24 it/sec, obj=1]
INFO - 08:59:09: 52%|█████▏ | 63/121 [00:00<00:00, 1496.21 it/sec, obj=2]
INFO - 08:59:09: 53%|█████▎ | 64/121 [00:00<00:00, 1497.44 it/sec, obj=3]
INFO - 08:59:09: 54%|█████▎ | 65/121 [00:00<00:00, 1499.24 it/sec, obj=4]
INFO - 08:59:09: 55%|█████▍ | 66/121 [00:00<00:00, 1499.50 it/sec, obj=5]
INFO - 08:59:09: 55%|█████▌ | 67/121 [00:00<00:00, 1500.81 it/sec, obj=-4]
INFO - 08:59:09: 56%|█████▌ | 68/121 [00:00<00:00, 1502.31 it/sec, obj=-3]
INFO - 08:59:09: 57%|█████▋ | 69/121 [00:00<00:00, 1503.93 it/sec, obj=-2]
INFO - 08:59:09: 58%|█████▊ | 70/121 [00:00<00:00, 1505.47 it/sec, obj=-1]
INFO - 08:59:09: 59%|█████▊ | 71/121 [00:00<00:00, 1506.22 it/sec, obj=0]
INFO - 08:59:09: 60%|█████▉ | 72/121 [00:00<00:00, 1507.76 it/sec, obj=1]
INFO - 08:59:09: 60%|██████ | 73/121 [00:00<00:00, 1508.23 it/sec, obj=2]
INFO - 08:59:09: 61%|██████ | 74/121 [00:00<00:00, 1509.62 it/sec, obj=3]
INFO - 08:59:09: 62%|██████▏ | 75/121 [00:00<00:00, 1511.02 it/sec, obj=4]
INFO - 08:59:09: 63%|██████▎ | 76/121 [00:00<00:00, 1512.43 it/sec, obj=5]
INFO - 08:59:09: 64%|██████▎ | 77/121 [00:00<00:00, 1512.34 it/sec, obj=6]
INFO - 08:59:09: 64%|██████▍ | 78/121 [00:00<00:00, 1513.62 it/sec, obj=-3]
INFO - 08:59:09: 65%|██████▌ | 79/121 [00:00<00:00, 1513.95 it/sec, obj=-2]
INFO - 08:59:09: 66%|██████▌ | 80/121 [00:00<00:00, 1515.06 it/sec, obj=-1]
INFO - 08:59:09: 67%|██████▋ | 81/121 [00:00<00:00, 1516.30 it/sec, obj=0]
INFO - 08:59:09: 68%|██████▊ | 82/121 [00:00<00:00, 1517.62 it/sec, obj=1]
INFO - 08:59:09: 69%|██████▊ | 83/121 [00:00<00:00, 1518.40 it/sec, obj=2]
INFO - 08:59:09: 69%|██████▉ | 84/121 [00:00<00:00, 1519.44 it/sec, obj=3]
INFO - 08:59:09: 70%|███████ | 85/121 [00:00<00:00, 1520.62 it/sec, obj=4]
INFO - 08:59:09: 71%|███████ | 86/121 [00:00<00:00, 1520.66 it/sec, obj=5]
INFO - 08:59:09: 72%|███████▏ | 87/121 [00:00<00:00, 1521.75 it/sec, obj=6]
INFO - 08:59:09: 73%|███████▎ | 88/121 [00:00<00:00, 1522.90 it/sec, obj=7]
INFO - 08:59:09: 74%|███████▎ | 89/121 [00:00<00:00, 1524.02 it/sec, obj=-2]
INFO - 08:59:09: 74%|███████▍ | 90/121 [00:00<00:00, 1524.52 it/sec, obj=-1]
INFO - 08:59:09: 75%|███████▌ | 91/121 [00:00<00:00, 1525.52 it/sec, obj=0]
INFO - 08:59:09: 76%|███████▌ | 92/121 [00:00<00:00, 1525.69 it/sec, obj=1]
INFO - 08:59:09: 77%|███████▋ | 93/121 [00:00<00:00, 1526.50 it/sec, obj=2]
INFO - 08:59:09: 78%|███████▊ | 94/121 [00:00<00:00, 1527.46 it/sec, obj=3]
INFO - 08:59:09: 79%|███████▊ | 95/121 [00:00<00:00, 1528.35 it/sec, obj=4]
INFO - 08:59:09: 79%|███████▉ | 96/121 [00:00<00:00, 1528.84 it/sec, obj=5]
INFO - 08:59:09: 80%|████████ | 97/121 [00:00<00:00, 1529.65 it/sec, obj=6]
INFO - 08:59:09: 81%|████████ | 98/121 [00:00<00:00, 1529.79 it/sec, obj=7]
INFO - 08:59:09: 82%|████████▏ | 99/121 [00:00<00:00, 1530.55 it/sec, obj=8]
INFO - 08:59:09: 83%|████████▎ | 100/121 [00:00<00:00, 1531.38 it/sec, obj=-1]
INFO - 08:59:09: 83%|████████▎ | 101/121 [00:00<00:00, 1532.27 it/sec, obj=0]
INFO - 08:59:09: 84%|████████▍ | 102/121 [00:00<00:00, 1533.23 it/sec, obj=1]
INFO - 08:59:09: 85%|████████▌ | 103/121 [00:00<00:00, 1533.48 it/sec, obj=2]
INFO - 08:59:09: 86%|████████▌ | 104/121 [00:00<00:00, 1534.26 it/sec, obj=3]
INFO - 08:59:09: 87%|████████▋ | 105/121 [00:00<00:00, 1534.23 it/sec, obj=4]
INFO - 08:59:09: 88%|████████▊ | 106/121 [00:00<00:00, 1535.10 it/sec, obj=5]
INFO - 08:59:09: 88%|████████▊ | 107/121 [00:00<00:00, 1535.16 it/sec, obj=6]
INFO - 08:59:09: 89%|████████▉ | 108/121 [00:00<00:00, 1534.83 it/sec, obj=7]
INFO - 08:59:09: 90%|█████████ | 109/121 [00:00<00:00, 1531.91 it/sec, obj=8]
INFO - 08:59:09: 91%|█████████ | 110/121 [00:00<00:00, 1532.47 it/sec, obj=9]
INFO - 08:59:09: 92%|█████████▏| 111/121 [00:00<00:00, 1532.51 it/sec, obj=0]
INFO - 08:59:09: 93%|█████████▎| 112/121 [00:00<00:00, 1533.24 it/sec, obj=1]
INFO - 08:59:09: 93%|█████████▎| 113/121 [00:00<00:00, 1533.94 it/sec, obj=2]
INFO - 08:59:09: 94%|█████████▍| 114/121 [00:00<00:00, 1534.62 it/sec, obj=3]
INFO - 08:59:09: 95%|█████████▌| 115/121 [00:00<00:00, 1534.88 it/sec, obj=4]
INFO - 08:59:09: 96%|█████████▌| 116/121 [00:00<00:00, 1535.60 it/sec, obj=5]
INFO - 08:59:09: 97%|█████████▋| 117/121 [00:00<00:00, 1535.63 it/sec, obj=6]
INFO - 08:59:09: 98%|█████████▊| 118/121 [00:00<00:00, 1536.29 it/sec, obj=7]
INFO - 08:59:09: 98%|█████████▊| 119/121 [00:00<00:00, 1536.96 it/sec, obj=8]
INFO - 08:59:09: 99%|█████████▉| 120/121 [00:00<00:00, 1537.65 it/sec, obj=9]
INFO - 08:59:09: 100%|██████████| 121/121 [00:00<00:00, 1537.93 it/sec, obj=10]
INFO - 08:59:09: Optimization result:
INFO - 08:59:09: Optimizer info:
INFO - 08:59:09: Status: None
INFO - 08:59:09: Message: None
INFO - 08:59:09: Number of calls to the objective function by the optimizer: 121
INFO - 08:59:09: Solution:
INFO - 08:59:09: Objective: -10.0
INFO - 08:59:09: Design space:
INFO - 08:59:09: +------+-------------+-------+-------------+---------+
INFO - 08:59:09: | Name | Lower bound | Value | Upper bound | Type |
INFO - 08:59:09: +------+-------------+-------+-------------+---------+
INFO - 08:59:09: | x1 | -5 | -5 | 5 | integer |
INFO - 08:59:09: | x2 | -5 | -5 | 5 | integer |
INFO - 08:59:09: +------+-------------+-------+-------------+---------+
INFO - 08:59:09: *** End DOEScenario execution (time: 0:00:00.091001) ***
{'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.106 seconds)