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 - 17:23:05:
    INFO - 17:23:05: *** Start DOEScenario execution ***
    INFO - 17:23:05: DOEScenario
    INFO - 17:23:05:    Disciplines: AnalyticDiscipline
    INFO - 17:23:05:    MDO formulation: DisciplinaryOpt
    INFO - 17:23:05: Optimization problem:
    INFO - 17:23:05:    minimize y(x1, x2)
    INFO - 17:23:05:    with respect to x1, x2
    INFO - 17:23:05:    over the design space:
    INFO - 17:23:05:    +------+-------------+-------+-------------+---------+
    INFO - 17:23:05:    | name | lower_bound | value | upper_bound | type    |
    INFO - 17:23:05:    +------+-------------+-------+-------------+---------+
    INFO - 17:23:05:    | x1   |      -5     |  None |      5      | integer |
    INFO - 17:23:05:    | x2   |      -5     |  None |      5      | integer |
    INFO - 17:23:05:    +------+-------------+-------+-------------+---------+
    INFO - 17:23:05: Solving optimization problem with algorithm fullfact:
    INFO - 17:23:05: ...   0%|          | 0/121 [00:00<?, ?it]
    INFO - 17:23:05: ...   1%|          | 1/121 [00:00<00:00, 219.98 it/sec, obj=-10]
    INFO - 17:23:05: ...   2%|▏         | 2/121 [00:00<00:00, 359.67 it/sec, obj=-9]
    INFO - 17:23:05: ...   2%|▏         | 3/121 [00:00<00:00, 453.57 it/sec, obj=-8]
    INFO - 17:23:05: ...   3%|▎         | 4/121 [00:00<00:00, 526.56 it/sec, obj=-7]
    INFO - 17:23:05: ...   4%|▍         | 5/121 [00:00<00:00, 584.00 it/sec, obj=-6]
    INFO - 17:23:05: ...   5%|▍         | 6/121 [00:00<00:00, 630.06 it/sec, obj=-5]
    INFO - 17:23:05: ...   6%|▌         | 7/121 [00:00<00:00, 661.65 it/sec, obj=-4]
    INFO - 17:23:05: ...   7%|▋         | 8/121 [00:00<00:00, 691.87 it/sec, obj=-3]
    INFO - 17:23:05: ...   7%|▋         | 9/121 [00:00<00:00, 718.26 it/sec, obj=-2]
    INFO - 17:23:05: ...   8%|▊         | 10/121 [00:00<00:00, 741.29 it/sec, obj=-1]
    INFO - 17:23:05: ...   9%|▉         | 11/121 [00:00<00:00, 756.92 it/sec, obj=0]
    INFO - 17:23:05: ...  10%|▉         | 12/121 [00:00<00:00, 773.77 it/sec, obj=-9]
    INFO - 17:23:05: ...  11%|█         | 13/121 [00:00<00:00, 789.58 it/sec, obj=-8]
    INFO - 17:23:05: ...  12%|█▏        | 14/121 [00:00<00:00, 803.51 it/sec, obj=-7]
    INFO - 17:23:05: ...  12%|█▏        | 15/121 [00:00<00:00, 812.63 it/sec, obj=-6]
    INFO - 17:23:05: ...  13%|█▎        | 16/121 [00:00<00:00, 823.06 it/sec, obj=-5]
    INFO - 17:23:05: ...  14%|█▍        | 17/121 [00:00<00:00, 833.38 it/sec, obj=-4]
    INFO - 17:23:05: ...  15%|█▍        | 18/121 [00:00<00:00, 842.60 it/sec, obj=-3]
    INFO - 17:23:05: ...  16%|█▌        | 19/121 [00:00<00:00, 845.99 it/sec, obj=-2]
    INFO - 17:23:05: ...  17%|█▋        | 20/121 [00:00<00:00, 853.06 it/sec, obj=-1]
    INFO - 17:23:05: ...  17%|█▋        | 21/121 [00:00<00:00, 860.57 it/sec, obj=0]
    INFO - 17:23:05: ...  18%|█▊        | 22/121 [00:00<00:00, 867.48 it/sec, obj=1]
    INFO - 17:23:05: ...  19%|█▉        | 23/121 [00:00<00:00, 871.43 it/sec, obj=-8]
    INFO - 17:23:05: ...  20%|█▉        | 24/121 [00:00<00:00, 876.71 it/sec, obj=-7]
    INFO - 17:23:05: ...  21%|██        | 25/121 [00:00<00:00, 882.31 it/sec, obj=-6]
    INFO - 17:23:05: ...  21%|██▏       | 26/121 [00:00<00:00, 887.65 it/sec, obj=-5]
    INFO - 17:23:05: ...  22%|██▏       | 27/121 [00:00<00:00, 890.36 it/sec, obj=-4]
    INFO - 17:23:05: ...  23%|██▎       | 28/121 [00:00<00:00, 894.53 it/sec, obj=-3]
    INFO - 17:23:05: ...  24%|██▍       | 29/121 [00:00<00:00, 899.03 it/sec, obj=-2]
    INFO - 17:23:05: ...  25%|██▍       | 30/121 [00:00<00:00, 903.16 it/sec, obj=-1]
    INFO - 17:23:05: ...  26%|██▌       | 31/121 [00:00<00:00, 905.06 it/sec, obj=0]
    INFO - 17:23:05: ...  26%|██▋       | 32/121 [00:00<00:00, 908.13 it/sec, obj=1]
    INFO - 17:23:05: ...  27%|██▋       | 33/121 [00:00<00:00, 911.81 it/sec, obj=2]
    INFO - 17:23:05: ...  28%|██▊       | 34/121 [00:00<00:00, 915.16 it/sec, obj=-7]
    INFO - 17:23:05: ...  29%|██▉       | 35/121 [00:00<00:00, 916.19 it/sec, obj=-6]
    INFO - 17:23:05: ...  30%|██▉       | 36/121 [00:00<00:00, 918.62 it/sec, obj=-5]
    INFO - 17:23:05: ...  31%|███       | 37/121 [00:00<00:00, 921.60 it/sec, obj=-4]
    INFO - 17:23:05: ...  31%|███▏      | 38/121 [00:00<00:00, 924.41 it/sec, obj=-3]
    INFO - 17:23:05: ...  32%|███▏      | 39/121 [00:00<00:00, 925.52 it/sec, obj=-2]
    INFO - 17:23:05: ...  33%|███▎      | 40/121 [00:00<00:00, 927.38 it/sec, obj=-1]
    INFO - 17:23:05: ...  34%|███▍      | 41/121 [00:00<00:00, 929.83 it/sec, obj=0]
    INFO - 17:23:05: ...  35%|███▍      | 42/121 [00:00<00:00, 932.18 it/sec, obj=1]
    INFO - 17:23:05: ...  36%|███▌      | 43/121 [00:00<00:00, 932.78 it/sec, obj=2]
    INFO - 17:23:05: ...  36%|███▋      | 44/121 [00:00<00:00, 932.91 it/sec, obj=3]
    INFO - 17:23:05: ...  37%|███▋      | 45/121 [00:00<00:00, 933.47 it/sec, obj=-6]
    INFO - 17:23:05: ...  38%|███▊      | 46/121 [00:00<00:00, 935.84 it/sec, obj=-5]
    INFO - 17:23:05: ...  39%|███▉      | 47/121 [00:00<00:00, 936.42 it/sec, obj=-4]
    INFO - 17:23:05: ...  40%|███▉      | 48/121 [00:00<00:00, 937.91 it/sec, obj=-3]
    INFO - 17:23:05: ...  40%|████      | 49/121 [00:00<00:00, 939.82 it/sec, obj=-2]
    INFO - 17:23:05: ...  41%|████▏     | 50/121 [00:00<00:00, 941.64 it/sec, obj=-1]
    INFO - 17:23:05: ...  42%|████▏     | 51/121 [00:00<00:00, 942.13 it/sec, obj=0]
    INFO - 17:23:05: ...  43%|████▎     | 52/121 [00:00<00:00, 943.43 it/sec, obj=1]
    INFO - 17:23:05: ...  44%|████▍     | 53/121 [00:00<00:00, 945.19 it/sec, obj=2]
    INFO - 17:23:05: ...  45%|████▍     | 54/121 [00:00<00:00, 946.91 it/sec, obj=3]
    INFO - 17:23:05: ...  45%|████▌     | 55/121 [00:00<00:00, 947.15 it/sec, obj=4]
    INFO - 17:23:05: ...  46%|████▋     | 56/121 [00:00<00:00, 948.21 it/sec, obj=-5]
    INFO - 17:23:05: ...  47%|████▋     | 57/121 [00:00<00:00, 949.80 it/sec, obj=-4]
    INFO - 17:23:05: ...  48%|████▊     | 58/121 [00:00<00:00, 951.38 it/sec, obj=-3]
    INFO - 17:23:05: ...  49%|████▉     | 59/121 [00:00<00:00, 951.72 it/sec, obj=-2]
    INFO - 17:23:05: ...  50%|████▉     | 60/121 [00:00<00:00, 952.55 it/sec, obj=-1]
    INFO - 17:23:05: ...  50%|█████     | 61/121 [00:00<00:00, 953.88 it/sec, obj=0]
    INFO - 17:23:05: ...  51%|█████     | 62/121 [00:00<00:00, 955.19 it/sec, obj=1]
    INFO - 17:23:05: ...  52%|█████▏    | 63/121 [00:00<00:00, 955.47 it/sec, obj=2]
    INFO - 17:23:05: ...  53%|█████▎    | 64/121 [00:00<00:00, 956.25 it/sec, obj=3]
    INFO - 17:23:05: ...  54%|█████▎    | 65/121 [00:00<00:00, 957.53 it/sec, obj=4]
    INFO - 17:23:05: ...  55%|█████▍    | 66/121 [00:00<00:00, 958.73 it/sec, obj=5]
    INFO - 17:23:05: ...  55%|█████▌    | 67/121 [00:00<00:00, 959.07 it/sec, obj=-4]
    INFO - 17:23:05: ...  56%|█████▌    | 68/121 [00:00<00:00, 959.94 it/sec, obj=-3]
    INFO - 17:23:05: ...  57%|█████▋    | 69/121 [00:00<00:00, 960.88 it/sec, obj=-2]
    INFO - 17:23:05: ...  58%|█████▊    | 70/121 [00:00<00:00, 962.00 it/sec, obj=-1]
    INFO - 17:23:05: ...  59%|█████▊    | 71/121 [00:00<00:00, 960.19 it/sec, obj=0]
    INFO - 17:23:05: ...  60%|█████▉    | 72/121 [00:00<00:00, 960.99 it/sec, obj=1]
    INFO - 17:23:05: ...  60%|██████    | 73/121 [00:00<00:00, 961.92 it/sec, obj=2]
    INFO - 17:23:05: ...  61%|██████    | 74/121 [00:00<00:00, 962.11 it/sec, obj=3]
    INFO - 17:23:05: ...  62%|██████▏   | 75/121 [00:00<00:00, 962.33 it/sec, obj=4]
    INFO - 17:23:05: ...  63%|██████▎   | 76/121 [00:00<00:00, 962.81 it/sec, obj=5]
    INFO - 17:23:05: ...  64%|██████▎   | 77/121 [00:00<00:00, 963.80 it/sec, obj=6]
    INFO - 17:23:05: ...  64%|██████▍   | 78/121 [00:00<00:00, 964.74 it/sec, obj=-3]
    INFO - 17:23:05: ...  65%|██████▌   | 79/121 [00:00<00:00, 964.54 it/sec, obj=-2]
    INFO - 17:23:05: ...  66%|██████▌   | 80/121 [00:00<00:00, 965.63 it/sec, obj=-1]
    INFO - 17:23:05: ...  67%|██████▋   | 81/121 [00:00<00:00, 966.23 it/sec, obj=0]
    INFO - 17:23:05: ...  68%|██████▊   | 82/121 [00:00<00:00, 967.07 it/sec, obj=1]
    INFO - 17:23:05: ...  69%|██████▊   | 83/121 [00:00<00:00, 967.21 it/sec, obj=2]
    INFO - 17:23:05: ...  69%|██████▉   | 84/121 [00:00<00:00, 967.71 it/sec, obj=3]
    INFO - 17:23:05: ...  70%|███████   | 85/121 [00:00<00:00, 968.35 it/sec, obj=4]
    INFO - 17:23:05: ...  71%|███████   | 86/121 [00:00<00:00, 969.08 it/sec, obj=5]
    INFO - 17:23:05: ...  72%|███████▏  | 87/121 [00:00<00:00, 969.75 it/sec, obj=6]
    INFO - 17:23:05: ...  73%|███████▎  | 88/121 [00:00<00:00, 969.71 it/sec, obj=7]
    INFO - 17:23:05: ...  74%|███████▎  | 89/121 [00:00<00:00, 970.34 it/sec, obj=-2]
    INFO - 17:23:05: ...  74%|███████▍  | 90/121 [00:00<00:00, 971.04 it/sec, obj=-1]
    INFO - 17:23:05: ...  75%|███████▌  | 91/121 [00:00<00:00, 971.80 it/sec, obj=0]
    INFO - 17:23:05: ...  76%|███████▌  | 92/121 [00:00<00:00, 971.64 it/sec, obj=1]
    INFO - 17:23:05: ...  77%|███████▋  | 93/121 [00:00<00:00, 972.12 it/sec, obj=2]
    INFO - 17:23:05: ...  78%|███████▊  | 94/121 [00:00<00:00, 972.80 it/sec, obj=3]
    INFO - 17:23:05: ...  79%|███████▊  | 95/121 [00:00<00:00, 973.47 it/sec, obj=4]
    INFO - 17:23:05: ...  79%|███████▉  | 96/121 [00:00<00:00, 973.35 it/sec, obj=5]
    INFO - 17:23:05: ...  80%|████████  | 97/121 [00:00<00:00, 973.75 it/sec, obj=6]
    INFO - 17:23:05: ...  81%|████████  | 98/121 [00:00<00:00, 974.27 it/sec, obj=7]
    INFO - 17:23:05: ...  82%|████████▏ | 99/121 [00:00<00:00, 974.89 it/sec, obj=8]
    INFO - 17:23:05: ...  83%|████████▎ | 100/121 [00:00<00:00, 974.71 it/sec, obj=-1]
    INFO - 17:23:05: ...  83%|████████▎ | 101/121 [00:00<00:00, 975.17 it/sec, obj=0]
    INFO - 17:23:05: ...  84%|████████▍ | 102/121 [00:00<00:00, 975.76 it/sec, obj=1]
    INFO - 17:23:05: ...  85%|████████▌ | 103/121 [00:00<00:00, 976.31 it/sec, obj=2]
    INFO - 17:23:05: ...  86%|████████▌ | 104/121 [00:00<00:00, 976.15 it/sec, obj=3]
    INFO - 17:23:05: ...  87%|████████▋ | 105/121 [00:00<00:00, 976.57 it/sec, obj=4]
    INFO - 17:23:05: ...  88%|████████▊ | 106/121 [00:00<00:00, 976.49 it/sec, obj=5]
    INFO - 17:23:05: ...  88%|████████▊ | 107/121 [00:00<00:00, 976.08 it/sec, obj=6]
    INFO - 17:23:05: ...  89%|████████▉ | 108/121 [00:00<00:00, 976.09 it/sec, obj=7]
    INFO - 17:23:05: ...  90%|█████████ | 109/121 [00:00<00:00, 976.41 it/sec, obj=8]
    INFO - 17:23:05: ...  91%|█████████ | 110/121 [00:00<00:00, 976.94 it/sec, obj=9]
    INFO - 17:23:05: ...  92%|█████████▏| 111/121 [00:00<00:00, 977.54 it/sec, obj=0]
    INFO - 17:23:05: ...  93%|█████████▎| 112/121 [00:00<00:00, 977.37 it/sec, obj=1]
    INFO - 17:23:05: ...  93%|█████████▎| 113/121 [00:00<00:00, 977.58 it/sec, obj=2]
    INFO - 17:23:05: ...  94%|█████████▍| 114/121 [00:00<00:00, 978.10 it/sec, obj=3]
    INFO - 17:23:05: ...  95%|█████████▌| 115/121 [00:00<00:00, 978.53 it/sec, obj=4]
    INFO - 17:23:05: ...  96%|█████████▌| 116/121 [00:00<00:00, 978.36 it/sec, obj=5]
    INFO - 17:23:05: ...  97%|█████████▋| 117/121 [00:00<00:00, 978.67 it/sec, obj=6]
    INFO - 17:23:05: ...  98%|█████████▊| 118/121 [00:00<00:00, 979.16 it/sec, obj=7]
    INFO - 17:23:05: ...  98%|█████████▊| 119/121 [00:00<00:00, 979.64 it/sec, obj=8]
    INFO - 17:23:05: ...  99%|█████████▉| 120/121 [00:00<00:00, 979.25 it/sec, obj=9]
    INFO - 17:23:05: ... 100%|██████████| 121/121 [00:00<00:00, 979.52 it/sec, obj=10]
    INFO - 17:23:05: Optimization result:
    INFO - 17:23:05:    Optimizer info:
    INFO - 17:23:05:       Status: None
    INFO - 17:23:05:       Message: None
    INFO - 17:23:05:       Number of calls to the objective function by the optimizer: 121
    INFO - 17:23:05:    Solution:
    INFO - 17:23:05:       Objective: -10.0
    INFO - 17:23:05:       Design space:
    INFO - 17:23:05:       +------+-------------+-------+-------------+---------+
    INFO - 17:23:05:       | name | lower_bound | value | upper_bound | type    |
    INFO - 17:23:05:       +------+-------------+-------+-------------+---------+
    INFO - 17:23:05:       | x1   |      -5     |   -5  |      5      | integer |
    INFO - 17:23:05:       | x2   |      -5     |   -5  |      5      | integer |
    INFO - 17:23:05:       +------+-------------+-------+-------------+---------+
    INFO - 17:23:05: *** End DOEScenario execution (time: 0:00:00.139840) ***

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

Gallery generated by Sphinx-Gallery