Note
Click here to download the full example code
Diagonal design of experiments¶
Here is an illustration of the diagonal design of experiments (DOE)
implemented by the DiagonalDOE
class
and used by the ScalableDiagonalModel
.
The idea is to sample the discipline by varying its inputs proportionally
on one of the diagonals of its input space.
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
configure_logger()
<RootLogger root (INFO)>
Create the discipline¶
First, we create an AnalyticDiscipline
implementing the function: \(f(x)=2x-3\sin(2\pi y)\)
and set its cache policy to "MemoryFullCache"
.
discipline = create_discipline(
"AnalyticDiscipline", expressions={"z": "2*x-3*sin(2*pi*y)"}
)
Create the design space¶
Then, we create a DesignSpace
where \(x\) and \(y\) vary between 0 and 1.
design_space = create_design_space()
design_space.add_variable("x", l_b=0.0, u_b=1.0)
design_space.add_variable("y", l_b=0.0, u_b=1.0)
Sample with the default mode¶
Lastly, we create a DOEScenario
and execute it with the DiagonalDOE
algorithm
to get 10 evaluations of \(f\).
Note that we use the default configuration:
all the disciplinary inputs vary proportionally
from their lower bounds to their upper bounds.
scenario = create_scenario(
discipline, "DisciplinaryOpt", "z", design_space, scenario_type="DOE"
)
scenario.execute({"algo": "DiagonalDOE", "n_samples": 10})
dataset = scenario.export_to_dataset(opt_naming=False)
dataset.plot("ScatterMatrix", save=False, show=True)

