Note
Click here to download the full example code
Create a DOE Scenario¶
from __future__ import annotations
from gemseo.api import configure_logger
from gemseo.api import create_design_space
from gemseo.api import create_discipline
from gemseo.api import create_scenario
from gemseo.api import get_available_doe_algorithms
from gemseo.api 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 - 16:57:56:
INFO - 16:57:56: *** Start DOEScenario execution ***
INFO - 16:57:56: DOEScenario
INFO - 16:57:56: Disciplines: AnalyticDiscipline
INFO - 16:57:56: MDO formulation: DisciplinaryOpt
INFO - 16:57:56: Optimization problem:
INFO - 16:57:56: minimize y(x1, x2)
INFO - 16:57:56: with respect to x1, x2
INFO - 16:57:56: over the design space:
INFO - 16:57:56: +------+-------------+-------+-------------+---------+
INFO - 16:57:56: | name | lower_bound | value | upper_bound | type |
INFO - 16:57:56: +------+-------------+-------+-------------+---------+
INFO - 16:57:56: | x1 | -5 | None | 5 | integer |
INFO - 16:57:56: | x2 | -5 | None | 5 | integer |
INFO - 16:57:56: +------+-------------+-------+-------------+---------+
INFO - 16:57:56: Solving optimization problem with algorithm fullfact:
INFO - 16:57:56: ... 0%| | 0/121 [00:00<?, ?it]
INFO - 16:57:56: ... 1%| | 1/121 [00:00<00:00, 380.75 it/sec, obj=-10]
INFO - 16:57:56: ... 2%|▏ | 2/121 [00:00<00:00, 627.51 it/sec, obj=-9]
INFO - 16:57:56: ... 2%|▏ | 3/121 [00:00<00:00, 812.32 it/sec, obj=-8]
INFO - 16:57:56: ... 3%|▎ | 4/121 [00:00<00:00, 955.26 it/sec, obj=-7]
INFO - 16:57:56: ... 4%|▍ | 5/121 [00:00<00:00, 1056.13 it/sec, obj=-6]
INFO - 16:57:56: ... 5%|▍ | 6/121 [00:00<00:00, 1130.29 it/sec, obj=-5]
INFO - 16:57:56: ... 6%|▌ | 7/121 [00:00<00:00, 1185.26 it/sec, obj=-4]
INFO - 16:57:56: ... 7%|▋ | 8/121 [00:00<00:00, 1248.40 it/sec, obj=-3]
INFO - 16:57:56: ... 7%|▋ | 9/121 [00:00<00:00, 1304.15 it/sec, obj=-2]
INFO - 16:57:56: ... 8%|▊ | 10/121 [00:00<00:00, 1352.74 it/sec, obj=-1]
INFO - 16:57:56: ... 9%|▉ | 11/121 [00:00<00:00, 1395.61 it/sec, obj=0]
INFO - 16:57:56: ... 10%|▉ | 12/121 [00:00<00:00, 1433.42 it/sec, obj=-9]
INFO - 16:57:56: ... 11%|█ | 13/121 [00:00<00:00, 1453.75 it/sec, obj=-8]
INFO - 16:57:56: ... 12%|█▏ | 14/121 [00:00<00:00, 1471.39 it/sec, obj=-7]
INFO - 16:57:56: ... 12%|█▏ | 15/121 [00:00<00:00, 1488.29 it/sec, obj=-6]
INFO - 16:57:56: ... 13%|█▎ | 16/121 [00:00<00:00, 1513.61 it/sec, obj=-5]
INFO - 16:57:56: ... 14%|█▍ | 17/121 [00:00<00:00, 1537.00 it/sec, obj=-4]
INFO - 16:57:56: ... 15%|█▍ | 18/121 [00:00<00:00, 1558.03 it/sec, obj=-3]
INFO - 16:57:56: ... 16%|█▌ | 19/121 [00:00<00:00, 1577.65 it/sec, obj=-2]
INFO - 16:57:56: ... 17%|█▋ | 20/121 [00:00<00:00, 1593.85 it/sec, obj=-1]
INFO - 16:57:56: ... 17%|█▋ | 21/121 [00:00<00:00, 1598.15 it/sec, obj=0]
INFO - 16:57:56: ... 18%|█▊ | 22/121 [00:00<00:00, 1604.78 it/sec, obj=1]
INFO - 16:57:56: ... 19%|█▉ | 23/121 [00:00<00:00, 1612.55 it/sec, obj=-8]
INFO - 16:57:56: ... 20%|█▉ | 24/121 [00:00<00:00, 1626.41 it/sec, obj=-7]
INFO - 16:57:56: ... 21%|██ | 25/121 [00:00<00:00, 1639.60 it/sec, obj=-6]
INFO - 16:57:56: ... 21%|██▏ | 26/121 [00:00<00:00, 1652.00 it/sec, obj=-5]
INFO - 16:57:56: ... 22%|██▏ | 27/121 [00:00<00:00, 1663.99 it/sec, obj=-4]
INFO - 16:57:56: ... 23%|██▎ | 28/121 [00:00<00:00, 1669.33 it/sec, obj=-3]
INFO - 16:57:56: ... 24%|██▍ | 29/121 [00:00<00:00, 1671.77 it/sec, obj=-2]
INFO - 16:57:56: ... 25%|██▍ | 30/121 [00:00<00:00, 1672.73 it/sec, obj=-1]
INFO - 16:57:56: ... 26%|██▌ | 31/121 [00:00<00:00, 1681.78 it/sec, obj=0]
INFO - 16:57:56: ... 26%|██▋ | 32/121 [00:00<00:00, 1691.02 it/sec, obj=1]
INFO - 16:57:56: ... 27%|██▋ | 33/121 [00:00<00:00, 1700.12 it/sec, obj=2]
INFO - 16:57:56: ... 28%|██▊ | 34/121 [00:00<00:00, 1708.56 it/sec, obj=-7]
INFO - 16:57:56: ... 29%|██▉ | 35/121 [00:00<00:00, 1716.50 it/sec, obj=-6]
INFO - 16:57:56: ... 30%|██▉ | 36/121 [00:00<00:00, 1716.81 it/sec, obj=-5]
INFO - 16:57:56: ... 31%|███ | 37/121 [00:00<00:00, 1717.78 it/sec, obj=-4]
INFO - 16:57:56: ... 31%|███▏ | 38/121 [00:00<00:00, 1717.44 it/sec, obj=-3]
INFO - 16:57:56: ... 32%|███▏ | 39/121 [00:00<00:00, 1723.90 it/sec, obj=-2]
INFO - 16:57:56: ... 33%|███▎ | 40/121 [00:00<00:00, 1730.38 it/sec, obj=-1]
INFO - 16:57:56: ... 34%|███▍ | 41/121 [00:00<00:00, 1736.74 it/sec, obj=0]
INFO - 16:57:56: ... 35%|███▍ | 42/121 [00:00<00:00, 1742.79 it/sec, obj=1]
INFO - 16:57:56: ... 36%|███▌ | 43/121 [00:00<00:00, 1745.75 it/sec, obj=2]
INFO - 16:57:56: ... 36%|███▋ | 44/121 [00:00<00:00, 1745.81 it/sec, obj=3]
INFO - 16:57:56: ... 37%|███▋ | 45/121 [00:00<00:00, 1743.46 it/sec, obj=-6]
INFO - 16:57:56: ... 38%|███▊ | 46/121 [00:00<00:00, 1748.62 it/sec, obj=-5]
INFO - 16:57:56: ... 39%|███▉ | 47/121 [00:00<00:00, 1753.80 it/sec, obj=-4]
INFO - 16:57:56: ... 40%|███▉ | 48/121 [00:00<00:00, 1759.05 it/sec, obj=-3]
INFO - 16:57:56: ... 40%|████ | 49/121 [00:00<00:00, 1764.01 it/sec, obj=-2]
INFO - 16:57:56: ... 41%|████▏ | 50/121 [00:00<00:00, 1768.96 it/sec, obj=-1]
INFO - 16:57:56: ... 42%|████▏ | 51/121 [00:00<00:00, 1769.62 it/sec, obj=0]
INFO - 16:57:56: ... 43%|████▎ | 52/121 [00:00<00:00, 1768.04 it/sec, obj=1]
INFO - 16:57:56: ... 44%|████▍ | 53/121 [00:00<00:00, 1766.70 it/sec, obj=2]
INFO - 16:57:56: ... 45%|████▍ | 54/121 [00:00<00:00, 1768.21 it/sec, obj=3]
INFO - 16:57:56: ... 45%|████▌ | 55/121 [00:00<00:00, 1771.86 it/sec, obj=4]
INFO - 16:57:56: ... 46%|████▋ | 56/121 [00:00<00:00, 1775.86 it/sec, obj=-5]
INFO - 16:57:56: ... 47%|████▋ | 57/121 [00:00<00:00, 1780.07 it/sec, obj=-4]
INFO - 16:57:56: ... 48%|████▊ | 58/121 [00:00<00:00, 1784.14 it/sec, obj=-3]
INFO - 16:57:56: ... 49%|████▉ | 59/121 [00:00<00:00, 1782.15 it/sec, obj=-2]
INFO - 16:57:56: ... 50%|████▉ | 60/121 [00:00<00:00, 1781.74 it/sec, obj=-1]
INFO - 16:57:56: ... 50%|█████ | 61/121 [00:00<00:00, 1782.67 it/sec, obj=0]
INFO - 16:57:56: ... 51%|█████ | 62/121 [00:00<00:00, 1786.10 it/sec, obj=1]
INFO - 16:57:56: ... 52%|█████▏ | 63/121 [00:00<00:00, 1788.79 it/sec, obj=2]
INFO - 16:57:56: ... 53%|█████▎ | 64/121 [00:00<00:00, 1791.90 it/sec, obj=3]
INFO - 16:57:56: ... 54%|█████▎ | 65/121 [00:00<00:00, 1795.36 it/sec, obj=4]
INFO - 16:57:56: ... 55%|█████▍ | 66/121 [00:00<00:00, 1795.81 it/sec, obj=5]
INFO - 16:57:56: ... 55%|█████▌ | 67/121 [00:00<00:00, 1795.00 it/sec, obj=-4]
INFO - 16:57:56: ... 56%|█████▌ | 68/121 [00:00<00:00, 1793.67 it/sec, obj=-3]
INFO - 16:57:56: ... 57%|█████▋ | 69/121 [00:00<00:00, 1792.94 it/sec, obj=-2]
INFO - 16:57:56: ... 58%|█████▊ | 70/121 [00:00<00:00, 1795.54 it/sec, obj=-1]
INFO - 16:57:56: ... 59%|█████▊ | 71/121 [00:00<00:00, 1798.51 it/sec, obj=0]
INFO - 16:57:56: ... 60%|█████▉ | 72/121 [00:00<00:00, 1801.38 it/sec, obj=1]
INFO - 16:57:56: ... 60%|██████ | 73/121 [00:00<00:00, 1803.46 it/sec, obj=2]
INFO - 16:57:56: ... 61%|██████ | 74/121 [00:00<00:00, 1801.50 it/sec, obj=3]
INFO - 16:57:56: ... 62%|██████▏ | 75/121 [00:00<00:00, 1800.78 it/sec, obj=4]
INFO - 16:57:56: ... 63%|██████▎ | 76/121 [00:00<00:00, 1801.19 it/sec, obj=5]
INFO - 16:57:56: ... 64%|██████▎ | 77/121 [00:00<00:00, 1803.70 it/sec, obj=6]
INFO - 16:57:56: ... 64%|██████▍ | 78/121 [00:00<00:00, 1806.40 it/sec, obj=-3]
INFO - 16:57:56: ... 65%|██████▌ | 79/121 [00:00<00:00, 1809.00 it/sec, obj=-2]
INFO - 16:57:56: ... 66%|██████▌ | 80/121 [00:00<00:00, 1811.70 it/sec, obj=-1]
INFO - 16:57:56: ... 67%|██████▋ | 81/121 [00:00<00:00, 1812.38 it/sec, obj=0]
INFO - 16:57:56: ... 68%|██████▊ | 82/121 [00:00<00:00, 1811.56 it/sec, obj=1]
INFO - 16:57:56: ... 69%|██████▊ | 83/121 [00:00<00:00, 1809.38 it/sec, obj=2]
INFO - 16:57:56: ... 69%|██████▉ | 84/121 [00:00<00:00, 1811.65 it/sec, obj=3]
INFO - 16:57:56: ... 70%|███████ | 85/121 [00:00<00:00, 1814.01 it/sec, obj=4]
INFO - 16:57:56: ... 71%|███████ | 86/121 [00:00<00:00, 1816.37 it/sec, obj=5]
INFO - 16:57:56: ... 72%|███████▏ | 87/121 [00:00<00:00, 1818.57 it/sec, obj=6]
INFO - 16:57:56: ... 73%|███████▎ | 88/121 [00:00<00:00, 1820.79 it/sec, obj=7]
INFO - 16:57:56: ... 74%|███████▎ | 89/121 [00:00<00:00, 1820.14 it/sec, obj=-2]
INFO - 16:57:56: ... 74%|███████▍ | 90/121 [00:00<00:00, 1819.17 it/sec, obj=-1]
INFO - 16:57:56: ... 75%|███████▌ | 91/121 [00:00<00:00, 1818.68 it/sec, obj=0]
INFO - 16:57:56: ... 76%|███████▌ | 92/121 [00:00<00:00, 1820.82 it/sec, obj=1]
INFO - 16:57:56: ... 77%|███████▋ | 93/121 [00:00<00:00, 1822.80 it/sec, obj=2]
INFO - 16:57:56: ... 78%|███████▊ | 94/121 [00:00<00:00, 1824.93 it/sec, obj=3]
INFO - 16:57:56: ... 79%|███████▊ | 95/121 [00:00<00:00, 1826.88 it/sec, obj=4]
INFO - 16:57:56: ... 79%|███████▉ | 96/121 [00:00<00:00, 1828.84 it/sec, obj=5]
INFO - 16:57:56: ... 80%|████████ | 97/121 [00:00<00:00, 1827.07 it/sec, obj=6]
INFO - 16:57:56: ... 81%|████████ | 98/121 [00:00<00:00, 1826.33 it/sec, obj=7]
INFO - 16:57:56: ... 82%|████████▏ | 99/121 [00:00<00:00, 1826.00 it/sec, obj=8]
INFO - 16:57:56: ... 83%|████████▎ | 100/121 [00:00<00:00, 1827.75 it/sec, obj=-1]
INFO - 16:57:56: ... 83%|████████▎ | 101/121 [00:00<00:00, 1829.50 it/sec, obj=0]
INFO - 16:57:56: ... 84%|████████▍ | 102/121 [00:00<00:00, 1831.33 it/sec, obj=1]
INFO - 16:57:56: ... 85%|████████▌ | 103/121 [00:00<00:00, 1833.10 it/sec, obj=2]
INFO - 16:57:56: ... 86%|████████▌ | 104/121 [00:00<00:00, 1833.04 it/sec, obj=3]
INFO - 16:57:56: ... 87%|████████▋ | 105/121 [00:00<00:00, 1832.11 it/sec, obj=4]
INFO - 16:57:56: ... 88%|████████▊ | 106/121 [00:00<00:00, 1830.16 it/sec, obj=5]
INFO - 16:57:56: ... 88%|████████▊ | 107/121 [00:00<00:00, 1831.69 it/sec, obj=6]
INFO - 16:57:56: ... 89%|████████▉ | 108/121 [00:00<00:00, 1833.35 it/sec, obj=7]
INFO - 16:57:56: ... 90%|█████████ | 109/121 [00:00<00:00, 1834.96 it/sec, obj=8]
INFO - 16:57:56: ... 91%|█████████ | 110/121 [00:00<00:00, 1836.64 it/sec, obj=9]
INFO - 16:57:56: ... 92%|█████████▏| 111/121 [00:00<00:00, 1838.27 it/sec, obj=0]
INFO - 16:57:56: ... 93%|█████████▎| 112/121 [00:00<00:00, 1837.33 it/sec, obj=1]
INFO - 16:57:56: ... 93%|█████████▎| 113/121 [00:00<00:00, 1836.41 it/sec, obj=2]
INFO - 16:57:56: ... 94%|█████████▍| 114/121 [00:00<00:00, 1836.05 it/sec, obj=3]
INFO - 16:57:56: ... 95%|█████████▌| 115/121 [00:00<00:00, 1837.52 it/sec, obj=4]
INFO - 16:57:56: ... 96%|█████████▌| 116/121 [00:00<00:00, 1839.13 it/sec, obj=5]
INFO - 16:57:56: ... 97%|█████████▋| 117/121 [00:00<00:00, 1840.66 it/sec, obj=6]
INFO - 16:57:56: ... 98%|█████████▊| 118/121 [00:00<00:00, 1842.22 it/sec, obj=7]
INFO - 16:57:56: ... 98%|█████████▊| 119/121 [00:00<00:00, 1843.40 it/sec, obj=8]
INFO - 16:57:56: ... 99%|█████████▉| 120/121 [00:00<00:00, 1842.03 it/sec, obj=9]
INFO - 16:57:56: ... 100%|██████████| 121/121 [00:00<00:00, 1841.32 it/sec, obj=10]
INFO - 16:57:56: Optimization result:
INFO - 16:57:56: Optimizer info:
INFO - 16:57:56: Status: None
INFO - 16:57:56: Message: None
INFO - 16:57:56: Number of calls to the objective function by the optimizer: 121
INFO - 16:57:56: Solution:
INFO - 16:57:56: Objective: -10.0
INFO - 16:57:56: Design space:
INFO - 16:57:56: +------+-------------+-------+-------------+---------+
INFO - 16:57:56: | name | lower_bound | value | upper_bound | type |
INFO - 16:57:56: +------+-------------+-------+-------------+---------+
INFO - 16:57:56: | x1 | -5 | -5 | 5 | integer |
INFO - 16:57:56: | x2 | -5 | -5 | 5 | integer |
INFO - 16:57:56: +------+-------------+-------+-------------+---------+
INFO - 16:57:56: *** End DOEScenario execution (time: 0:00:00.074725) ***
{'eval_jac': False, 'algo': 'fullfact', 'n_samples': 121}
The optimum results can be found in the execution log. It is also possible to
extract them by invoking the Scenario.get_optimum()
method. It
returns a dictionary containing the optimum results for the
scenario under consideration:
opt_results = scenario.get_optimum()
print(
"The solution of P is (x*,f(x*)) = ({}, {})".format(
opt_results.x_opt, opt_results.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:
algo_list = get_available_doe_algorithms()
print(f"Available algorithms: {algo_list}")
Available 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:
post_list = get_available_post_processings()
print(f"Available algorithms: {post_list}")
Available algorithms: ['BasicHistory', 'Compromise', 'ConstraintsHistory', 'Correlations', 'GradientSensitivity', 'HighTradeOff', 'KMeans', 'MultiObjectiveDiagram', 'ObjConstrHist', 'OptHistoryView', 'ParallelCoordinates', 'ParetoFront', 'Petal', 'QuadApprox', 'Radar', 'RadarChart', 'Robustness', 'SOM', 'ScatterPareto', 'ScatterPlotMatrix', 'VariableInfluence']
You can also look at the examples:
Total running time of the script: ( 0 minutes 0.091 seconds)