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:

\[\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 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 - 13:28:00:
    INFO - 13:28:00: *** Start DOEScenario execution ***
    INFO - 13:28:00: DOEScenario
    INFO - 13:28:00:    Disciplines: AnalyticDiscipline
    INFO - 13:28:00:    MDO formulation: DisciplinaryOpt
    INFO - 13:28:00: Optimization problem:
    INFO - 13:28:00:    minimize y(x1, x2)
    INFO - 13:28:00:    with respect to x1, x2
    INFO - 13:28:00:    over the design space:
    INFO - 13:28:00:    +------+-------------+-------+-------------+---------+
    INFO - 13:28:00:    | name | lower_bound | value | upper_bound | type    |
    INFO - 13:28:00:    +------+-------------+-------+-------------+---------+
    INFO - 13:28:00:    | x1   |      -5     |  None |      5      | integer |
    INFO - 13:28:00:    | x2   |      -5     |  None |      5      | integer |
    INFO - 13:28:00:    +------+-------------+-------+-------------+---------+
    INFO - 13:28:00: Solving optimization problem with algorithm fullfact:
    INFO - 13:28:00: ...   0%|          | 0/121 [00:00<?, ?it]
    INFO - 13:28:00: ...   1%|          | 1/121 [00:00<00:00, 388.18 it/sec, obj=-10]
    INFO - 13:28:00: ...   2%|▏         | 2/121 [00:00<00:00, 621.98 it/sec, obj=-9]
    INFO - 13:28:00: ...   2%|▏         | 3/121 [00:00<00:00, 777.44 it/sec, obj=-8]
    INFO - 13:28:00: ...   3%|▎         | 4/121 [00:00<00:00, 892.74 it/sec, obj=-7]
    INFO - 13:28:00: ...   4%|▍         | 5/121 [00:00<00:00, 982.00 it/sec, obj=-6]
    INFO - 13:28:00: ...   5%|▍         | 6/121 [00:00<00:00, 1052.30 it/sec, obj=-5]
    INFO - 13:28:00: ...   6%|▌         | 7/121 [00:00<00:00, 1100.08 it/sec, obj=-4]
    INFO - 13:28:00: ...   7%|▋         | 8/121 [00:00<00:00, 1146.81 it/sec, obj=-3]
    INFO - 13:28:00: ...   7%|▋         | 9/121 [00:00<00:00, 1183.09 it/sec, obj=-2]
    INFO - 13:28:00: ...   8%|▊         | 10/121 [00:00<00:00, 1216.55 it/sec, obj=-1]
    INFO - 13:28:00: ...   9%|▉         | 11/121 [00:00<00:00, 1246.28 it/sec, obj=0]
    INFO - 13:28:00: ...  10%|▉         | 12/121 [00:00<00:00, 1272.03 it/sec, obj=-9]
    INFO - 13:28:00: ...  11%|█         | 13/121 [00:00<00:00, 1290.77 it/sec, obj=-8]
    INFO - 13:28:00: ...  12%|█▏        | 14/121 [00:00<00:00, 1310.78 it/sec, obj=-7]
    INFO - 13:28:00: ...  12%|█▏        | 15/121 [00:00<00:00, 1328.80 it/sec, obj=-6]
    INFO - 13:28:00: ...  13%|█▎        | 16/121 [00:00<00:00, 1343.52 it/sec, obj=-5]
    INFO - 13:28:00: ...  14%|█▍        | 17/121 [00:00<00:00, 1358.28 it/sec, obj=-4]
    INFO - 13:28:00: ...  15%|█▍        | 18/121 [00:00<00:00, 1371.06 it/sec, obj=-3]
    INFO - 13:28:00: ...  16%|█▌        | 19/121 [00:00<00:00, 1383.49 it/sec, obj=-2]
    INFO - 13:28:00: ...  17%|█▋        | 20/121 [00:00<00:00, 1391.31 it/sec, obj=-1]
    INFO - 13:28:00: ...  17%|█▋        | 21/121 [00:00<00:00, 1402.02 it/sec, obj=0]
    INFO - 13:28:00: ...  18%|█▊        | 22/121 [00:00<00:00, 1410.58 it/sec, obj=1]
    INFO - 13:28:00: ...  19%|█▉        | 23/121 [00:00<00:00, 1419.00 it/sec, obj=-8]
    INFO - 13:28:00: ...  20%|█▉        | 24/121 [00:00<00:00, 1427.40 it/sec, obj=-7]
    INFO - 13:28:00: ...  21%|██        | 25/121 [00:00<00:00, 1435.23 it/sec, obj=-6]
    INFO - 13:28:00: ...  21%|██▏       | 26/121 [00:00<00:00, 1440.47 it/sec, obj=-5]
    INFO - 13:28:00: ...  22%|██▏       | 27/121 [00:00<00:00, 1447.03 it/sec, obj=-4]
    INFO - 13:28:00: ...  23%|██▎       | 28/121 [00:00<00:00, 1453.49 it/sec, obj=-3]
    INFO - 13:28:00: ...  24%|██▍       | 29/121 [00:00<00:00, 1458.17 it/sec, obj=-2]
    INFO - 13:28:00: ...  25%|██▍       | 30/121 [00:00<00:00, 1463.79 it/sec, obj=-1]
    INFO - 13:28:00: ...  26%|██▌       | 31/121 [00:00<00:00, 1469.21 it/sec, obj=0]
    INFO - 13:28:00: ...  26%|██▋       | 32/121 [00:00<00:00, 1474.21 it/sec, obj=1]
    INFO - 13:28:00: ...  27%|██▋       | 33/121 [00:00<00:00, 1477.01 it/sec, obj=2]
    INFO - 13:28:00: ...  28%|██▊       | 34/121 [00:00<00:00, 1481.50 it/sec, obj=-7]
    INFO - 13:28:00: ...  29%|██▉       | 35/121 [00:00<00:00, 1484.72 it/sec, obj=-6]
    INFO - 13:28:00: ...  30%|██▉       | 36/121 [00:00<00:00, 1488.46 it/sec, obj=-5]
    INFO - 13:28:00: ...  31%|███       | 37/121 [00:00<00:00, 1492.12 it/sec, obj=-4]
    INFO - 13:28:00: ...  31%|███▏      | 38/121 [00:00<00:00, 1495.69 it/sec, obj=-3]
    INFO - 13:28:00: ...  32%|███▏      | 39/121 [00:00<00:00, 1497.39 it/sec, obj=-2]
    INFO - 13:28:00: ...  33%|███▎      | 40/121 [00:00<00:00, 1500.48 it/sec, obj=-1]
    INFO - 13:28:00: ...  34%|███▍      | 41/121 [00:00<00:00, 1503.94 it/sec, obj=0]
    INFO - 13:28:00: ...  35%|███▍      | 42/121 [00:00<00:00, 1506.06 it/sec, obj=1]
    INFO - 13:28:00: ...  36%|███▌      | 43/121 [00:00<00:00, 1508.96 it/sec, obj=2]
    INFO - 13:28:00: ...  36%|███▋      | 44/121 [00:00<00:00, 1512.07 it/sec, obj=3]
    INFO - 13:28:00: ...  37%|███▋      | 45/121 [00:00<00:00, 1514.97 it/sec, obj=-6]
    INFO - 13:28:00: ...  38%|███▊      | 46/121 [00:00<00:00, 1516.15 it/sec, obj=-5]
    INFO - 13:28:00: ...  39%|███▉      | 47/121 [00:00<00:00, 1516.23 it/sec, obj=-4]
    INFO - 13:28:00: ...  40%|███▉      | 48/121 [00:00<00:00, 1514.79 it/sec, obj=-3]
    INFO - 13:28:00: ...  40%|████      | 49/121 [00:00<00:00, 1516.75 it/sec, obj=-2]
    INFO - 13:28:00: ...  41%|████▏     | 50/121 [00:00<00:00, 1518.92 it/sec, obj=-1]
    INFO - 13:28:00: ...  42%|████▏     | 51/121 [00:00<00:00, 1521.13 it/sec, obj=0]
    INFO - 13:28:00: ...  43%|████▎     | 52/121 [00:00<00:00, 1521.88 it/sec, obj=1]
    INFO - 13:28:00: ...  44%|████▍     | 53/121 [00:00<00:00, 1523.86 it/sec, obj=2]
    INFO - 13:28:00: ...  45%|████▍     | 54/121 [00:00<00:00, 1523.53 it/sec, obj=3]
    INFO - 13:28:00: ...  45%|████▌     | 55/121 [00:00<00:00, 1524.99 it/sec, obj=4]
    INFO - 13:28:00: ...  46%|████▋     | 56/121 [00:00<00:00, 1526.76 it/sec, obj=-5]
    INFO - 13:28:00: ...  47%|████▋     | 57/121 [00:00<00:00, 1526.76 it/sec, obj=-4]
    INFO - 13:28:00: ...  48%|████▊     | 58/121 [00:00<00:00, 1525.97 it/sec, obj=-3]
    INFO - 13:28:00: ...  49%|████▉     | 59/121 [00:00<00:00, 1527.28 it/sec, obj=-2]
    INFO - 13:28:00: ...  50%|████▉     | 60/121 [00:00<00:00, 1528.91 it/sec, obj=-1]
    INFO - 13:28:00: ...  50%|█████     | 61/121 [00:00<00:00, 1529.80 it/sec, obj=0]
    INFO - 13:28:00: ...  51%|█████     | 62/121 [00:00<00:00, 1531.42 it/sec, obj=1]
    INFO - 13:28:00: ...  52%|█████▏    | 63/121 [00:00<00:00, 1533.09 it/sec, obj=2]
    INFO - 13:28:00: ...  53%|█████▎    | 64/121 [00:00<00:00, 1529.42 it/sec, obj=3]
    INFO - 13:28:00: ...  54%|█████▎    | 65/121 [00:00<00:00, 1530.89 it/sec, obj=4]
    INFO - 13:28:00: ...  55%|█████▍    | 66/121 [00:00<00:00, 1532.29 it/sec, obj=5]
    INFO - 13:28:00: ...  55%|█████▌    | 67/121 [00:00<00:00, 1533.24 it/sec, obj=-4]
    INFO - 13:28:00: ...  56%|█████▌    | 68/121 [00:00<00:00, 1534.66 it/sec, obj=-3]
    INFO - 13:28:00: ...  57%|█████▋    | 69/121 [00:00<00:00, 1536.15 it/sec, obj=-2]
    INFO - 13:28:00: ...  58%|█████▊    | 70/121 [00:00<00:00, 1537.64 it/sec, obj=-1]
    INFO - 13:28:00: ...  59%|█████▊    | 71/121 [00:00<00:00, 1538.10 it/sec, obj=0]
    INFO - 13:28:00: ...  60%|█████▉    | 72/121 [00:00<00:00, 1539.34 it/sec, obj=1]
    INFO - 13:28:00: ...  60%|██████    | 73/121 [00:00<00:00, 1539.96 it/sec, obj=2]
    INFO - 13:28:00: ...  61%|██████    | 74/121 [00:00<00:00, 1540.51 it/sec, obj=3]
    INFO - 13:28:00: ...  62%|██████▏   | 75/121 [00:00<00:00, 1541.77 it/sec, obj=4]
    INFO - 13:28:00: ...  63%|██████▎   | 76/121 [00:00<00:00, 1542.93 it/sec, obj=5]
    INFO - 13:28:00: ...  64%|██████▎   | 77/121 [00:00<00:00, 1543.29 it/sec, obj=6]
    INFO - 13:28:00: ...  64%|██████▍   | 78/121 [00:00<00:00, 1544.32 it/sec, obj=-3]
    INFO - 13:28:00: ...  65%|██████▌   | 79/121 [00:00<00:00, 1545.63 it/sec, obj=-2]
    INFO - 13:28:00: ...  66%|██████▌   | 80/121 [00:00<00:00, 1546.34 it/sec, obj=-1]
    INFO - 13:28:00: ...  67%|██████▋   | 81/121 [00:00<00:00, 1547.50 it/sec, obj=0]
    INFO - 13:28:00: ...  68%|██████▊   | 82/121 [00:00<00:00, 1548.74 it/sec, obj=1]
    INFO - 13:28:00: ...  69%|██████▊   | 83/121 [00:00<00:00, 1549.98 it/sec, obj=2]
    INFO - 13:28:00: ...  69%|██████▉   | 84/121 [00:00<00:00, 1550.37 it/sec, obj=3]
    INFO - 13:28:00: ...  70%|███████   | 85/121 [00:00<00:00, 1551.45 it/sec, obj=4]
    INFO - 13:28:00: ...  71%|███████   | 86/121 [00:00<00:00, 1552.61 it/sec, obj=5]
    INFO - 13:28:00: ...  72%|███████▏  | 87/121 [00:00<00:00, 1553.06 it/sec, obj=6]
    INFO - 13:28:00: ...  73%|███████▎  | 88/121 [00:00<00:00, 1554.13 it/sec, obj=7]
    INFO - 13:28:00: ...  74%|███████▎  | 89/121 [00:00<00:00, 1555.20 it/sec, obj=-2]
    INFO - 13:28:00: ...  74%|███████▍  | 90/121 [00:00<00:00, 1555.55 it/sec, obj=-1]
    INFO - 13:28:00: ...  75%|███████▌  | 91/121 [00:00<00:00, 1556.37 it/sec, obj=0]
    INFO - 13:28:00: ...  76%|███████▌  | 92/121 [00:00<00:00, 1557.38 it/sec, obj=1]
    INFO - 13:28:00: ...  77%|███████▋  | 93/121 [00:00<00:00, 1557.89 it/sec, obj=2]
    INFO - 13:28:00: ...  78%|███████▊  | 94/121 [00:00<00:00, 1558.82 it/sec, obj=3]
    INFO - 13:28:00: ...  79%|███████▊  | 95/121 [00:00<00:00, 1559.81 it/sec, obj=4]
    INFO - 13:28:00: ...  79%|███████▉  | 96/121 [00:00<00:00, 1560.67 it/sec, obj=5]
    INFO - 13:28:00: ...  80%|████████  | 97/121 [00:00<00:00, 1559.56 it/sec, obj=6]
    INFO - 13:28:00: ...  81%|████████  | 98/121 [00:00<00:00, 1559.57 it/sec, obj=7]
    INFO - 13:28:00: ...  82%|████████▏ | 99/121 [00:00<00:00, 1560.02 it/sec, obj=8]
    INFO - 13:28:00: ...  83%|████████▎ | 100/121 [00:00<00:00, 1560.64 it/sec, obj=-1]
    INFO - 13:28:00: ...  83%|████████▎ | 101/121 [00:00<00:00, 1561.43 it/sec, obj=0]
    INFO - 13:28:00: ...  84%|████████▍ | 102/121 [00:00<00:00, 1562.20 it/sec, obj=1]
    INFO - 13:28:00: ...  85%|████████▌ | 103/121 [00:00<00:00, 1562.25 it/sec, obj=2]
    INFO - 13:28:00: ...  86%|████████▌ | 104/121 [00:00<00:00, 1562.86 it/sec, obj=3]
    INFO - 13:28:00: ...  87%|████████▋ | 105/121 [00:00<00:00, 1563.59 it/sec, obj=4]
    INFO - 13:28:00: ...  88%|████████▊ | 106/121 [00:00<00:00, 1564.00 it/sec, obj=5]
    INFO - 13:28:00: ...  88%|████████▊ | 107/121 [00:00<00:00, 1564.64 it/sec, obj=6]
    INFO - 13:28:00: ...  89%|████████▉ | 108/121 [00:00<00:00, 1565.35 it/sec, obj=7]
    INFO - 13:28:00: ...  90%|█████████ | 109/121 [00:00<00:00, 1566.07 it/sec, obj=8]
    INFO - 13:28:00: ...  91%|█████████ | 110/121 [00:00<00:00, 1566.17 it/sec, obj=9]
    INFO - 13:28:00: ...  92%|█████████▏| 111/121 [00:00<00:00, 1566.90 it/sec, obj=0]
    INFO - 13:28:00: ...  93%|█████████▎| 112/121 [00:00<00:00, 1567.33 it/sec, obj=1]
    INFO - 13:28:00: ...  93%|█████████▎| 113/121 [00:00<00:00, 1567.84 it/sec, obj=2]
    INFO - 13:28:00: ...  94%|█████████▍| 114/121 [00:00<00:00, 1568.65 it/sec, obj=3]
    INFO - 13:28:00: ...  95%|█████████▌| 115/121 [00:00<00:00, 1569.39 it/sec, obj=4]
    INFO - 13:28:00: ...  96%|█████████▌| 116/121 [00:00<00:00, 1569.36 it/sec, obj=5]
    INFO - 13:28:00: ...  97%|█████████▋| 117/121 [00:00<00:00, 1569.97 it/sec, obj=6]
    INFO - 13:28:00: ...  98%|█████████▊| 118/121 [00:00<00:00, 1570.62 it/sec, obj=7]
    INFO - 13:28:00: ...  98%|█████████▊| 119/121 [00:00<00:00, 1570.90 it/sec, obj=8]
    INFO - 13:28:00: ...  99%|█████████▉| 120/121 [00:00<00:00, 1571.53 it/sec, obj=9]
    INFO - 13:28:00: ... 100%|██████████| 121/121 [00:00<00:00, 1572.20 it/sec, obj=10]
    INFO - 13:28:00: Optimization result:
    INFO - 13:28:00:    Optimizer info:
    INFO - 13:28:00:       Status: None
    INFO - 13:28:00:       Message: None
    INFO - 13:28:00:       Number of calls to the objective function by the optimizer: 121
    INFO - 13:28:00:    Solution:
    INFO - 13:28:00:       Objective: -10.0
    INFO - 13:28:00:       Design space:
    INFO - 13:28:00:       +------+-------------+-------+-------------+---------+
    INFO - 13:28:00:       | name | lower_bound | value | upper_bound | type    |
    INFO - 13:28:00:       +------+-------------+-------+-------------+---------+
    INFO - 13:28:00:       | x1   |      -5     |   -5  |      5      | integer |
    INFO - 13:28:00:       | x2   |      -5     |   -5  |      5      | integer |
    INFO - 13:28:00:       +------+-------------+-------+-------------+---------+
    INFO - 13:28:00: *** End DOEScenario execution (time: 0:00:00.086613) ***

{'eval_jac': False, 'n_samples': 121, 'algo': 'fullfact'}

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

Gallery generated by Sphinx-Gallery