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:

\[\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 - 08:35:54:
INFO - 08:35:54: *** Start DOEScenario execution ***
INFO - 08:35:54: DOEScenario
INFO - 08:35:54:    Disciplines: AnalyticDiscipline
INFO - 08:35:54:    MDO formulation: DisciplinaryOpt
INFO - 08:35:54: Optimization problem:
INFO - 08:35:54:    minimize y(x1, x2)
INFO - 08:35:54:    with respect to x1, x2
INFO - 08:35:54:    over the design space:
INFO - 08:35:54:       +------+-------------+-------+-------------+---------+
INFO - 08:35:54:       | Name | Lower bound | Value | Upper bound | Type    |
INFO - 08:35:54:       +------+-------------+-------+-------------+---------+
INFO - 08:35:54:       | x1   |      -5     |  None |      5      | integer |
INFO - 08:35:54:       | x2   |      -5     |  None |      5      | integer |
INFO - 08:35:54:       +------+-------------+-------+-------------+---------+
INFO - 08:35:54: Solving optimization problem with algorithm PYDOE_FULLFACT:
INFO - 08:35:54:      1%|          | 1/121 [00:00<00:00, 451.58 it/sec, obj=-10]
INFO - 08:35:54:      2%|▏         | 2/121 [00:00<00:00, 739.15 it/sec, obj=-9]
INFO - 08:35:54:      2%|▏         | 3/121 [00:00<00:00, 955.28 it/sec, obj=-8]
INFO - 08:35:54:      3%|▎         | 4/121 [00:00<00:00, 1118.11 it/sec, obj=-7]
INFO - 08:35:54:      4%|▍         | 5/121 [00:00<00:00, 1245.41 it/sec, obj=-6]
INFO - 08:35:54:      5%|▍         | 6/121 [00:00<00:00, 1348.36 it/sec, obj=-5]
INFO - 08:35:54:      6%|▌         | 7/121 [00:00<00:00, 1426.63 it/sec, obj=-4]
INFO - 08:35:54:      7%|▋         | 8/121 [00:00<00:00, 1500.58 it/sec, obj=-3]
INFO - 08:35:54:      7%|▋         | 9/121 [00:00<00:00, 1564.58 it/sec, obj=-2]
INFO - 08:35:54:      8%|▊         | 10/121 [00:00<00:00, 1615.99 it/sec, obj=-1]
INFO - 08:35:54:      9%|▉         | 11/121 [00:00<00:00, 1663.15 it/sec, obj=0]
INFO - 08:35:54:     10%|▉         | 12/121 [00:00<00:00, 1705.00 it/sec, obj=-9]
INFO - 08:35:54:     11%|█         | 13/121 [00:00<00:00, 1742.82 it/sec, obj=-8]
INFO - 08:35:54:     12%|█▏        | 14/121 [00:00<00:00, 1777.03 it/sec, obj=-7]
INFO - 08:35:54:     12%|█▏        | 15/121 [00:00<00:00, 1807.27 it/sec, obj=-6]
INFO - 08:35:54:     13%|█▎        | 16/121 [00:00<00:00, 1826.79 it/sec, obj=-5]
INFO - 08:35:54:     14%|█▍        | 17/121 [00:00<00:00, 1849.44 it/sec, obj=-4]
INFO - 08:35:54:     15%|█▍        | 18/121 [00:00<00:00, 1871.53 it/sec, obj=-3]
INFO - 08:35:54:     16%|█▌        | 19/121 [00:00<00:00, 1892.38 it/sec, obj=-2]
INFO - 08:35:54:     17%|█▋        | 20/121 [00:00<00:00, 1908.28 it/sec, obj=-1]
INFO - 08:35:54:     17%|█▋        | 21/121 [00:00<00:00, 1926.18 it/sec, obj=0]
INFO - 08:35:54:     18%|█▊        | 22/121 [00:00<00:00, 1943.20 it/sec, obj=1]
INFO - 08:35:54:     19%|█▉        | 23/121 [00:00<00:00, 1939.82 it/sec, obj=-8]
INFO - 08:35:54:     20%|█▉        | 24/121 [00:00<00:00, 1952.81 it/sec, obj=-7]
INFO - 08:35:54:     21%|██        | 25/121 [00:00<00:00, 1960.76 it/sec, obj=-6]
INFO - 08:35:54:     21%|██▏       | 26/121 [00:00<00:00, 1972.43 it/sec, obj=-5]
INFO - 08:35:54:     22%|██▏       | 27/121 [00:00<00:00, 1984.69 it/sec, obj=-4]
INFO - 08:35:54:     23%|██▎       | 28/121 [00:00<00:00, 1996.24 it/sec, obj=-3]
INFO - 08:35:54:     24%|██▍       | 29/121 [00:00<00:00, 2004.36 it/sec, obj=-2]
INFO - 08:35:54:     25%|██▍       | 30/121 [00:00<00:00, 2014.36 it/sec, obj=-1]
INFO - 08:35:54:     26%|██▌       | 31/121 [00:00<00:00, 2024.06 it/sec, obj=0]
INFO - 08:35:54:     26%|██▋       | 32/121 [00:00<00:00, 2033.23 it/sec, obj=1]
INFO - 08:35:54:     27%|██▋       | 33/121 [00:00<00:00, 2042.11 it/sec, obj=2]
INFO - 08:35:54:     28%|██▊       | 34/121 [00:00<00:00, 2050.68 it/sec, obj=-7]
INFO - 08:35:54:     29%|██▉       | 35/121 [00:00<00:00, 2054.74 it/sec, obj=-6]
INFO - 08:35:54:     30%|██▉       | 36/121 [00:00<00:00, 2062.01 it/sec, obj=-5]
INFO - 08:35:54:     31%|███       | 37/121 [00:00<00:00, 2069.33 it/sec, obj=-4]
INFO - 08:35:54:     31%|███▏      | 38/121 [00:00<00:00, 2074.47 it/sec, obj=-3]
INFO - 08:35:54:     32%|███▏      | 39/121 [00:00<00:00, 2081.09 it/sec, obj=-2]
INFO - 08:35:54:     33%|███▎      | 40/121 [00:00<00:00, 2087.58 it/sec, obj=-1]
INFO - 08:35:54:     34%|███▍      | 41/121 [00:00<00:00, 2093.76 it/sec, obj=0]
INFO - 08:35:54:     35%|███▍      | 42/121 [00:00<00:00, 2099.60 it/sec, obj=1]
INFO - 08:35:54:     36%|███▌      | 43/121 [00:00<00:00, 2103.14 it/sec, obj=2]
INFO - 08:35:54:     36%|███▋      | 44/121 [00:00<00:00, 2105.07 it/sec, obj=3]
INFO - 08:35:54:     37%|███▋      | 45/121 [00:00<00:00, 2109.53 it/sec, obj=-6]
INFO - 08:35:54:     38%|███▊      | 46/121 [00:00<00:00, 2114.50 it/sec, obj=-5]
INFO - 08:35:54:     39%|███▉      | 47/121 [00:00<00:00, 2118.02 it/sec, obj=-4]
INFO - 08:35:54:     40%|███▉      | 48/121 [00:00<00:00, 2122.40 it/sec, obj=-3]
INFO - 08:35:54:     40%|████      | 49/121 [00:00<00:00, 2126.86 it/sec, obj=-2]
INFO - 08:35:54:     41%|████▏     | 50/121 [00:00<00:00, 2131.34 it/sec, obj=-1]
INFO - 08:35:54:     42%|████▏     | 51/121 [00:00<00:00, 2135.87 it/sec, obj=0]
INFO - 08:35:54:     43%|████▎     | 52/121 [00:00<00:00, 2140.22 it/sec, obj=1]
INFO - 08:35:54:     44%|████▍     | 53/121 [00:00<00:00, 2142.16 it/sec, obj=2]
INFO - 08:35:54:     45%|████▍     | 54/121 [00:00<00:00, 2145.59 it/sec, obj=3]
INFO - 08:35:54:     45%|████▌     | 55/121 [00:00<00:00, 2149.06 it/sec, obj=4]
INFO - 08:35:54:     46%|████▋     | 56/121 [00:00<00:00, 2152.82 it/sec, obj=-5]
INFO - 08:35:54:     47%|████▋     | 57/121 [00:00<00:00, 2154.92 it/sec, obj=-4]
INFO - 08:35:54:     48%|████▊     | 58/121 [00:00<00:00, 2158.25 it/sec, obj=-3]
INFO - 08:35:54:     49%|████▉     | 59/121 [00:00<00:00, 2161.54 it/sec, obj=-2]
INFO - 08:35:54:     50%|████▉     | 60/121 [00:00<00:00, 2164.95 it/sec, obj=-1]
INFO - 08:35:54:     50%|█████     | 61/121 [00:00<00:00, 2168.17 it/sec, obj=0]
INFO - 08:35:54:     51%|█████     | 62/121 [00:00<00:00, 2171.13 it/sec, obj=1]
INFO - 08:35:54:     52%|█████▏    | 63/121 [00:00<00:00, 2171.79 it/sec, obj=2]
INFO - 08:35:54:     53%|█████▎    | 64/121 [00:00<00:00, 2174.46 it/sec, obj=3]
INFO - 08:35:54:     54%|█████▎    | 65/121 [00:00<00:00, 2177.22 it/sec, obj=4]
INFO - 08:35:54:     55%|█████▍    | 66/121 [00:00<00:00, 2178.77 it/sec, obj=5]
INFO - 08:35:54:     55%|█████▌    | 67/121 [00:00<00:00, 2181.02 it/sec, obj=-4]
INFO - 08:35:54:     56%|█████▌    | 68/121 [00:00<00:00, 2183.63 it/sec, obj=-3]
INFO - 08:35:54:     57%|█████▋    | 69/121 [00:00<00:00, 2186.08 it/sec, obj=-2]
INFO - 08:35:54:     58%|█████▊    | 70/121 [00:00<00:00, 2188.57 it/sec, obj=-1]
INFO - 08:35:54:     59%|█████▊    | 71/121 [00:00<00:00, 2191.11 it/sec, obj=0]
INFO - 08:35:54:     60%|█████▉    | 72/121 [00:00<00:00, 2191.92 it/sec, obj=1]
INFO - 08:35:54:     60%|██████    | 73/121 [00:00<00:00, 2193.99 it/sec, obj=2]
INFO - 08:35:54:     61%|██████    | 74/121 [00:00<00:00, 2196.48 it/sec, obj=3]
INFO - 08:35:54:     62%|██████▏   | 75/121 [00:00<00:00, 2197.97 it/sec, obj=4]
INFO - 08:35:54:     63%|██████▎   | 76/121 [00:00<00:00, 2199.64 it/sec, obj=5]
INFO - 08:35:54:     64%|██████▎   | 77/121 [00:00<00:00, 2201.69 it/sec, obj=6]
INFO - 08:35:54:     64%|██████▍   | 78/121 [00:00<00:00, 2203.45 it/sec, obj=-3]
INFO - 08:35:54:     65%|██████▌   | 79/121 [00:00<00:00, 2205.40 it/sec, obj=-2]
INFO - 08:35:54:     66%|██████▌   | 80/121 [00:00<00:00, 2207.27 it/sec, obj=-1]
INFO - 08:35:54:     67%|██████▋   | 81/121 [00:00<00:00, 2207.83 it/sec, obj=0]
INFO - 08:35:54:     68%|██████▊   | 82/121 [00:00<00:00, 2209.12 it/sec, obj=1]
INFO - 08:35:54:     69%|██████▊   | 83/121 [00:00<00:00, 2210.95 it/sec, obj=2]
INFO - 08:35:54:     69%|██████▉   | 84/121 [00:00<00:00, 2212.78 it/sec, obj=3]
INFO - 08:35:54:     70%|███████   | 85/121 [00:00<00:00, 2213.44 it/sec, obj=4]
INFO - 08:35:54:     71%|███████   | 86/121 [00:00<00:00, 2214.83 it/sec, obj=5]
INFO - 08:35:54:     72%|███████▏  | 87/121 [00:00<00:00, 2216.26 it/sec, obj=6]
INFO - 08:35:54:     73%|███████▎  | 88/121 [00:00<00:00, 2217.82 it/sec, obj=7]
INFO - 08:35:54:     74%|███████▎  | 89/121 [00:00<00:00, 2219.38 it/sec, obj=-2]
INFO - 08:35:54:     74%|███████▍  | 90/121 [00:00<00:00, 2220.81 it/sec, obj=-1]
INFO - 08:35:54:     75%|███████▌  | 91/121 [00:00<00:00, 2219.78 it/sec, obj=0]
INFO - 08:35:54:     76%|███████▌  | 92/121 [00:00<00:00, 2221.02 it/sec, obj=1]
INFO - 08:35:54:     77%|███████▋  | 93/121 [00:00<00:00, 2222.34 it/sec, obj=2]
INFO - 08:35:54:     78%|███████▊  | 94/121 [00:00<00:00, 2222.76 it/sec, obj=3]
INFO - 08:35:54:     79%|███████▊  | 95/121 [00:00<00:00, 2223.94 it/sec, obj=4]
INFO - 08:35:54:     79%|███████▉  | 96/121 [00:00<00:00, 2225.29 it/sec, obj=5]
INFO - 08:35:54:     80%|████████  | 97/121 [00:00<00:00, 2222.31 it/sec, obj=6]
INFO - 08:35:54:     81%|████████  | 98/121 [00:00<00:00, 2214.06 it/sec, obj=7]
INFO - 08:35:54:     82%|████████▏ | 99/121 [00:00<00:00, 2212.61 it/sec, obj=8]
INFO - 08:35:54:     83%|████████▎ | 100/121 [00:00<00:00, 2213.40 it/sec, obj=-1]
INFO - 08:35:54:     83%|████████▎ | 101/121 [00:00<00:00, 2209.15 it/sec, obj=0]
INFO - 08:35:54:     84%|████████▍ | 102/121 [00:00<00:00, 2209.47 it/sec, obj=1]
INFO - 08:35:54:     85%|████████▌ | 103/121 [00:00<00:00, 2210.50 it/sec, obj=2]
INFO - 08:35:54:     86%|████████▌ | 104/121 [00:00<00:00, 2211.70 it/sec, obj=3]
INFO - 08:35:54:     87%|████████▋ | 105/121 [00:00<00:00, 2212.82 it/sec, obj=4]
INFO - 08:35:54:     88%|████████▊ | 106/121 [00:00<00:00, 2213.53 it/sec, obj=5]
INFO - 08:35:54:     88%|████████▊ | 107/121 [00:00<00:00, 2214.71 it/sec, obj=6]
INFO - 08:35:54:     89%|████████▉ | 108/121 [00:00<00:00, 2214.77 it/sec, obj=7]
INFO - 08:35:54:     90%|█████████ | 109/121 [00:00<00:00, 2215.66 it/sec, obj=8]
INFO - 08:35:54:     91%|█████████ | 110/121 [00:00<00:00, 2216.85 it/sec, obj=9]
INFO - 08:35:54:     92%|█████████▏| 111/121 [00:00<00:00, 2218.13 it/sec, obj=0]
INFO - 08:35:54:     93%|█████████▎| 112/121 [00:00<00:00, 2217.98 it/sec, obj=1]
INFO - 08:35:54:     93%|█████████▎| 113/121 [00:00<00:00, 2209.65 it/sec, obj=2]
INFO - 08:35:54:     94%|█████████▍| 114/121 [00:00<00:00, 2209.83 it/sec, obj=3]
INFO - 08:35:54:     95%|█████████▌| 115/121 [00:00<00:00, 2210.25 it/sec, obj=4]
INFO - 08:35:54:     96%|█████████▌| 116/121 [00:00<00:00, 2207.80 it/sec, obj=5]
INFO - 08:35:54:     97%|█████████▋| 117/121 [00:00<00:00, 2206.91 it/sec, obj=6]
INFO - 08:35:54:     98%|█████████▊| 118/121 [00:00<00:00, 2207.88 it/sec, obj=7]
INFO - 08:35:54:     98%|█████████▊| 119/121 [00:00<00:00, 2208.96 it/sec, obj=8]
INFO - 08:35:54:     99%|█████████▉| 120/121 [00:00<00:00, 2208.52 it/sec, obj=9]
INFO - 08:35:54:    100%|██████████| 121/121 [00:00<00:00, 2209.48 it/sec, obj=10]
INFO - 08:35:54: Optimization result:
INFO - 08:35:54:    Optimizer info:
INFO - 08:35:54:       Status: None
INFO - 08:35:54:       Message: None
INFO - 08:35:54:       Number of calls to the objective function by the optimizer: 121
INFO - 08:35:54:    Solution:
INFO - 08:35:54:       Objective: -10.0
INFO - 08:35:54:       Design space:
INFO - 08:35:54:          +------+-------------+-------+-------------+---------+
INFO - 08:35:54:          | Name | Lower bound | Value | Upper bound | Type    |
INFO - 08:35:54:          +------+-------------+-------+-------------+---------+
INFO - 08:35:54:          | x1   |      -5     |   -5  |      5      | integer |
INFO - 08:35:54:          | x2   |      -5     |   -5  |      5      | integer |
INFO - 08:35:54:          +------+-------------+-------+-------------+---------+
INFO - 08:35:54: *** End DOEScenario execution (time: 0:00:00.059122) ***

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', '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.067 seconds)

Gallery generated by Sphinx-Gallery