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 - 15:59:04:
    INFO - 15:59:04: *** Start DOEScenario execution ***
    INFO - 15:59:04: DOEScenario
    INFO - 15:59:04:    Disciplines: AnalyticDiscipline
    INFO - 15:59:04:    MDO formulation: DisciplinaryOpt
    INFO - 15:59:04: Optimization problem:
    INFO - 15:59:04:    minimize y(x1, x2)
    INFO - 15:59:04:    with respect to x1, x2
    INFO - 15:59:04:    over the design space:
    INFO - 15:59:04:    +------+-------------+-------+-------------+---------+
    INFO - 15:59:04:    | name | lower_bound | value | upper_bound | type    |
    INFO - 15:59:04:    +------+-------------+-------+-------------+---------+
    INFO - 15:59:04:    | x1   |      -5     |  None |      5      | integer |
    INFO - 15:59:04:    | x2   |      -5     |  None |      5      | integer |
    INFO - 15:59:04:    +------+-------------+-------+-------------+---------+
    INFO - 15:59:04: Solving optimization problem with algorithm fullfact:
    INFO - 15:59:04: ...   0%|          | 0/121 [00:00<?, ?it]
    INFO - 15:59:04: ...   1%|          | 1/121 [00:00<00:00, 367.89 it/sec, obj=-10]
    INFO - 15:59:04: ...   2%|▏         | 2/121 [00:00<00:00, 598.59 it/sec, obj=-9]
    INFO - 15:59:04: ...   2%|▏         | 3/121 [00:00<00:00, 755.87 it/sec, obj=-8]
    INFO - 15:59:04: ...   3%|▎         | 4/121 [00:00<00:00, 876.92 it/sec, obj=-7]
    INFO - 15:59:04: ...   4%|▍         | 5/121 [00:00<00:00, 971.49 it/sec, obj=-6]
    INFO - 15:59:04: ...   5%|▍         | 6/121 [00:00<00:00, 1047.75 it/sec, obj=-5]
    INFO - 15:59:04: ...   6%|▌         | 7/121 [00:00<00:00, 1106.30 it/sec, obj=-4]
    INFO - 15:59:04: ...   7%|▋         | 8/121 [00:00<00:00, 1158.05 it/sec, obj=-3]
    INFO - 15:59:04: ...   7%|▋         | 9/121 [00:00<00:00, 1198.64 it/sec, obj=-2]
    INFO - 15:59:04: ...   8%|▊         | 10/121 [00:00<00:00, 1230.18 it/sec, obj=-1]
    INFO - 15:59:04: ...   9%|▉         | 11/121 [00:00<00:00, 1261.82 it/sec, obj=0]
    INFO - 15:59:04: ...  10%|▉         | 12/121 [00:00<00:00, 1290.56 it/sec, obj=-9]
    INFO - 15:59:04: ...  11%|█         | 13/121 [00:00<00:00, 1314.70 it/sec, obj=-8]
    INFO - 15:59:04: ...  12%|█▏        | 14/121 [00:00<00:00, 1337.29 it/sec, obj=-7]
    INFO - 15:59:04: ...  12%|█▏        | 15/121 [00:00<00:00, 1357.58 it/sec, obj=-6]
    INFO - 15:59:04: ...  13%|█▎        | 16/121 [00:00<00:00, 1369.40 it/sec, obj=-5]
    INFO - 15:59:04: ...  14%|█▍        | 17/121 [00:00<00:00, 1382.41 it/sec, obj=-4]
    INFO - 15:59:04: ...  15%|█▍        | 18/121 [00:00<00:00, 1397.69 it/sec, obj=-3]
    INFO - 15:59:04: ...  16%|█▌        | 19/121 [00:00<00:00, 1411.80 it/sec, obj=-2]
    INFO - 15:59:04: ...  17%|█▋        | 20/121 [00:00<00:00, 1423.00 it/sec, obj=-1]
    INFO - 15:59:04: ...  17%|█▋        | 21/121 [00:00<00:00, 1434.95 it/sec, obj=0]
    INFO - 15:59:04: ...  18%|█▊        | 22/121 [00:00<00:00, 1445.99 it/sec, obj=1]
    INFO - 15:59:04: ...  19%|█▉        | 23/121 [00:00<00:00, 1456.84 it/sec, obj=-8]
    INFO - 15:59:04: ...  20%|█▉        | 24/121 [00:00<00:00, 1463.19 it/sec, obj=-7]
    INFO - 15:59:04: ...  21%|██        | 25/121 [00:00<00:00, 1471.93 it/sec, obj=-6]
    INFO - 15:59:04: ...  21%|██▏       | 26/121 [00:00<00:00, 1480.58 it/sec, obj=-5]
    INFO - 15:59:04: ...  22%|██▏       | 27/121 [00:00<00:00, 1487.15 it/sec, obj=-4]
    INFO - 15:59:04: ...  23%|██▎       | 28/121 [00:00<00:00, 1494.99 it/sec, obj=-3]
    INFO - 15:59:04: ...  24%|██▍       | 29/121 [00:00<00:00, 1502.31 it/sec, obj=-2]
    INFO - 15:59:04: ...  25%|██▍       | 30/121 [00:00<00:00, 1507.21 it/sec, obj=-1]
    INFO - 15:59:04: ...  26%|██▌       | 31/121 [00:00<00:00, 1512.87 it/sec, obj=0]
    INFO - 15:59:04: ...  26%|██▋       | 32/121 [00:00<00:00, 1518.99 it/sec, obj=1]
    INFO - 15:59:04: ...  27%|██▋       | 33/121 [00:00<00:00, 1525.00 it/sec, obj=2]
    INFO - 15:59:04: ...  28%|██▊       | 34/121 [00:00<00:00, 1529.18 it/sec, obj=-7]
    INFO - 15:59:04: ...  29%|██▉       | 35/121 [00:00<00:00, 1533.98 it/sec, obj=-6]
    INFO - 15:59:04: ...  30%|██▉       | 36/121 [00:00<00:00, 1538.55 it/sec, obj=-5]
    INFO - 15:59:04: ...  31%|███       | 37/121 [00:00<00:00, 1541.49 it/sec, obj=-4]
    INFO - 15:59:04: ...  31%|███▏      | 38/121 [00:00<00:00, 1545.61 it/sec, obj=-3]
    INFO - 15:59:04: ...  32%|███▏      | 39/121 [00:00<00:00, 1549.81 it/sec, obj=-2]
    INFO - 15:59:04: ...  33%|███▎      | 40/121 [00:00<00:00, 1552.93 it/sec, obj=-1]
    INFO - 15:59:04: ...  34%|███▍      | 41/121 [00:00<00:00, 1556.37 it/sec, obj=0]
    INFO - 15:59:04: ...  35%|███▍      | 42/121 [00:00<00:00, 1560.09 it/sec, obj=1]
    INFO - 15:59:04: ...  36%|███▌      | 43/121 [00:00<00:00, 1563.72 it/sec, obj=2]
    INFO - 15:59:04: ...  36%|███▋      | 44/121 [00:00<00:00, 1565.90 it/sec, obj=3]
    INFO - 15:59:04: ...  37%|███▋      | 45/121 [00:00<00:00, 1569.05 it/sec, obj=-6]
    INFO - 15:59:04: ...  38%|███▊      | 46/121 [00:00<00:00, 1572.19 it/sec, obj=-5]
    INFO - 15:59:04: ...  39%|███▉      | 47/121 [00:00<00:00, 1574.29 it/sec, obj=-4]
    INFO - 15:59:04: ...  40%|███▉      | 48/121 [00:00<00:00, 1577.18 it/sec, obj=-3]
    INFO - 15:59:04: ...  40%|████      | 49/121 [00:00<00:00, 1580.24 it/sec, obj=-2]
    INFO - 15:59:04: ...  41%|████▏     | 50/121 [00:00<00:00, 1583.08 it/sec, obj=-1]
    INFO - 15:59:04: ...  42%|████▏     | 51/121 [00:00<00:00, 1584.41 it/sec, obj=0]
    INFO - 15:59:04: ...  43%|████▎     | 52/121 [00:00<00:00, 1586.96 it/sec, obj=1]
    INFO - 15:59:04: ...  44%|████▍     | 53/121 [00:00<00:00, 1589.54 it/sec, obj=2]
    INFO - 15:59:04: ...  45%|████▍     | 54/121 [00:00<00:00, 1591.36 it/sec, obj=3]
    INFO - 15:59:04: ...  45%|████▌     | 55/121 [00:00<00:00, 1593.55 it/sec, obj=4]
    INFO - 15:59:04: ...  46%|████▋     | 56/121 [00:00<00:00, 1595.81 it/sec, obj=-5]
    INFO - 15:59:04: ...  47%|████▋     | 57/121 [00:00<00:00, 1598.35 it/sec, obj=-4]
    INFO - 15:59:04: ...  48%|████▊     | 58/121 [00:00<00:00, 1599.05 it/sec, obj=-3]
    INFO - 15:59:04: ...  49%|████▉     | 59/121 [00:00<00:00, 1600.99 it/sec, obj=-2]
    INFO - 15:59:04: ...  50%|████▉     | 60/121 [00:00<00:00, 1603.06 it/sec, obj=-1]
    INFO - 15:59:04: ...  50%|█████     | 61/121 [00:00<00:00, 1604.17 it/sec, obj=0]
    INFO - 15:59:04: ...  51%|█████     | 62/121 [00:00<00:00, 1605.96 it/sec, obj=1]
    INFO - 15:59:04: ...  52%|█████▏    | 63/121 [00:00<00:00, 1608.01 it/sec, obj=2]
    INFO - 15:59:04: ...  53%|█████▎    | 64/121 [00:00<00:00, 1609.98 it/sec, obj=3]
    INFO - 15:59:04: ...  54%|█████▎    | 65/121 [00:00<00:00, 1610.75 it/sec, obj=4]
    INFO - 15:59:04: ...  55%|█████▍    | 66/121 [00:00<00:00, 1612.39 it/sec, obj=5]
    INFO - 15:59:04: ...  55%|█████▌    | 67/121 [00:00<00:00, 1613.91 it/sec, obj=-4]
    INFO - 15:59:04: ...  56%|█████▌    | 68/121 [00:00<00:00, 1614.95 it/sec, obj=-3]
    INFO - 15:59:04: ...  57%|█████▋    | 69/121 [00:00<00:00, 1616.51 it/sec, obj=-2]
    INFO - 15:59:04: ...  58%|█████▊    | 70/121 [00:00<00:00, 1618.01 it/sec, obj=-1]
    INFO - 15:59:04: ...  59%|█████▊    | 71/121 [00:00<00:00, 1613.73 it/sec, obj=0]
    INFO - 15:59:04: ...  60%|█████▉    | 72/121 [00:00<00:00, 1614.95 it/sec, obj=1]
    INFO - 15:59:04: ...  60%|██████    | 73/121 [00:00<00:00, 1616.42 it/sec, obj=2]
    INFO - 15:59:04: ...  61%|██████    | 74/121 [00:00<00:00, 1617.41 it/sec, obj=3]
    INFO - 15:59:04: ...  62%|██████▏   | 75/121 [00:00<00:00, 1618.48 it/sec, obj=4]
    INFO - 15:59:04: ...  63%|██████▎   | 76/121 [00:00<00:00, 1619.74 it/sec, obj=5]
    INFO - 15:59:04: ...  64%|██████▎   | 77/121 [00:00<00:00, 1620.98 it/sec, obj=6]
    INFO - 15:59:04: ...  64%|██████▍   | 78/121 [00:00<00:00, 1621.25 it/sec, obj=-3]
    INFO - 15:59:04: ...  65%|██████▌   | 79/121 [00:00<00:00, 1622.33 it/sec, obj=-2]
    INFO - 15:59:04: ...  66%|██████▌   | 80/121 [00:00<00:00, 1623.65 it/sec, obj=-1]
    INFO - 15:59:04: ...  67%|██████▋   | 81/121 [00:00<00:00, 1624.21 it/sec, obj=0]
    INFO - 15:59:04: ...  68%|██████▊   | 82/121 [00:00<00:00, 1625.29 it/sec, obj=1]
    INFO - 15:59:04: ...  69%|██████▊   | 83/121 [00:00<00:00, 1626.34 it/sec, obj=2]
    INFO - 15:59:04: ...  69%|██████▉   | 84/121 [00:00<00:00, 1627.53 it/sec, obj=3]
    INFO - 15:59:04: ...  70%|███████   | 85/121 [00:00<00:00, 1627.89 it/sec, obj=4]
    INFO - 15:59:04: ...  71%|███████   | 86/121 [00:00<00:00, 1628.83 it/sec, obj=5]
    INFO - 15:59:04: ...  72%|███████▏  | 87/121 [00:00<00:00, 1629.99 it/sec, obj=6]
    INFO - 15:59:04: ...  73%|███████▎  | 88/121 [00:00<00:00, 1630.51 it/sec, obj=7]
    INFO - 15:59:04: ...  74%|███████▎  | 89/121 [00:00<00:00, 1631.38 it/sec, obj=-2]
    INFO - 15:59:04: ...  74%|███████▍  | 90/121 [00:00<00:00, 1632.44 it/sec, obj=-1]
    INFO - 15:59:04: ...  75%|███████▌  | 91/121 [00:00<00:00, 1633.51 it/sec, obj=0]
    INFO - 15:59:04: ...  76%|███████▌  | 92/121 [00:00<00:00, 1633.67 it/sec, obj=1]
    INFO - 15:59:04: ...  77%|███████▋  | 93/121 [00:00<00:00, 1634.48 it/sec, obj=2]
    INFO - 15:59:04: ...  78%|███████▊  | 94/121 [00:00<00:00, 1635.29 it/sec, obj=3]
    INFO - 15:59:04: ...  79%|███████▊  | 95/121 [00:00<00:00, 1635.72 it/sec, obj=4]
    INFO - 15:59:04: ...  79%|███████▉  | 96/121 [00:00<00:00, 1636.54 it/sec, obj=5]
    INFO - 15:59:04: ...  80%|████████  | 97/121 [00:00<00:00, 1637.36 it/sec, obj=6]
    INFO - 15:59:04: ...  81%|████████  | 98/121 [00:00<00:00, 1638.25 it/sec, obj=7]
    INFO - 15:59:04: ...  82%|████████▏ | 99/121 [00:00<00:00, 1638.21 it/sec, obj=8]
    INFO - 15:59:04: ...  83%|████████▎ | 100/121 [00:00<00:00, 1638.94 it/sec, obj=-1]
    INFO - 15:59:04: ...  83%|████████▎ | 101/121 [00:00<00:00, 1639.75 it/sec, obj=0]
    INFO - 15:59:04: ...  84%|████████▍ | 102/121 [00:00<00:00, 1640.11 it/sec, obj=1]
    INFO - 15:59:04: ...  85%|████████▌ | 103/121 [00:00<00:00, 1640.83 it/sec, obj=2]
    INFO - 15:59:04: ...  86%|████████▌ | 104/121 [00:00<00:00, 1641.53 it/sec, obj=3]
    INFO - 15:59:04: ...  87%|████████▋ | 105/121 [00:00<00:00, 1641.57 it/sec, obj=4]
    INFO - 15:59:04: ...  88%|████████▊ | 106/121 [00:00<00:00, 1642.24 it/sec, obj=5]
    INFO - 15:59:04: ...  88%|████████▊ | 107/121 [00:00<00:00, 1642.90 it/sec, obj=6]
    INFO - 15:59:04: ...  89%|████████▉ | 108/121 [00:00<00:00, 1643.61 it/sec, obj=7]
    INFO - 15:59:04: ...  90%|█████████ | 109/121 [00:00<00:00, 1642.60 it/sec, obj=8]
    INFO - 15:59:04: ...  91%|█████████ | 110/121 [00:00<00:00, 1643.09 it/sec, obj=9]
    INFO - 15:59:04: ...  92%|█████████▏| 111/121 [00:00<00:00, 1643.76 it/sec, obj=0]
    INFO - 15:59:04: ...  93%|█████████▎| 112/121 [00:00<00:00, 1643.67 it/sec, obj=1]
    INFO - 15:59:04: ...  93%|█████████▎| 113/121 [00:00<00:00, 1644.07 it/sec, obj=2]
    INFO - 15:59:04: ...  94%|█████████▍| 114/121 [00:00<00:00, 1644.79 it/sec, obj=3]
    INFO - 15:59:04: ...  95%|█████████▌| 115/121 [00:00<00:00, 1645.09 it/sec, obj=4]
    INFO - 15:59:04: ...  96%|█████████▌| 116/121 [00:00<00:00, 1645.65 it/sec, obj=5]
    INFO - 15:59:04: ...  97%|█████████▋| 117/121 [00:00<00:00, 1646.29 it/sec, obj=6]
    INFO - 15:59:04: ...  98%|█████████▊| 118/121 [00:00<00:00, 1646.95 it/sec, obj=7]
    INFO - 15:59:04: ...  98%|█████████▊| 119/121 [00:00<00:00, 1646.70 it/sec, obj=8]
    INFO - 15:59:04: ...  99%|█████████▉| 120/121 [00:00<00:00, 1645.00 it/sec, obj=9]
    INFO - 15:59:04: ... 100%|██████████| 121/121 [00:00<00:00, 1644.82 it/sec, obj=10]
    INFO - 15:59:04: Optimization result:
    INFO - 15:59:04:    Optimizer info:
    INFO - 15:59:04:       Status: None
    INFO - 15:59:04:       Message: None
    INFO - 15:59:04:       Number of calls to the objective function by the optimizer: 121
    INFO - 15:59:04:    Solution:
    INFO - 15:59:04:       Objective: -10.0
    INFO - 15:59:04:       Design space:
    INFO - 15:59:04:       +------+-------------+-------+-------------+---------+
    INFO - 15:59:04:       | name | lower_bound | value | upper_bound | type    |
    INFO - 15:59:04:       +------+-------------+-------+-------------+---------+
    INFO - 15:59:04:       | x1   |      -5     |   -5  |      5      | integer |
    INFO - 15:59:04:       | x2   |      -5     |   -5  |      5      | integer |
    INFO - 15:59:04:       +------+-------------+-------+-------------+---------+
    INFO - 15:59:04: *** End DOEScenario execution (time: 0:00:00.082976) ***

{'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.100 seconds)

Gallery generated by Sphinx-Gallery