Note
Go to the end to download the full example code.
Create a DOE Scenario#
from __future__ import annotations
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
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 Discipline of AnalyticDiscipline type
from a Python function:
expressions = {"y": "x1+x2"}
discipline = create_discipline("AnalyticDiscipline", expressions=expressions)
Now, we want to minimize this Discipline
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", lower_bound=-5, upper_bound=5, type_="integer")
design_space.add_variable("x2", lower_bound=-5, upper_bound=5, type_="integer")
Define the DOE scenario#
Then, by means of the create_scenario() API function,
we define a DOEScenario from the Discipline
and the DesignSpace defined above:
scenario = create_scenario(
discipline,
"y",
design_space,
scenario_type="DOE",
formulation_name="DisciplinaryOpt",
)
Note that the formulation settings passed to create_scenario() can be provided
via a Pydantic model. For more information, see Formulation Settings.
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_name="PYDOE_FULLFACT", n_samples=11**2)
INFO - 16:24:38: *** Start DOEScenario execution ***
INFO - 16:24:38: DOEScenario
INFO - 16:24:38: Disciplines: AnalyticDiscipline
INFO - 16:24:38: MDO formulation: DisciplinaryOpt
INFO - 16:24:38: Optimization problem:
INFO - 16:24:38: minimize y(x1, x2)
INFO - 16:24:38: with respect to x1, x2
INFO - 16:24:38: over the design space:
INFO - 16:24:38: +------+-------------+-------+-------------+---------+
INFO - 16:24:38: | Name | Lower bound | Value | Upper bound | Type |
INFO - 16:24:38: +------+-------------+-------+-------------+---------+
INFO - 16:24:38: | x1 | -5 | None | 5 | integer |
INFO - 16:24:38: | x2 | -5 | None | 5 | integer |
INFO - 16:24:38: +------+-------------+-------+-------------+---------+
INFO - 16:24:38: Solving optimization problem with algorithm PYDOE_FULLFACT:
INFO - 16:24:38: 1%| | 1/121 [00:00<00:00, 555.68 it/sec, feas=True, obj=-10]
INFO - 16:24:38: 2%|▏ | 2/121 [00:00<00:00, 939.48 it/sec, feas=True, obj=-9]
INFO - 16:24:38: 2%|▏ | 3/121 [00:00<00:00, 1245.34 it/sec, feas=True, obj=-8]
INFO - 16:24:38: 3%|▎ | 4/121 [00:00<00:00, 1508.47 it/sec, feas=True, obj=-7]
INFO - 16:24:38: 4%|▍ | 5/121 [00:00<00:00, 1733.47 it/sec, feas=True, obj=-6]
INFO - 16:24:38: 5%|▍ | 6/121 [00:00<00:00, 1930.49 it/sec, feas=True, obj=-5]
INFO - 16:24:38: 6%|▌ | 7/121 [00:00<00:00, 2092.07 it/sec, feas=True, obj=-4]
INFO - 16:24:38: 7%|▋ | 8/121 [00:00<00:00, 2237.26 it/sec, feas=True, obj=-3]
INFO - 16:24:38: 7%|▋ | 9/121 [00:00<00:00, 2370.41 it/sec, feas=True, obj=-2]
INFO - 16:24:38: 8%|▊ | 10/121 [00:00<00:00, 2490.24 it/sec, feas=True, obj=-1]
INFO - 16:24:38: 9%|▉ | 11/121 [00:00<00:00, 2600.75 it/sec, feas=True, obj=0]
INFO - 16:24:38: 10%|▉ | 12/121 [00:00<00:00, 2688.80 it/sec, feas=True, obj=-9]
INFO - 16:24:38: 11%|█ | 13/121 [00:00<00:00, 2773.87 it/sec, feas=True, obj=-8]
INFO - 16:24:38: 12%|█▏ | 14/121 [00:00<00:00, 2856.88 it/sec, feas=True, obj=-7]
INFO - 16:24:38: 12%|█▏ | 15/121 [00:00<00:00, 2935.27 it/sec, feas=True, obj=-6]
INFO - 16:24:38: 13%|█▎ | 16/121 [00:00<00:00, 2998.74 it/sec, feas=True, obj=-5]
INFO - 16:24:38: 14%|█▍ | 17/121 [00:00<00:00, 3060.75 it/sec, feas=True, obj=-4]
INFO - 16:24:38: 15%|█▍ | 18/121 [00:00<00:00, 3123.73 it/sec, feas=True, obj=-3]
INFO - 16:24:38: 16%|█▌ | 19/121 [00:00<00:00, 3176.11 it/sec, feas=True, obj=-2]
INFO - 16:24:38: 17%|█▋ | 20/121 [00:00<00:00, 3228.13 it/sec, feas=True, obj=-1]
INFO - 16:24:38: 17%|█▋ | 21/121 [00:00<00:00, 3268.17 it/sec, feas=True, obj=0]
INFO - 16:24:38: 18%|█▊ | 22/121 [00:00<00:00, 3312.92 it/sec, feas=True, obj=1]
INFO - 16:24:38: 19%|█▉ | 23/121 [00:00<00:00, 3358.83 it/sec, feas=True, obj=-8]
INFO - 16:24:38: 20%|█▉ | 24/121 [00:00<00:00, 3403.66 it/sec, feas=True, obj=-7]
INFO - 16:24:38: 21%|██ | 25/121 [00:00<00:00, 3444.50 it/sec, feas=True, obj=-6]
INFO - 16:24:38: 21%|██▏ | 26/121 [00:00<00:00, 3471.33 it/sec, feas=True, obj=-5]
INFO - 16:24:38: 22%|██▏ | 27/121 [00:00<00:00, 3505.42 it/sec, feas=True, obj=-4]
INFO - 16:24:38: 23%|██▎ | 28/121 [00:00<00:00, 3540.03 it/sec, feas=True, obj=-3]
INFO - 16:24:38: 24%|██▍ | 29/121 [00:00<00:00, 3571.93 it/sec, feas=True, obj=-2]
INFO - 16:24:38: 25%|██▍ | 30/121 [00:00<00:00, 3595.84 it/sec, feas=True, obj=-1]
INFO - 16:24:38: 26%|██▌ | 31/121 [00:00<00:00, 3622.02 it/sec, feas=True, obj=0]
INFO - 16:24:38: 26%|██▋ | 32/121 [00:00<00:00, 3650.40 it/sec, feas=True, obj=1]
INFO - 16:24:38: 27%|██▋ | 33/121 [00:00<00:00, 3677.75 it/sec, feas=True, obj=2]
INFO - 16:24:38: 28%|██▊ | 34/121 [00:00<00:00, 3703.68 it/sec, feas=True, obj=-7]
INFO - 16:24:38: 29%|██▉ | 35/121 [00:00<00:00, 3722.03 it/sec, feas=True, obj=-6]
INFO - 16:24:38: 30%|██▉ | 36/121 [00:00<00:00, 3742.69 it/sec, feas=True, obj=-5]
INFO - 16:24:38: 31%|███ | 37/121 [00:00<00:00, 3764.81 it/sec, feas=True, obj=-4]
INFO - 16:24:38: 31%|███▏ | 38/121 [00:00<00:00, 3781.16 it/sec, feas=True, obj=-3]
INFO - 16:24:38: 32%|███▏ | 39/121 [00:00<00:00, 3802.37 it/sec, feas=True, obj=-2]
INFO - 16:24:38: 33%|███▎ | 40/121 [00:00<00:00, 3813.18 it/sec, feas=True, obj=-1]
INFO - 16:24:38: 34%|███▍ | 41/121 [00:00<00:00, 3830.59 it/sec, feas=True, obj=0]
INFO - 16:24:38: 35%|███▍ | 42/121 [00:00<00:00, 3849.50 it/sec, feas=True, obj=1]
INFO - 16:24:38: 36%|███▌ | 43/121 [00:00<00:00, 3866.55 it/sec, feas=True, obj=2]
INFO - 16:24:38: 36%|███▋ | 44/121 [00:00<00:00, 3878.15 it/sec, feas=True, obj=3]
INFO - 16:24:38: 37%|███▋ | 45/121 [00:00<00:00, 3890.98 it/sec, feas=True, obj=-6]
INFO - 16:24:38: 38%|███▊ | 46/121 [00:00<00:00, 3907.05 it/sec, feas=True, obj=-5]
INFO - 16:24:38: 39%|███▉ | 47/121 [00:00<00:00, 3920.69 it/sec, feas=True, obj=-4]
INFO - 16:24:38: 40%|███▉ | 48/121 [00:00<00:00, 3936.62 it/sec, feas=True, obj=-3]
INFO - 16:24:38: 40%|████ | 49/121 [00:00<00:00, 3945.50 it/sec, feas=True, obj=-2]
INFO - 16:24:38: 41%|████▏ | 50/121 [00:00<00:00, 3958.38 it/sec, feas=True, obj=-1]
INFO - 16:24:38: 42%|████▏ | 51/121 [00:00<00:00, 3974.31 it/sec, feas=True, obj=0]
INFO - 16:24:38: 43%|████▎ | 52/121 [00:00<00:00, 3989.75 it/sec, feas=True, obj=1]
INFO - 16:24:38: 44%|████▍ | 53/121 [00:00<00:00, 4003.21 it/sec, feas=True, obj=2]
INFO - 16:24:38: 45%|████▍ | 54/121 [00:00<00:00, 4009.57 it/sec, feas=True, obj=3]
INFO - 16:24:38: 45%|████▌ | 55/121 [00:00<00:00, 4022.09 it/sec, feas=True, obj=4]
INFO - 16:24:38: 46%|████▋ | 56/121 [00:00<00:00, 4034.44 it/sec, feas=True, obj=-5]
INFO - 16:24:38: 47%|████▋ | 57/121 [00:00<00:00, 4047.46 it/sec, feas=True, obj=-4]
INFO - 16:24:38: 48%|████▊ | 58/121 [00:00<00:00, 4061.47 it/sec, feas=True, obj=-3]
INFO - 16:24:38: 49%|████▉ | 59/121 [00:00<00:00, 4068.19 it/sec, feas=True, obj=-2]
INFO - 16:24:38: 50%|████▉ | 60/121 [00:00<00:00, 4055.86 it/sec, feas=True, obj=-1]
INFO - 16:24:38: 50%|█████ | 61/121 [00:00<00:00, 4064.89 it/sec, feas=True, obj=0]
INFO - 16:24:38: 51%|█████ | 62/121 [00:00<00:00, 4075.33 it/sec, feas=True, obj=1]
INFO - 16:24:38: 52%|█████▏ | 63/121 [00:00<00:00, 4080.82 it/sec, feas=True, obj=2]
INFO - 16:24:38: 53%|█████▎ | 64/121 [00:00<00:00, 4088.51 it/sec, feas=True, obj=3]
INFO - 16:24:38: 54%|█████▎ | 65/121 [00:00<00:00, 4096.98 it/sec, feas=True, obj=4]
INFO - 16:24:38: 55%|█████▍ | 66/121 [00:00<00:00, 4104.44 it/sec, feas=True, obj=5]
INFO - 16:24:38: 55%|█████▌ | 67/121 [00:00<00:00, 4112.12 it/sec, feas=True, obj=-4]
INFO - 16:24:38: 56%|█████▌ | 68/121 [00:00<00:00, 4115.56 it/sec, feas=True, obj=-3]
INFO - 16:24:38: 57%|█████▋ | 69/121 [00:00<00:00, 4124.72 it/sec, feas=True, obj=-2]
INFO - 16:24:38: 58%|█████▊ | 70/121 [00:00<00:00, 4133.54 it/sec, feas=True, obj=-1]
INFO - 16:24:38: 59%|█████▊ | 71/121 [00:00<00:00, 4142.03 it/sec, feas=True, obj=0]
INFO - 16:24:38: 60%|█████▉ | 72/121 [00:00<00:00, 4146.62 it/sec, feas=True, obj=1]
INFO - 16:24:38: 60%|██████ | 73/121 [00:00<00:00, 4154.41 it/sec, feas=True, obj=2]
INFO - 16:24:38: 61%|██████ | 74/121 [00:00<00:00, 4163.64 it/sec, feas=True, obj=3]
INFO - 16:24:38: 62%|██████▏ | 75/121 [00:00<00:00, 4169.95 it/sec, feas=True, obj=4]
INFO - 16:24:38: 63%|██████▎ | 76/121 [00:00<00:00, 4178.42 it/sec, feas=True, obj=5]
INFO - 16:24:38: 64%|██████▎ | 77/121 [00:00<00:00, 4182.30 it/sec, feas=True, obj=6]
INFO - 16:24:38: 64%|██████▍ | 78/121 [00:00<00:00, 4190.01 it/sec, feas=True, obj=-3]
INFO - 16:24:38: 65%|██████▌ | 79/121 [00:00<00:00, 4198.02 it/sec, feas=True, obj=-2]
INFO - 16:24:38: 66%|██████▌ | 80/121 [00:00<00:00, 4206.08 it/sec, feas=True, obj=-1]
INFO - 16:24:38: 67%|██████▋ | 81/121 [00:00<00:00, 4212.77 it/sec, feas=True, obj=0]
INFO - 16:24:38: 68%|██████▊ | 82/121 [00:00<00:00, 4215.79 it/sec, feas=True, obj=1]
INFO - 16:24:38: 69%|██████▊ | 83/121 [00:00<00:00, 4223.31 it/sec, feas=True, obj=2]
INFO - 16:24:38: 69%|██████▉ | 84/121 [00:00<00:00, 4231.28 it/sec, feas=True, obj=3]
INFO - 16:24:38: 70%|███████ | 85/121 [00:00<00:00, 4239.04 it/sec, feas=True, obj=4]
INFO - 16:24:38: 71%|███████ | 86/121 [00:00<00:00, 4245.60 it/sec, feas=True, obj=5]
INFO - 16:24:38: 72%|███████▏ | 87/121 [00:00<00:00, 4247.37 it/sec, feas=True, obj=6]
INFO - 16:24:38: 73%|███████▎ | 88/121 [00:00<00:00, 4253.37 it/sec, feas=True, obj=7]
INFO - 16:24:38: 74%|███████▎ | 89/121 [00:00<00:00, 4259.44 it/sec, feas=True, obj=-2]
INFO - 16:24:38: 74%|███████▍ | 90/121 [00:00<00:00, 4265.35 it/sec, feas=True, obj=-1]
INFO - 16:24:38: 75%|███████▌ | 91/121 [00:00<00:00, 4272.00 it/sec, feas=True, obj=0]
INFO - 16:24:38: 76%|███████▌ | 92/121 [00:00<00:00, 4273.55 it/sec, feas=True, obj=1]
INFO - 16:24:38: 77%|███████▋ | 93/121 [00:00<00:00, 4278.49 it/sec, feas=True, obj=2]
INFO - 16:24:38: 78%|███████▊ | 94/121 [00:00<00:00, 4281.71 it/sec, feas=True, obj=3]
INFO - 16:24:38: 79%|███████▊ | 95/121 [00:00<00:00, 4286.30 it/sec, feas=True, obj=4]
INFO - 16:24:38: 79%|███████▉ | 96/121 [00:00<00:00, 4287.92 it/sec, feas=True, obj=5]
INFO - 16:24:38: 80%|████████ | 97/121 [00:00<00:00, 4291.91 it/sec, feas=True, obj=6]
INFO - 16:24:38: 81%|████████ | 98/121 [00:00<00:00, 4297.35 it/sec, feas=True, obj=7]
INFO - 16:24:38: 82%|████████▏ | 99/121 [00:00<00:00, 4303.14 it/sec, feas=True, obj=8]
INFO - 16:24:38: 83%|████████▎ | 100/121 [00:00<00:00, 4308.92 it/sec, feas=True, obj=-1]
INFO - 16:24:38: 83%|████████▎ | 101/121 [00:00<00:00, 4311.13 it/sec, feas=True, obj=0]
INFO - 16:24:38: 84%|████████▍ | 102/121 [00:00<00:00, 4316.35 it/sec, feas=True, obj=1]
INFO - 16:24:38: 85%|████████▌ | 103/121 [00:00<00:00, 4322.25 it/sec, feas=True, obj=2]
INFO - 16:24:38: 86%|████████▌ | 104/121 [00:00<00:00, 4327.84 it/sec, feas=True, obj=3]
INFO - 16:24:38: 87%|████████▋ | 105/121 [00:00<00:00, 4333.00 it/sec, feas=True, obj=4]
INFO - 16:24:38: 88%|████████▊ | 106/121 [00:00<00:00, 4334.35 it/sec, feas=True, obj=5]
INFO - 16:24:38: 88%|████████▊ | 107/121 [00:00<00:00, 4338.87 it/sec, feas=True, obj=6]
INFO - 16:24:38: 89%|████████▉ | 108/121 [00:00<00:00, 4343.93 it/sec, feas=True, obj=7]
INFO - 16:24:38: 90%|█████████ | 109/121 [00:00<00:00, 4348.21 it/sec, feas=True, obj=8]
INFO - 16:24:38: 91%|█████████ | 110/121 [00:00<00:00, 4352.95 it/sec, feas=True, obj=9]
INFO - 16:24:38: 92%|█████████▏| 111/121 [00:00<00:00, 4353.83 it/sec, feas=True, obj=0]
INFO - 16:24:38: 93%|█████████▎| 112/121 [00:00<00:00, 4358.49 it/sec, feas=True, obj=1]
INFO - 16:24:38: 93%|█████████▎| 113/121 [00:00<00:00, 4356.30 it/sec, feas=True, obj=2]
INFO - 16:24:38: 94%|█████████▍| 114/121 [00:00<00:00, 4357.92 it/sec, feas=True, obj=3]
INFO - 16:24:38: 95%|█████████▌| 115/121 [00:00<00:00, 4357.78 it/sec, feas=True, obj=4]
INFO - 16:24:38: 96%|█████████▌| 116/121 [00:00<00:00, 4360.14 it/sec, feas=True, obj=5]
INFO - 16:24:38: 97%|█████████▋| 117/121 [00:00<00:00, 4363.36 it/sec, feas=True, obj=6]
INFO - 16:24:38: 98%|█████████▊| 118/121 [00:00<00:00, 4366.79 it/sec, feas=True, obj=7]
INFO - 16:24:38: 98%|█████████▊| 119/121 [00:00<00:00, 4370.33 it/sec, feas=True, obj=8]
INFO - 16:24:38: 99%|█████████▉| 120/121 [00:00<00:00, 4370.55 it/sec, feas=True, obj=9]
INFO - 16:24:38: 100%|██████████| 121/121 [00:00<00:00, 4332.96 it/sec, feas=True, obj=10]
INFO - 16:24:38: Optimization result:
INFO - 16:24:38: Optimizer info:
INFO - 16:24:38: Status: None
INFO - 16:24:38: Message: None
INFO - 16:24:38: Solution:
INFO - 16:24:38: Objective: -10.0
INFO - 16:24:38: Design space:
INFO - 16:24:38: +------+-------------+-------+-------------+---------+
INFO - 16:24:38: | Name | Lower bound | Value | Upper bound | Type |
INFO - 16:24:38: +------+-------------+-------+-------------+---------+
INFO - 16:24:38: | x1 | -5 | -5 | 5 | integer |
INFO - 16:24:38: | x2 | -5 | -5 | 5 | integer |
INFO - 16:24:38: +------+-------------+-------+-------------+---------+
INFO - 16:24:38: *** End DOEScenario execution ***
Note that the algorithm settings passed to execute() can be provided
via a Pydantic model. For more information, see Algorithm Settings.
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', 'MorrisDOE', 'OATDOE', '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', 'PYDOE_BBDESIGN', 'PYDOE_CCDESIGN', 'PYDOE_FF2N', 'PYDOE_FULLFACT', 'PYDOE_LHS', 'PYDOE_PBDESIGN', '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', 'ConstraintsHistory', 'Correlations', 'DataVersusModel', 'GradientSensitivity', 'HessianHistory', 'ObjConstrHist', 'OptHistoryView', 'ParallelCoordinates', 'ParetoFront', 'QuadApprox', 'RadarChart', 'Robustness', 'SOM', 'ScatterPlotMatrix', 'TopologyView', 'VariableInfluence']
You can also look at the examples:
Total running time of the script: (0 minutes 0.036 seconds)