Note
Go to the end to download the full example code.
Sample several disciplines.#
The DOEScenario class is used to solve trade-off studies,
based on a design space, an objective and optional constraints.
But for a simple need of sampling disciplines,
this class is not very appropriate
because the notions of objective, which is mandatory, and constraints do not make sense
and the same for the log including information related to an optimization problem.
Rather than using this class,
you can consider the sample_disciplines() function
whose API has been designed fro sampling purposes.
from __future__ import annotations
from gemseo import sample_disciplines
from gemseo.algos.design_space import DesignSpace
from gemseo.disciplines.analytic import AnalyticDiscipline
First, create the disciplines:
disciplines = [
AnalyticDiscipline({"y1": "x0+x1+y2"}),
AnalyticDiscipline({"y2": "x0+x2+2*y1"}),
AnalyticDiscipline({"y0": "x0+y1+y2"}),
]
Then, create the input space:
input_space = DesignSpace()
input_space.add_variable("x0", lower_bound=0.0, upper_bound=1.0)
input_space.add_variable("x1", lower_bound=0.0, upper_bound=1.0)
input_space.add_variable("x2", lower_bound=0.0, upper_bound=1.0)
Lastly, sample these disciplines over the input space with the outputs of interest, the number of samples and the name of the DOE algorithm:
io_dataset = sample_disciplines(
disciplines, input_space, ["y0", "y2"], algo_name="PYDOE_FULLFACT", n_samples=10
)
io_dataset
INFO - 16:24:58: *** Start Sampling execution ***
INFO - 16:24:58: Sampling
INFO - 16:24:58: Disciplines: AnalyticDiscipline AnalyticDiscipline AnalyticDiscipline
INFO - 16:24:58: MDO formulation: MDF
INFO - 16:24:58: Running the algorithm PYDOE_FULLFACT:
WARNING - 16:24:58: A full-factorial DOE of 10 samples in dimension 3 does not exist; use 8 samples instead, i.e. the largest 3-th integer power less than 10.
INFO - 16:24:58: 12%|█▎ | 1/8 [00:00<00:00, 159.82 it/sec]
INFO - 16:24:58: 25%|██▌ | 2/8 [00:00<00:00, 227.09 it/sec]
INFO - 16:24:58: 38%|███▊ | 3/8 [00:00<00:00, 272.38 it/sec]
INFO - 16:24:58: 50%|█████ | 4/8 [00:00<00:00, 298.59 it/sec]
INFO - 16:24:58: 62%|██████▎ | 5/8 [00:00<00:00, 320.01 it/sec]
INFO - 16:24:58: 75%|███████▌ | 6/8 [00:00<00:00, 336.01 it/sec]
INFO - 16:24:58: 88%|████████▊ | 7/8 [00:00<00:00, 345.32 it/sec]
INFO - 16:24:58: 100%|██████████| 8/8 [00:00<00:00, 353.43 it/sec]
INFO - 16:24:58: *** End Sampling execution ***
Note that this function creates an MDF formulation
and samples the top-level disciplines generated by this MDO formulation.
The formulation and formulation_options arguments
allow to customize the MDO formulation
and the options of the DOE algorithm can be passed as keyword arguments.
Total running time of the script: (0 minutes 0.047 seconds)