.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/doe/plot_doe_from_file.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_doe_plot_doe_from_file.py: Use a design of experiments from a file ======================================= .. GENERATED FROM PYTHON SOURCE LINES 24-33 .. code-block:: Python from __future__ import annotations from pathlib import Path from gemseo import create_design_space from gemseo import create_discipline from gemseo import create_scenario .. GENERATED FROM PYTHON SOURCE LINES 34-35 Let us consider a discipline implementing the function :math:`y=a*b` .. GENERATED FROM PYTHON SOURCE LINES 35-37 .. code-block:: Python discipline = create_discipline("AnalyticDiscipline", expressions={"y": "a*b"}) .. GENERATED FROM PYTHON SOURCE LINES 38-39 where :math:`a,b\in\{1,2,\ldots,10\}`: .. GENERATED FROM PYTHON SOURCE LINES 39-43 .. code-block:: Python design_space = create_design_space() design_space.add_variable("a", 1, design_space.DesignVariableType.INTEGER, 1, 10) design_space.add_variable("b", 1, design_space.DesignVariableType.INTEGER, 1, 10) .. GENERATED FROM PYTHON SOURCE LINES 44-46 We want to evaluate this discipline over this design space by using the input samples defined in the file "doe.txt": .. GENERATED FROM PYTHON SOURCE LINES 46-48 .. code-block:: Python print(Path("doe.txt").read_text()) .. rst-class:: sphx-glr-script-out .. code-block:: none 1,2 3,4 5,6 .. GENERATED FROM PYTHON SOURCE LINES 49-54 In this file, rows are points and columns are variables whose order must be consistent with that of the design space. In this example, we can see that the first input value is defined by :math:`a=1` and :math:`b=2`. .. GENERATED FROM PYTHON SOURCE LINES 56-59 For that, we can create a scenario and execute it with a :class:`.CustomDOE`, with the option "doe_file". We could also change the delimiter (default: ',') or skip the first rows in the file. .. GENERATED FROM PYTHON SOURCE LINES 59-64 .. code-block:: Python scenario = create_scenario( [discipline], "DisciplinaryOpt", "y", design_space, scenario_type="DOE" ) scenario.execute({"algo": "CustomDOE", "algo_options": {"doe_file": "doe.txt"}}) .. rst-class:: sphx-glr-script-out .. code-block:: none {'eval_jac': False, 'algo_options': {'doe_file': 'doe.txt'}, 'algo': 'CustomDOE'} .. GENERATED FROM PYTHON SOURCE LINES 65-68 We can display the content of the database as a :class:`.Dataset` and check the values of the output, which should be the product of :math:`a` and :math:`b`. .. GENERATED FROM PYTHON SOURCE LINES 68-71 .. code-block:: Python opt_problem = scenario.formulation.opt_problem dataset = opt_problem.to_dataset(name="custom_sampling", opt_naming=False) dataset .. raw:: html
GROUP inputs outputs
VARIABLE a b y
COMPONENT 0 0 0
0 1.0 2.0 2.0
1 3.0 4.0 12.0
2 5.0 6.0 30.0


.. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.037 seconds) .. _sphx_glr_download_examples_doe_plot_doe_from_file.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_from_file.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_doe_from_file.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_