.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/api/plot_sampling.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_api_plot_sampling.py: Sample several disciplines. ========================== The :class:`.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 :func:`.sample_disciplines` function whose API has been designed fro sampling purposes. .. GENERATED FROM PYTHON SOURCE LINES 29-36 .. code-block:: Python from __future__ import annotations from gemseo import sample_disciplines from gemseo.algos.design_space import DesignSpace from gemseo.disciplines.analytic import AnalyticDiscipline .. GENERATED FROM PYTHON SOURCE LINES 37-39 First, create the disciplines: .. GENERATED FROM PYTHON SOURCE LINES 39-45 .. code-block:: Python disciplines = [ AnalyticDiscipline({"y1": "x0+x1+y2"}), AnalyticDiscipline({"y2": "x0+x2+2*y1"}), AnalyticDiscipline({"y0": "x0+y1+y2"}), ] .. GENERATED FROM PYTHON SOURCE LINES 46-48 Then, create the input space: .. GENERATED FROM PYTHON SOURCE LINES 48-53 .. code-block:: Python 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) .. GENERATED FROM PYTHON SOURCE LINES 54-57 Lastly, sample these disciplines over the input space with the outputs of interest, the number of samples and the name of the DOE algorithm: .. GENERATED FROM PYTHON SOURCE LINES 57-62 .. code-block:: Python io_dataset = sample_disciplines( disciplines, input_space, ["y0", "y2"], algo_name="PYDOE_FULLFACT", n_samples=10 ) io_dataset .. raw:: html
GROUP inputs outputs
VARIABLE x0 x1 x2 y0 y2
COMPONENT 0 0 0 0 0
0 0.0 0.0 0.0 0.0 0.0
1 1.0 0.0 0.0 -4.0 -3.0
2 0.0 1.0 0.0 -3.0 -2.0
3 1.0 1.0 0.0 -7.0 -5.0
4 0.0 0.0 1.0 -2.0 -1.0
5 1.0 0.0 1.0 -6.0 -4.0
6 0.0 1.0 1.0 -5.0 -3.0
7 1.0 1.0 1.0 -9.0 -6.0


.. GENERATED FROM PYTHON SOURCE LINES 63-68 Note that this function creates an :class:`.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. .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.060 seconds) .. _sphx_glr_download_examples_api_plot_sampling.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_sampling.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_sampling.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_sampling.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_