INFO - 17:20:42:
INFO - 17:20:42: *** Start DOEScenario execution ***
INFO - 17:20:42: DOEScenario
INFO - 17:20:42: Disciplines: AnalyticDiscipline
INFO - 17:20:42: MDO formulation: DisciplinaryOpt
INFO - 17:20:42: Optimization problem:
INFO - 17:20:42: minimize z(x, y)
INFO - 17:20:42: with respect to x, y
INFO - 17:20:42: over the design space:
INFO - 17:20:42: +------+-------------+-------+-------------+-------+
INFO - 17:20:42: | name | lower_bound | value | upper_bound | type |
INFO - 17:20:42: +------+-------------+-------+-------------+-------+
INFO - 17:20:42: | x | 0 | None | 1 | float |
INFO - 17:20:42: | y | 0 | None | 1 | float |
INFO - 17:20:42: +------+-------------+-------+-------------+-------+
INFO - 17:20:42: Solving optimization problem with algorithm DiagonalDOE:
INFO - 17:20:42: ... 0%| | 0/10 [00:00<?, ?it]
INFO - 17:20:42: ... 10%|█ | 1/10 [00:00<00:00, 227.79 it/sec, obj=0]
INFO - 17:20:42: ... 20%|██ | 2/10 [00:00<00:00, 370.16 it/sec, obj=-1.71]
INFO - 17:20:42: ... 30%|███ | 3/10 [00:00<00:00, 461.06 it/sec, obj=-2.51]
INFO - 17:20:42: ... 40%|████ | 4/10 [00:00<00:00, 531.63 it/sec, obj=-1.93]
INFO - 17:20:42: ... 50%|█████ | 5/10 [00:00<00:00, 588.08 it/sec, obj=-.137]
INFO - 17:20:42: ... 60%|██████ | 6/10 [00:00<00:00, 632.78 it/sec, obj=2.14]
INFO - 17:20:42: ... 70%|███████ | 7/10 [00:00<00:00, 662.79 it/sec, obj=3.93]
INFO - 17:20:42: ... 80%|████████ | 8/10 [00:00<00:00, 691.32 it/sec, obj=4.51]
INFO - 17:20:42: ... 90%|█████████ | 9/10 [00:00<00:00, 717.57 it/sec, obj=3.71]
INFO - 17:20:42: ... 100%|██████████| 10/10 [00:00<00:00, 740.18 it/sec, obj=2]
INFO - 17:20:42: Optimization result:
INFO - 17:20:42: Optimizer info:
INFO - 17:20:42: Status: None
INFO - 17:20:42: Message: None
INFO - 17:20:42: Number of calls to the objective function by the optimizer: 10
INFO - 17:20:42: Solution:
INFO - 17:20:42: Objective: -2.5099788145921798
INFO - 17:20:42: Design space:
INFO - 17:20:42: +------+-------------+--------------------+-------------+-------+
INFO - 17:20:42: | name | lower_bound | value | upper_bound | type |
INFO - 17:20:42: +------+-------------+--------------------+-------------+-------+
INFO - 17:20:42: | x | 0 | 0.2222222222222222 | 1 | float |
INFO - 17:20:42: | y | 0 | 0.2222222222222222 | 1 | float |
INFO - 17:20:42: +------+-------------+--------------------+-------------+-------+
INFO - 17:20:42: *** End DOEScenario execution (time: 0:00:00.027541) ***
/home/docs/checkouts/readthedocs.org/user_builds/gemseo/envs/4.2.0/lib/python3.9/site-packages/gemseo/post/dataset/scatter_plot_matrix.py:135: UserWarning: To output multiple subplots, the figure containing the passed axes is being cleared.
sub_axes = scatter_matrix(
<gemseo.post.dataset.scatter_plot_matrix.ScatterMatrix object at 0x7fcd1b5f3190>
Sample with reverse mode for \(y\)¶
We can also change the configuration
in order to select another diagonal of the input space,
e.g. increasing \(x\) and decreasing \(y\).
This configuration is illustrated in the new ScatterMatrix
plot
where the \((x,y)\) points follow the \(t\mapsto -t\) line
while the \((x,y)\) points follow the \(t\mapsto t\) line
with the default configuration.
scenario = create_scenario(
discipline, "DisciplinaryOpt", "z", design_space, scenario_type="DOE"
)
scenario.execute(
{"algo": "DiagonalDOE", "n_samples": 10, "algo_options": {"reverse": ["y"]}}
)
dataset = scenario.export_to_dataset(opt_naming=False)
dataset.plot("ScatterMatrix", save=False, show=True)

INFO - 17:20:43:
INFO - 17:20:43: *** Start DOEScenario execution ***
INFO - 17:20:43: DOEScenario
INFO - 17:20:43: Disciplines: AnalyticDiscipline
INFO - 17:20:43: MDO formulation: DisciplinaryOpt
INFO - 17:20:43: Optimization problem:
INFO - 17:20:43: minimize z(x, y)
INFO - 17:20:43: with respect to x, y
INFO - 17:20:43: over the design space:
INFO - 17:20:43: +------+-------------+--------------------+-------------+-------+
INFO - 17:20:43: | name | lower_bound | value | upper_bound | type |
INFO - 17:20:43: +------+-------------+--------------------+-------------+-------+
INFO - 17:20:43: | x | 0 | 0.2222222222222222 | 1 | float |
INFO - 17:20:43: | y | 0 | 0.2222222222222222 | 1 | float |
INFO - 17:20:43: +------+-------------+--------------------+-------------+-------+
INFO - 17:20:43: Solving optimization problem with algorithm DiagonalDOE:
INFO - 17:20:43: ... 0%| | 0/10 [00:00<?, ?it]
INFO - 17:20:43: ... 10%|█ | 1/10 [00:00<00:00, 1061.85 it/sec, obj=7.35e-16]
INFO - 17:20:43: ... 20%|██ | 2/10 [00:00<00:00, 975.08 it/sec, obj=2.15]
INFO - 17:20:43: ... 30%|███ | 3/10 [00:00<00:00, 952.39 it/sec, obj=3.4]
INFO - 17:20:43: ... 40%|████ | 4/10 [00:00<00:00, 961.11 it/sec, obj=3.26]
INFO - 17:20:43: ... 50%|█████ | 5/10 [00:00<00:00, 973.34 it/sec, obj=1.91]
INFO - 17:20:43: ... 60%|██████ | 6/10 [00:00<00:00, 982.35 it/sec, obj=0.0851]
INFO - 17:20:43: ... 70%|███████ | 7/10 [00:00<00:00, 971.32 it/sec, obj=-1.26]
INFO - 17:20:43: ... 80%|████████ | 8/10 [00:00<00:00, 975.25 it/sec, obj=-1.4]
INFO - 17:20:43: ... 90%|█████████ | 9/10 [00:00<00:00, 977.52 it/sec, obj=-.151]
INFO - 17:20:43: ... 100%|██████████| 10/10 [00:00<00:00, 978.63 it/sec, obj=2]
INFO - 17:20:43: Optimization result:
INFO - 17:20:43: Optimizer info:
INFO - 17:20:43: Status: None
INFO - 17:20:43: Message: None
INFO - 17:20:43: Number of calls to the objective function by the optimizer: 10
INFO - 17:20:43: Solution:
INFO - 17:20:43: Objective: -1.3988677034810695
INFO - 17:20:43: Design space:
INFO - 17:20:43: +------+-------------+--------------------+-------------+-------+
INFO - 17:20:43: | name | lower_bound | value | upper_bound | type |
INFO - 17:20:43: +------+-------------+--------------------+-------------+-------+
INFO - 17:20:43: | x | 0 | 0.7777777777777777 | 1 | float |
INFO - 17:20:43: | y | 0 | 0.2222222222222223 | 1 | float |
INFO - 17:20:43: +------+-------------+--------------------+-------------+-------+
INFO - 17:20:43: *** End DOEScenario execution (time: 0:00:00.024384) ***
/home/docs/checkouts/readthedocs.org/user_builds/gemseo/envs/4.2.0/lib/python3.9/site-packages/gemseo/post/dataset/scatter_plot_matrix.py:135: UserWarning: To output multiple subplots, the figure containing the passed axes is being cleared.
sub_axes = scatter_matrix(
<gemseo.post.dataset.scatter_plot_matrix.ScatterMatrix object at 0x7fcd1b384a60>
Total running time of the script: ( 0 minutes 1.609 seconds)