.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/doe/plot_custom_doe.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_doe_plot_custom_doe.py: Use a design of experiments from a file ======================================= .. GENERATED FROM PYTHON SOURCE LINES 26-35 .. code-block:: default from __future__ import absolute_import, division, print_function, unicode_literals from builtins import open from future import standard_library from gemseo.api import create_design_space, create_discipline, create_scenario standard_library.install_aliases() .. GENERATED FROM PYTHON SOURCE LINES 36-39 In this example, we consider a discipline implementing the function :math:`y=a+b` where :math:`a,b\in\{1,2,\ldots,10\}` and evaluate it over a design of experiments defined in a txt file: .. GENERATED FROM PYTHON SOURCE LINES 39-42 .. code-block:: default f = open("doe.txt", "r") print(f.read()) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none 1,2 3,4 5,6 .. GENERATED FROM PYTHON SOURCE LINES 43-46 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 48-49 First, we define the discipline. .. GENERATED FROM PYTHON SOURCE LINES 49-51 .. code-block:: default discipline = create_discipline("AnalyticDiscipline", expressions_dict={"y": "a*b"}) .. GENERATED FROM PYTHON SOURCE LINES 52-53 Then, we create the design space: .. GENERATED FROM PYTHON SOURCE LINES 53-57 .. code-block:: default design_space = create_design_space() design_space.add_variable("a", 1, design_space.INTEGER, 1, 10) design_space.add_variable("b", 1, design_space.INTEGER, 1, 10) .. GENERATED FROM PYTHON SOURCE LINES 58-61 Lastly, we create a scenario and execute it with a :class:`.CustomDOE`. For that, we use the file as option. We could also change the delimiter (default: ',') or skip the first rows in the file. .. GENERATED FROM PYTHON SOURCE LINES 61-66 .. code-block:: default 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 Out: .. code-block:: none {'eval_jac': False, 'algo': 'CustomDOE', 'algo_options': {'doe_file': 'doe.txt'}} .. GENERATED FROM PYTHON SOURCE LINES 67-69 We can display the content of the database as a dataframe and check the values of the output, which should be the product of :math:`a` and :math:`b`. .. GENERATED FROM PYTHON SOURCE LINES 69-72 .. code-block:: default opt_problem = scenario.formulation.opt_problem dataset = opt_problem.export_to_dataset(name="custom_sampling", opt_naming=False) print(dataset.export_to_dataframe()) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none inputs outputs a b y 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.035 seconds) .. _sphx_glr_download_examples_doe_plot_custom_doe.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_custom_doe.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_custom_doe.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_