.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/scenario/plot_doe_scenario.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_scenario_plot_doe_scenario.py: Create a DOE Scenario ===================== .. GENERATED FROM PYTHON SOURCE LINES 26-39 .. code-block:: Python 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() .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 40-61 Let :math:`(P)` be a simple optimization problem: .. math:: (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. In this example, we will see how to use |g| to solve this problem :math:`(P)` by means of a Design Of Experiments (DOE) Define the discipline --------------------- Firstly, by means of the :func:`.create_discipline` API function, we create an :class:`.Discipline` of :class:`.AnalyticDiscipline` type from a Python function: .. GENERATED FROM PYTHON SOURCE LINES 62-66 .. code-block:: Python expressions = {"y": "x1+x2"} discipline = create_discipline("AnalyticDiscipline", expressions=expressions) .. GENERATED FROM PYTHON SOURCE LINES 67-75 Now, we want to minimize this :class:`.Discipline` over a design of experiments (DOE). Define the design space ----------------------- For that, by means of the :func:`.create_design_space` API function, we define the :class:`.DesignSpace` :math:`[-5, 5]\times[-5, 5]` by using its :meth:`.DesignSpace.add_variable` method. .. GENERATED FROM PYTHON SOURCE LINES 75-80 .. code-block:: Python 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") .. GENERATED FROM PYTHON SOURCE LINES 81-86 Define the DOE scenario ----------------------- Then, by means of the :func:`.create_scenario` API function, we define a :class:`.DOEScenario` from the :class:`.Discipline` and the :class:`.DesignSpace` defined above: .. GENERATED FROM PYTHON SOURCE LINES 86-95 .. code-block:: Python scenario = create_scenario( discipline, "y", design_space, scenario_type="DOE", formulation_name="DisciplinaryOpt", ) .. GENERATED FROM PYTHON SOURCE LINES 96-98 Note that the formulation settings passed to :func:`.create_scenario` can be provided via a Pydantic model. For more information, see :ref:`formulation_settings`. .. GENERATED FROM PYTHON SOURCE LINES 100-107 Execute the DOE scenario ------------------------ Lastly, we solve the :class:`.OptimizationProblem` included in the :class:`.DOEScenario` defined above by minimizing the objective function over a design of experiments included in the :class:`.DesignSpace`. Precisely, we choose a `full factorial design `_ of size :math:`11^2`: .. GENERATED FROM PYTHON SOURCE LINES 107-110 .. code-block:: Python scenario.execute(algo_name="PYDOE_FULLFACT", n_samples=11**2) .. rst-class:: sphx-glr-script-out .. code-block:: none INFO - 11:42:50: *** Start DOEScenario execution *** INFO - 11:42:50: DOEScenario INFO - 11:42:50: Disciplines: AnalyticDiscipline INFO - 11:42:50: MDO formulation: DisciplinaryOpt INFO - 11:42:50: Optimization problem: INFO - 11:42:50: minimize y(x1, x2) INFO - 11:42:50: with respect to x1, x2 INFO - 11:42:50: over the design space: INFO - 11:42:50: +------+-------------+-------+-------------+---------+ INFO - 11:42:50: | Name | Lower bound | Value | Upper bound | Type | INFO - 11:42:50: +------+-------------+-------+-------------+---------+ INFO - 11:42:50: | x1 | -5 | None | 5 | integer | INFO - 11:42:50: | x2 | -5 | None | 5 | integer | INFO - 11:42:50: +------+-------------+-------+-------------+---------+ INFO - 11:42:50: Solving optimization problem with algorithm PYDOE_FULLFACT: INFO - 11:42:50: 1%| | 1/121 [00:00<00:00, 458.54 it/sec, obj=-10] INFO - 11:42:50: 2%|▏ | 2/121 [00:00<00:00, 782.01 it/sec, obj=-9] INFO - 11:42:50: 2%|▏ | 3/121 [00:00<00:00, 1049.80 it/sec, obj=-8] INFO - 11:42:50: 3%|▎ | 4/121 [00:00<00:00, 1253.06 it/sec, obj=-7] INFO - 11:42:50: 4%|▍ | 5/121 [00:00<00:00, 1437.88 it/sec, obj=-6] INFO - 11:42:50: 5%|▍ | 6/121 [00:00<00:00, 1606.50 it/sec, obj=-5] INFO - 11:42:50: 6%|▌ | 7/121 [00:00<00:00, 1758.51 it/sec, obj=-4] INFO - 11:42:50: 7%|▋ | 8/121 [00:00<00:00, 1871.31 it/sec, obj=-3] INFO - 11:42:50: 7%|▋ | 9/121 [00:00<00:00, 1987.30 it/sec, obj=-2] INFO - 11:42:50: 8%|▊ | 10/121 [00:00<00:00, 2095.27 it/sec, obj=-1] INFO - 11:42:50: 9%|▉ | 11/121 [00:00<00:00, 2195.97 it/sec, obj=0] INFO - 11:42:50: 10%|▉ | 12/121 [00:00<00:00, 2271.90 it/sec, obj=-9] INFO - 11:42:50: 11%|█ | 13/121 [00:00<00:00, 2349.75 it/sec, obj=-8] INFO - 11:42:50: 12%|█▏ | 14/121 [00:00<00:00, 2426.76 it/sec, obj=-7] INFO - 11:42:50: 12%|█▏ | 15/121 [00:00<00:00, 2500.78 it/sec, obj=-6] INFO - 11:42:50: 13%|█▎ | 16/121 [00:00<00:00, 2556.63 it/sec, obj=-5] INFO - 11:42:50: 14%|█▍ | 17/121 [00:00<00:00, 2614.33 it/sec, obj=-4] INFO - 11:42:50: 15%|█▍ | 18/121 [00:00<00:00, 2669.74 it/sec, obj=-3] INFO - 11:42:50: 16%|█▌ | 19/121 [00:00<00:00, 2723.29 it/sec, obj=-2] INFO - 11:42:50: 17%|█▋ | 20/121 [00:00<00:00, 2733.51 it/sec, obj=-1] INFO - 11:42:50: 17%|█▋ | 21/121 [00:00<00:00, 2775.67 it/sec, obj=0] INFO - 11:42:50: 18%|█▊ | 22/121 [00:00<00:00, 2815.31 it/sec, obj=1] INFO - 11:42:50: 19%|█▉ | 23/121 [00:00<00:00, 2845.86 it/sec, obj=-8] INFO - 11:42:50: 20%|█▉ | 24/121 [00:00<00:00, 2875.68 it/sec, obj=-7] INFO - 11:42:50: 21%|██ | 25/121 [00:00<00:00, 2913.03 it/sec, obj=-6] INFO - 11:42:50: 21%|██▏ | 26/121 [00:00<00:00, 2951.02 it/sec, obj=-5] INFO - 11:42:50: 22%|██▏ | 27/121 [00:00<00:00, 2986.29 it/sec, obj=-4] INFO - 11:42:50: 23%|██▎ | 28/121 [00:00<00:00, 3007.05 it/sec, obj=-3] INFO - 11:42:50: 24%|██▍ | 29/121 [00:00<00:00, 3033.36 it/sec, obj=-2] INFO - 11:42:50: 25%|██▍ | 30/121 [00:00<00:00, 3061.46 it/sec, obj=-1] INFO - 11:42:50: 26%|██▌ | 31/121 [00:00<00:00, 3090.87 it/sec, obj=0] INFO - 11:42:50: 26%|██▋ | 32/121 [00:00<00:00, 3097.86 it/sec, obj=1] INFO - 11:42:50: 27%|██▋ | 33/121 [00:00<00:00, 3124.00 it/sec, obj=2] INFO - 11:42:50: 28%|██▊ | 34/121 [00:00<00:00, 3102.90 it/sec, obj=-7] INFO - 11:42:50: 29%|██▉ | 35/121 [00:00<00:00, 3102.49 it/sec, obj=-6] INFO - 11:42:50: 30%|██▉ | 36/121 [00:00<00:00, 3118.44 it/sec, obj=-5] INFO - 11:42:50: 31%|███ | 37/121 [00:00<00:00, 3137.42 it/sec, obj=-4] INFO - 11:42:50: 31%|███▏ | 38/121 [00:00<00:00, 3156.86 it/sec, obj=-3] INFO - 11:42:50: 32%|███▏ | 39/121 [00:00<00:00, 3169.38 it/sec, obj=-2] INFO - 11:42:50: 33%|███▎ | 40/121 [00:00<00:00, 3184.80 it/sec, obj=-1] INFO - 11:42:50: 34%|███▍ | 41/121 [00:00<00:00, 3201.58 it/sec, obj=0] INFO - 11:42:50: 35%|███▍ | 42/121 [00:00<00:00, 3220.43 it/sec, obj=1] INFO - 11:42:50: 36%|███▌ | 43/121 [00:00<00:00, 3231.42 it/sec, obj=2] INFO - 11:42:50: 36%|███▋ | 44/121 [00:00<00:00, 3246.77 it/sec, obj=3] INFO - 11:42:50: 37%|███▋ | 45/121 [00:00<00:00, 3264.28 it/sec, obj=-6] INFO - 11:42:50: 38%|███▊ | 46/121 [00:00<00:00, 3280.53 it/sec, obj=-5] INFO - 11:42:50: 39%|███▉ | 47/121 [00:00<00:00, 3289.49 it/sec, obj=-4] INFO - 11:42:50: 40%|███▉ | 48/121 [00:00<00:00, 3306.40 it/sec, obj=-3] INFO - 11:42:50: 40%|████ | 49/121 [00:00<00:00, 3322.84 it/sec, obj=-2] INFO - 11:42:50: 41%|████▏ | 50/121 [00:00<00:00, 3338.88 it/sec, obj=-1] INFO - 11:42:50: 42%|████▏ | 51/121 [00:00<00:00, 3348.98 it/sec, obj=0] INFO - 11:42:50: 43%|████▎ | 52/121 [00:00<00:00, 3364.09 it/sec, obj=1] INFO - 11:42:50: 44%|████▍ | 53/121 [00:00<00:00, 3378.39 it/sec, obj=2] INFO - 11:42:50: 45%|████▍ | 54/121 [00:00<00:00, 3392.69 it/sec, obj=3] INFO - 11:42:50: 45%|████▌ | 55/121 [00:00<00:00, 3400.00 it/sec, obj=4] INFO - 11:42:50: 46%|████▋ | 56/121 [00:00<00:00, 3412.28 it/sec, obj=-5] INFO - 11:42:50: 47%|████▋ | 57/121 [00:00<00:00, 3425.69 it/sec, obj=-4] INFO - 11:42:50: 48%|████▊ | 58/121 [00:00<00:00, 3438.73 it/sec, obj=-3] INFO - 11:42:50: 49%|████▉ | 59/121 [00:00<00:00, 3446.33 it/sec, obj=-2] INFO - 11:42:50: 50%|████▉ | 60/121 [00:00<00:00, 3456.99 it/sec, obj=-1] INFO - 11:42:50: 50%|█████ | 61/121 [00:00<00:00, 3465.47 it/sec, obj=0] INFO - 11:42:50: 51%|█████ | 62/121 [00:00<00:00, 3475.54 it/sec, obj=1] INFO - 11:42:50: 52%|█████▏ | 63/121 [00:00<00:00, 3482.77 it/sec, obj=2] INFO - 11:42:50: 53%|█████▎ | 64/121 [00:00<00:00, 3489.98 it/sec, obj=3] INFO - 11:42:50: 54%|█████▎ | 65/121 [00:00<00:00, 3500.05 it/sec, obj=4] INFO - 11:42:50: 55%|█████▍ | 66/121 [00:00<00:00, 3510.55 it/sec, obj=5] INFO - 11:42:50: 55%|█████▌ | 67/121 [00:00<00:00, 3520.87 it/sec, obj=-4] INFO - 11:42:50: 56%|█████▌ | 68/121 [00:00<00:00, 3526.24 it/sec, obj=-3] INFO - 11:42:50: 57%|█████▋ | 69/121 [00:00<00:00, 3536.73 it/sec, obj=-2] INFO - 11:42:50: 58%|█████▊ | 70/121 [00:00<00:00, 3546.72 it/sec, obj=-1] INFO - 11:42:50: 59%|█████▊ | 71/121 [00:00<00:00, 3555.68 it/sec, obj=0] INFO - 11:42:50: 60%|█████▉ | 72/121 [00:00<00:00, 3554.16 it/sec, obj=1] INFO - 11:42:50: 60%|██████ | 73/121 [00:00<00:00, 3561.32 it/sec, obj=2] INFO - 11:42:50: 61%|██████ | 74/121 [00:00<00:00, 3570.44 it/sec, obj=3] INFO - 11:42:50: 62%|██████▏ | 75/121 [00:00<00:00, 3579.49 it/sec, obj=4] INFO - 11:42:50: 63%|██████▎ | 76/121 [00:00<00:00, 3584.15 it/sec, obj=5] INFO - 11:42:50: 64%|██████▎ | 77/121 [00:00<00:00, 3592.33 it/sec, obj=6] INFO - 11:42:50: 64%|██████▍ | 78/121 [00:00<00:00, 3597.41 it/sec, obj=-3] INFO - 11:42:50: 65%|██████▌ | 79/121 [00:00<00:00, 3604.41 it/sec, obj=-2] INFO - 11:42:50: 66%|██████▌ | 80/121 [00:00<00:00, 3608.55 it/sec, obj=-1] INFO - 11:42:50: 67%|██████▋ | 81/121 [00:00<00:00, 3614.16 it/sec, obj=0] INFO - 11:42:50: 68%|██████▊ | 82/121 [00:00<00:00, 3619.43 it/sec, obj=1] INFO - 11:42:50: 69%|██████▊ | 83/121 [00:00<00:00, 3625.57 it/sec, obj=2] INFO - 11:42:50: 69%|██████▉ | 84/121 [00:00<00:00, 3629.49 it/sec, obj=3] INFO - 11:42:50: 70%|███████ | 85/121 [00:00<00:00, 3636.21 it/sec, obj=4] INFO - 11:42:50: 71%|███████ | 86/121 [00:00<00:00, 3643.46 it/sec, obj=5] INFO - 11:42:50: 72%|███████▏ | 87/121 [00:00<00:00, 3650.87 it/sec, obj=6] INFO - 11:42:50: 73%|███████▎ | 88/121 [00:00<00:00, 3655.42 it/sec, obj=7] INFO - 11:42:50: 74%|███████▎ | 89/121 [00:00<00:00, 3660.09 it/sec, obj=-2] INFO - 11:42:50: 74%|███████▍ | 90/121 [00:00<00:00, 3666.24 it/sec, obj=-1] INFO - 11:42:50: 75%|███████▌ | 91/121 [00:00<00:00, 3673.34 it/sec, obj=0] INFO - 11:42:50: 76%|███████▌ | 92/121 [00:00<00:00, 3680.16 it/sec, obj=1] INFO - 11:42:50: 77%|███████▋ | 93/121 [00:00<00:00, 3682.86 it/sec, obj=2] INFO - 11:42:50: 78%|███████▊ | 94/121 [00:00<00:00, 3689.37 it/sec, obj=3] INFO - 11:42:50: 79%|███████▊ | 95/121 [00:00<00:00, 3693.23 it/sec, obj=4] INFO - 11:42:50: 79%|███████▉ | 96/121 [00:00<00:00, 3699.56 it/sec, obj=5] INFO - 11:42:50: 80%|████████ | 97/121 [00:00<00:00, 3701.88 it/sec, obj=6] INFO - 11:42:50: 81%|████████ | 98/121 [00:00<00:00, 3706.65 it/sec, obj=7] INFO - 11:42:50: 82%|████████▏ | 99/121 [00:00<00:00, 3711.94 it/sec, obj=8] INFO - 11:42:50: 83%|████████▎ | 100/121 [00:00<00:00, 3717.40 it/sec, obj=-1] INFO - 11:42:50: 83%|████████▎ | 101/121 [00:00<00:00, 3719.76 it/sec, obj=0] INFO - 11:42:50: 84%|████████▍ | 102/121 [00:00<00:00, 3724.73 it/sec, obj=1] INFO - 11:42:50: 85%|████████▌ | 103/121 [00:00<00:00, 3729.98 it/sec, obj=2] INFO - 11:42:50: 86%|████████▌ | 104/121 [00:00<00:00, 3735.42 it/sec, obj=3] INFO - 11:42:50: 87%|████████▋ | 105/121 [00:00<00:00, 3737.95 it/sec, obj=4] INFO - 11:42:50: 88%|████████▊ | 106/121 [00:00<00:00, 3741.79 it/sec, obj=5] INFO - 11:42:50: 88%|████████▊ | 107/121 [00:00<00:00, 3745.91 it/sec, obj=6] INFO - 11:42:50: 89%|████████▉ | 108/121 [00:00<00:00, 3750.87 it/sec, obj=7] INFO - 11:42:50: 90%|█████████ | 109/121 [00:00<00:00, 3755.65 it/sec, obj=8] INFO - 11:42:50: 91%|█████████ | 110/121 [00:00<00:00, 3757.33 it/sec, obj=9] INFO - 11:42:50: 92%|█████████▏| 111/121 [00:00<00:00, 3760.86 it/sec, obj=0] INFO - 11:42:50: 93%|█████████▎| 112/121 [00:00<00:00, 3764.93 it/sec, obj=1] INFO - 11:42:50: 93%|█████████▎| 113/121 [00:00<00:00, 3769.52 it/sec, obj=2] INFO - 11:42:50: 94%|█████████▍| 114/121 [00:00<00:00, 3766.54 it/sec, obj=3] INFO - 11:42:50: 95%|█████████▌| 115/121 [00:00<00:00, 3768.79 it/sec, obj=4] INFO - 11:42:50: 96%|█████████▌| 116/121 [00:00<00:00, 3772.65 it/sec, obj=5] INFO - 11:42:50: 97%|█████████▋| 117/121 [00:00<00:00, 3777.20 it/sec, obj=6] INFO - 11:42:50: 98%|█████████▊| 118/121 [00:00<00:00, 3778.54 it/sec, obj=7] INFO - 11:42:50: 98%|█████████▊| 119/121 [00:00<00:00, 3782.46 it/sec, obj=8] INFO - 11:42:50: 99%|█████████▉| 120/121 [00:00<00:00, 3787.01 it/sec, obj=9] INFO - 11:42:50: 100%|██████████| 121/121 [00:00<00:00, 3791.24 it/sec, obj=10] INFO - 11:42:50: Optimization result: INFO - 11:42:50: Optimizer info: INFO - 11:42:50: Status: None INFO - 11:42:50: Message: None INFO - 11:42:50: Number of calls to the objective function by the optimizer: 121 INFO - 11:42:50: Solution: INFO - 11:42:50: Objective: -10.0 INFO - 11:42:50: Design space: INFO - 11:42:50: +------+-------------+-------+-------------+---------+ INFO - 11:42:50: | Name | Lower bound | Value | Upper bound | Type | INFO - 11:42:50: +------+-------------+-------+-------------+---------+ INFO - 11:42:50: | x1 | -5 | -5 | 5 | integer | INFO - 11:42:50: | x2 | -5 | -5 | 5 | integer | INFO - 11:42:50: +------+-------------+-------+-------------+---------+ INFO - 11:42:50: *** End DOEScenario execution (time: 0:00:00.034625) *** .. GENERATED FROM PYTHON SOURCE LINES 111-113 Note that the algorithm settings passed to :meth:`~.BaseDriverLibrary.execute` can be provided via a Pydantic model. For more information, see :ref:`algorithm_settings`. .. GENERATED FROM PYTHON SOURCE LINES 115-117 The optimum results can be found in the execution log. It is also possible to access them with :attr:`.Scenario.optimization_result`: .. GENERATED FROM PYTHON SOURCE LINES 117-121 .. code-block:: Python optimization_result = scenario.optimization_result f"The solution of P is (x*, f(x*)) = ({optimization_result.x_opt}, {optimization_result.f_opt})" .. rst-class:: sphx-glr-script-out .. code-block:: none 'The solution of P is (x*, f(x*)) = ([-5. -5.], -10.0)' .. GENERATED FROM PYTHON SOURCE LINES 122-125 Available DOE algorithms ------------------------ In order to get the list of available DOE algorithms, use: .. GENERATED FROM PYTHON SOURCE LINES 125-127 .. code-block:: Python get_available_doe_algorithms() .. rst-class:: sphx-glr-script-out .. code-block:: none ['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'] .. GENERATED FROM PYTHON SOURCE LINES 128-131 Available post-processing ------------------------- In order to get the list of available post-processing algorithms, use: .. GENERATED FROM PYTHON SOURCE LINES 131-133 .. code-block:: Python get_available_post_processings() .. rst-class:: sphx-glr-script-out .. code-block:: none ['Animation', 'BasicHistory', 'Compromise', 'ConstraintsHistory', 'Correlations', 'DataVersusModel', 'GradientSensitivity', 'HessianHistory', 'HighTradeOff', 'MultiObjectiveDiagram', 'ObjConstrHist', 'OptHistoryView', 'ParallelCoordinates', 'ParetoFront', 'Petal', 'QuadApprox', 'Radar', 'RadarChart', 'Robustness', 'SOM', 'ScatterPareto', 'ScatterPlotMatrix', 'TopologyView', 'VariableInfluence'] .. GENERATED FROM PYTHON SOURCE LINES 134-140 You can also look at the examples: .. raw:: html
Examples
.. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.043 seconds) .. _sphx_glr_download_examples_scenario_plot_doe_scenario.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_doe_scenario.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_doe_scenario.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_doe_scenario.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_