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:

\[\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 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:14:20: *** Start DOEScenario execution ***
INFO - 16:14:20: DOEScenario
INFO - 16:14:20:    Disciplines: AnalyticDiscipline
INFO - 16:14:20:    MDO formulation: DisciplinaryOpt
INFO - 16:14:20: Optimization problem:
INFO - 16:14:20:    minimize y(x1, x2)
INFO - 16:14:20:    with respect to x1, x2
INFO - 16:14:20:    over the design space:
INFO - 16:14:20:       +------+-------------+-------+-------------+---------+
INFO - 16:14:20:       | Name | Lower bound | Value | Upper bound | Type    |
INFO - 16:14:20:       +------+-------------+-------+-------------+---------+
INFO - 16:14:20:       | x1   |      -5     |  None |      5      | integer |
INFO - 16:14:20:       | x2   |      -5     |  None |      5      | integer |
INFO - 16:14:20:       +------+-------------+-------+-------------+---------+
INFO - 16:14:20: Solving optimization problem with algorithm PYDOE_FULLFACT:
INFO - 16:14:20:      1%|          | 1/121 [00:00<00:00, 470.64 it/sec, feas=True, obj=-10]
INFO - 16:14:20:      2%|▏         | 2/121 [00:00<00:00, 764.13 it/sec, feas=True, obj=-9]
INFO - 16:14:20:      2%|▏         | 3/121 [00:00<00:00, 970.38 it/sec, feas=True, obj=-8]
INFO - 16:14:20:      3%|▎         | 4/121 [00:00<00:00, 1128.03 it/sec, feas=True, obj=-7]
INFO - 16:14:20:      4%|▍         | 5/121 [00:00<00:00, 1253.83 it/sec, feas=True, obj=-6]
INFO - 16:14:20:      5%|▍         | 6/121 [00:00<00:00, 1354.24 it/sec, feas=True, obj=-5]
INFO - 16:14:20:      6%|▌         | 7/121 [00:00<00:00, 1432.13 it/sec, feas=True, obj=-4]
INFO - 16:14:20:      7%|▋         | 8/121 [00:00<00:00, 1501.59 it/sec, feas=True, obj=-3]
INFO - 16:14:20:      7%|▋         | 9/121 [00:00<00:00, 1565.49 it/sec, feas=True, obj=-2]
INFO - 16:14:20:      8%|▊         | 10/121 [00:00<00:00, 1611.40 it/sec, feas=True, obj=-1]
INFO - 16:14:20:      9%|▉         | 11/121 [00:00<00:00, 1661.53 it/sec, feas=True, obj=0]
INFO - 16:14:20:     10%|▉         | 12/121 [00:00<00:00, 1697.41 it/sec, feas=True, obj=-9]
INFO - 16:14:20:     11%|█         | 13/121 [00:00<00:00, 1737.21 it/sec, feas=True, obj=-8]
INFO - 16:14:20:     12%|█▏        | 14/121 [00:00<00:00, 1763.53 it/sec, feas=True, obj=-7]
INFO - 16:14:20:     12%|█▏        | 15/121 [00:00<00:00, 1796.33 it/sec, feas=True, obj=-6]
INFO - 16:14:20:     13%|█▎        | 16/121 [00:00<00:00, 1823.56 it/sec, feas=True, obj=-5]
INFO - 16:14:20:     14%|█▍        | 17/121 [00:00<00:00, 1843.03 it/sec, feas=True, obj=-4]
INFO - 16:14:20:     15%|█▍        | 18/121 [00:00<00:00, 1863.31 it/sec, feas=True, obj=-3]
INFO - 16:14:20:     16%|█▌        | 19/121 [00:00<00:00, 1882.68 it/sec, feas=True, obj=-2]
INFO - 16:14:20:     17%|█▋        | 20/121 [00:00<00:00, 1899.38 it/sec, feas=True, obj=-1]
INFO - 16:14:20:     17%|█▋        | 21/121 [00:00<00:00, 1914.00 it/sec, feas=True, obj=0]
INFO - 16:14:20:     18%|█▊        | 22/121 [00:00<00:00, 1927.73 it/sec, feas=True, obj=1]
INFO - 16:14:20:     19%|█▉        | 23/121 [00:00<00:00, 1941.49 it/sec, feas=True, obj=-8]
INFO - 16:14:20:     20%|█▉        | 24/121 [00:00<00:00, 1954.59 it/sec, feas=True, obj=-7]
INFO - 16:14:20:     21%|██        | 25/121 [00:00<00:00, 1969.49 it/sec, feas=True, obj=-6]
INFO - 16:14:20:     21%|██▏       | 26/121 [00:00<00:00, 1979.81 it/sec, feas=True, obj=-5]
INFO - 16:14:20:     22%|██▏       | 27/121 [00:00<00:00, 1988.90 it/sec, feas=True, obj=-4]
INFO - 16:14:20:     23%|██▎       | 28/121 [00:00<00:00, 1998.21 it/sec, feas=True, obj=-3]
INFO - 16:14:20:     24%|██▍       | 29/121 [00:00<00:00, 2007.18 it/sec, feas=True, obj=-2]
INFO - 16:14:20:     25%|██▍       | 30/121 [00:00<00:00, 2011.88 it/sec, feas=True, obj=-1]
INFO - 16:14:20:     26%|██▌       | 31/121 [00:00<00:00, 2022.67 it/sec, feas=True, obj=0]
INFO - 16:14:20:     26%|██▋       | 32/121 [00:00<00:00, 2030.34 it/sec, feas=True, obj=1]
INFO - 16:14:20:     27%|██▋       | 33/121 [00:00<00:00, 2037.00 it/sec, feas=True, obj=2]
INFO - 16:14:20:     28%|██▊       | 34/121 [00:00<00:00, 2043.60 it/sec, feas=True, obj=-7]
INFO - 16:14:20:     29%|██▉       | 35/121 [00:00<00:00, 2047.31 it/sec, feas=True, obj=-6]
INFO - 16:14:20:     30%|██▉       | 36/121 [00:00<00:00, 2053.57 it/sec, feas=True, obj=-5]
INFO - 16:14:20:     31%|███       | 37/121 [00:00<00:00, 2059.00 it/sec, feas=True, obj=-4]
INFO - 16:14:20:     31%|███▏      | 38/121 [00:00<00:00, 2064.50 it/sec, feas=True, obj=-3]
INFO - 16:14:20:     32%|███▏      | 39/121 [00:00<00:00, 2072.89 it/sec, feas=True, obj=-2]
INFO - 16:14:20:     33%|███▎      | 40/121 [00:00<00:00, 2075.59 it/sec, feas=True, obj=-1]
INFO - 16:14:20:     34%|███▍      | 41/121 [00:00<00:00, 2083.63 it/sec, feas=True, obj=0]
INFO - 16:14:20:     35%|███▍      | 42/121 [00:00<00:00, 2086.52 it/sec, feas=True, obj=1]
INFO - 16:14:20:     36%|███▌      | 43/121 [00:00<00:00, 2093.26 it/sec, feas=True, obj=2]
INFO - 16:14:20:     36%|███▋      | 44/121 [00:00<00:00, 2094.06 it/sec, feas=True, obj=3]
INFO - 16:14:20:     37%|███▋      | 45/121 [00:00<00:00, 2100.33 it/sec, feas=True, obj=-6]
INFO - 16:14:20:     38%|███▊      | 46/121 [00:00<00:00, 2101.81 it/sec, feas=True, obj=-5]
INFO - 16:14:20:     39%|███▉      | 47/121 [00:00<00:00, 2107.49 it/sec, feas=True, obj=-4]
INFO - 16:14:20:     40%|███▉      | 48/121 [00:00<00:00, 2112.31 it/sec, feas=True, obj=-3]
INFO - 16:14:20:     40%|████      | 49/121 [00:00<00:00, 2116.50 it/sec, feas=True, obj=-2]
INFO - 16:14:20:     41%|████▏     | 50/121 [00:00<00:00, 2121.12 it/sec, feas=True, obj=-1]
INFO - 16:14:20:     42%|████▏     | 51/121 [00:00<00:00, 2125.41 it/sec, feas=True, obj=0]
INFO - 16:14:20:     43%|████▎     | 52/121 [00:00<00:00, 2121.65 it/sec, feas=True, obj=1]
INFO - 16:14:20:     44%|████▍     | 53/121 [00:00<00:00, 2122.68 it/sec, feas=True, obj=2]
INFO - 16:14:20:     45%|████▍     | 54/121 [00:00<00:00, 2126.21 it/sec, feas=True, obj=3]
INFO - 16:14:20:     45%|████▌     | 55/121 [00:00<00:00, 2131.25 it/sec, feas=True, obj=4]
INFO - 16:14:20:     46%|████▋     | 56/121 [00:00<00:00, 2132.14 it/sec, feas=True, obj=-5]
INFO - 16:14:20:     47%|████▋     | 57/121 [00:00<00:00, 2136.91 it/sec, feas=True, obj=-4]
INFO - 16:14:20:     48%|████▊     | 58/121 [00:00<00:00, 2138.56 it/sec, feas=True, obj=-3]
INFO - 16:14:20:     49%|████▉     | 59/121 [00:00<00:00, 2142.92 it/sec, feas=True, obj=-2]
INFO - 16:14:20:     50%|████▉     | 60/121 [00:00<00:00, 2145.37 it/sec, feas=True, obj=-1]
INFO - 16:14:20:     50%|█████     | 61/121 [00:00<00:00, 2148.78 it/sec, feas=True, obj=0]
INFO - 16:14:20:     51%|█████     | 62/121 [00:00<00:00, 2153.67 it/sec, feas=True, obj=1]
INFO - 16:14:20:     52%|█████▏    | 63/121 [00:00<00:00, 2153.61 it/sec, feas=True, obj=2]
INFO - 16:14:20:     53%|█████▎    | 64/121 [00:00<00:00, 2158.15 it/sec, feas=True, obj=3]
INFO - 16:14:20:     54%|█████▎    | 65/121 [00:00<00:00, 2160.54 it/sec, feas=True, obj=4]
INFO - 16:14:20:     55%|█████▍    | 66/121 [00:00<00:00, 2162.98 it/sec, feas=True, obj=5]
INFO - 16:14:20:     55%|█████▌    | 67/121 [00:00<00:00, 2164.21 it/sec, feas=True, obj=-4]
INFO - 16:14:20:     56%|█████▌    | 68/121 [00:00<00:00, 2166.66 it/sec, feas=True, obj=-3]
INFO - 16:14:20:     57%|█████▋    | 69/121 [00:00<00:00, 2169.94 it/sec, feas=True, obj=-2]
INFO - 16:14:20:     58%|█████▊    | 70/121 [00:00<00:00, 2169.31 it/sec, feas=True, obj=-1]
INFO - 16:14:20:     59%|█████▊    | 71/121 [00:00<00:00, 2172.83 it/sec, feas=True, obj=0]
INFO - 16:14:20:     60%|█████▉    | 72/121 [00:00<00:00, 2171.81 it/sec, feas=True, obj=1]
INFO - 16:14:20:     60%|██████    | 73/121 [00:00<00:00, 2174.31 it/sec, feas=True, obj=2]
INFO - 16:14:20:     61%|██████    | 74/121 [00:00<00:00, 2173.35 it/sec, feas=True, obj=3]
INFO - 16:14:20:     62%|██████▏   | 75/121 [00:00<00:00, 2176.55 it/sec, feas=True, obj=4]
INFO - 16:14:20:     63%|██████▎   | 76/121 [00:00<00:00, 2176.79 it/sec, feas=True, obj=5]
INFO - 16:14:20:     64%|██████▎   | 77/121 [00:00<00:00, 2179.73 it/sec, feas=True, obj=6]
INFO - 16:14:20:     64%|██████▍   | 78/121 [00:00<00:00, 2181.47 it/sec, feas=True, obj=-3]
INFO - 16:14:20:     65%|██████▌   | 79/121 [00:00<00:00, 2183.04 it/sec, feas=True, obj=-2]
INFO - 16:14:20:     66%|██████▌   | 80/121 [00:00<00:00, 2185.22 it/sec, feas=True, obj=-1]
INFO - 16:14:20:     67%|██████▋   | 81/121 [00:00<00:00, 2186.66 it/sec, feas=True, obj=0]
INFO - 16:14:20:     68%|██████▊   | 82/121 [00:00<00:00, 2188.13 it/sec, feas=True, obj=1]
INFO - 16:14:20:     69%|██████▊   | 83/121 [00:00<00:00, 2189.53 it/sec, feas=True, obj=2]
INFO - 16:14:20:     69%|██████▉   | 84/121 [00:00<00:00, 2191.64 it/sec, feas=True, obj=3]
INFO - 16:14:20:     70%|███████   | 85/121 [00:00<00:00, 2194.79 it/sec, feas=True, obj=4]
INFO - 16:14:20:     71%|███████   | 86/121 [00:00<00:00, 2195.50 it/sec, feas=True, obj=5]
INFO - 16:14:20:     72%|███████▏  | 87/121 [00:00<00:00, 2198.62 it/sec, feas=True, obj=6]
INFO - 16:14:20:     73%|███████▎  | 88/121 [00:00<00:00, 2199.91 it/sec, feas=True, obj=7]
INFO - 16:14:20:     74%|███████▎  | 89/121 [00:00<00:00, 2202.11 it/sec, feas=True, obj=-2]
INFO - 16:14:20:     74%|███████▍  | 90/121 [00:00<00:00, 2204.91 it/sec, feas=True, obj=-1]
INFO - 16:14:20:     75%|███████▌  | 91/121 [00:00<00:00, 2204.25 it/sec, feas=True, obj=0]
INFO - 16:14:20:     76%|███████▌  | 92/121 [00:00<00:00, 2206.92 it/sec, feas=True, obj=1]
INFO - 16:14:20:     77%|███████▋  | 93/121 [00:00<00:00, 2207.95 it/sec, feas=True, obj=2]
INFO - 16:14:20:     78%|███████▊  | 94/121 [00:00<00:00, 2209.51 it/sec, feas=True, obj=3]
INFO - 16:14:20:     79%|███████▊  | 95/121 [00:00<00:00, 2209.78 it/sec, feas=True, obj=4]
INFO - 16:14:20:     79%|███████▉  | 96/121 [00:00<00:00, 2211.49 it/sec, feas=True, obj=5]
INFO - 16:14:20:     80%|████████  | 97/121 [00:00<00:00, 2211.19 it/sec, feas=True, obj=6]
INFO - 16:14:20:     81%|████████  | 98/121 [00:00<00:00, 2213.48 it/sec, feas=True, obj=7]
INFO - 16:14:20:     82%|████████▏ | 99/121 [00:00<00:00, 2214.75 it/sec, feas=True, obj=8]
INFO - 16:14:20:     83%|████████▎ | 100/121 [00:00<00:00, 2215.40 it/sec, feas=True, obj=-1]
INFO - 16:14:20:     83%|████████▎ | 101/121 [00:00<00:00, 2216.43 it/sec, feas=True, obj=0]
INFO - 16:14:20:     84%|████████▍ | 102/121 [00:00<00:00, 2218.10 it/sec, feas=True, obj=1]
INFO - 16:14:20:     85%|████████▌ | 103/121 [00:00<00:00, 2219.22 it/sec, feas=True, obj=2]
INFO - 16:14:20:     86%|████████▌ | 104/121 [00:00<00:00, 2219.64 it/sec, feas=True, obj=3]
INFO - 16:14:20:     87%|████████▋ | 105/121 [00:00<00:00, 2220.67 it/sec, feas=True, obj=4]
INFO - 16:14:20:     88%|████████▊ | 106/121 [00:00<00:00, 2222.57 it/sec, feas=True, obj=5]
INFO - 16:14:20:     88%|████████▊ | 107/121 [00:00<00:00, 2222.47 it/sec, feas=True, obj=6]
INFO - 16:14:20:     89%|████████▉ | 108/121 [00:00<00:00, 2224.54 it/sec, feas=True, obj=7]
INFO - 16:14:20:     90%|█████████ | 109/121 [00:00<00:00, 2224.50 it/sec, feas=True, obj=8]
INFO - 16:14:20:     91%|█████████ | 110/121 [00:00<00:00, 2226.07 it/sec, feas=True, obj=9]
INFO - 16:14:20:     92%|█████████▏| 111/121 [00:00<00:00, 2225.67 it/sec, feas=True, obj=0]
INFO - 16:14:20:     93%|█████████▎| 112/121 [00:00<00:00, 2227.36 it/sec, feas=True, obj=1]
INFO - 16:14:20:     93%|█████████▎| 113/121 [00:00<00:00, 2228.30 it/sec, feas=True, obj=2]
INFO - 16:14:20:     94%|█████████▍| 114/121 [00:00<00:00, 2229.12 it/sec, feas=True, obj=3]
INFO - 16:14:20:     95%|█████████▌| 115/121 [00:00<00:00, 2230.05 it/sec, feas=True, obj=4]
INFO - 16:14:20:     96%|█████████▌| 116/121 [00:00<00:00, 2231.23 it/sec, feas=True, obj=5]
INFO - 16:14:20:     97%|█████████▋| 117/121 [00:00<00:00, 2231.61 it/sec, feas=True, obj=6]
INFO - 16:14:20:     98%|█████████▊| 118/121 [00:00<00:00, 2231.85 it/sec, feas=True, obj=7]
INFO - 16:14:20:     98%|█████████▊| 119/121 [00:00<00:00, 2232.35 it/sec, feas=True, obj=8]
INFO - 16:14:20:     99%|█████████▉| 120/121 [00:00<00:00, 2233.21 it/sec, feas=True, obj=9]
INFO - 16:14:20:    100%|██████████| 121/121 [00:00<00:00, 2220.59 it/sec, feas=True, obj=10]
INFO - 16:14:20: Optimization result:
INFO - 16:14:20:    Optimizer info:
INFO - 16:14:20:       Status: None
INFO - 16:14:20:       Message: None
INFO - 16:14:20:    Solution:
INFO - 16:14:20:       Objective: -10.0
INFO - 16:14:20:       Design space:
INFO - 16:14:20:          +------+-------------+-------+-------------+---------+
INFO - 16:14:20:          | Name | Lower bound | Value | Upper bound | Type    |
INFO - 16:14:20:          +------+-------------+-------+-------------+---------+
INFO - 16:14:20:          | x1   |      -5     |   -5  |      5      | integer |
INFO - 16:14:20:          | x2   |      -5     |   -5  |      5      | integer |
INFO - 16:14:20:          +------+-------------+-------+-------------+---------+
INFO - 16:14:20: *** 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', 'TopologyGifAnimation', 'TopologyView', 'VariableInfluence']

You can also look at the examples:

Total running time of the script: (0 minutes 0.066 seconds)

Gallery generated by Sphinx-Gallery