.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/doe/plot_doe_from_array.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_doe_from_array.py: Use a design of experiments from an array ========================================= .. GENERATED FROM PYTHON SOURCE LINES 24-31 .. code-block:: default from __future__ import annotations import numpy as np from gemseo.api import create_design_space from gemseo.api import create_discipline from gemseo.api import create_scenario .. GENERATED FROM PYTHON SOURCE LINES 32-33 Let us consider a discipline implementing the function :math:`y=a*b` .. GENERATED FROM PYTHON SOURCE LINES 33-35 .. code-block:: default discipline = create_discipline("AnalyticDiscipline", expressions={"y": "a*b"}) .. GENERATED FROM PYTHON SOURCE LINES 36-37 where :math:`a,b\in\{1,2,\ldots,10\}`: .. GENERATED FROM PYTHON SOURCE LINES 37-41 .. 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 42-44 We want to evaluate this discipline over this design space by using the following input samples: .. GENERATED FROM PYTHON SOURCE LINES 44-48 .. code-block:: default sample_1 = [1.0, 2.0] sample_2 = [2.0, 3.0] samples = np.array([sample_1, sample_2]) .. GENERATED FROM PYTHON SOURCE LINES 49-51 For that, we can create a scenario and execute it with a :class:`.CustomDOE` with the option "samples": .. GENERATED FROM PYTHON SOURCE LINES 51-56 .. code-block:: default scenario = create_scenario( [discipline], "DisciplinaryOpt", "y", design_space, scenario_type="DOE" ) scenario.execute({"algo": "CustomDOE", "algo_options": {"samples": samples}}) .. rst-class:: sphx-glr-script-out .. code-block:: none {'eval_jac': False, 'algo': 'CustomDOE', 'algo_options': {'samples': array([[1., 2.], [2., 3.]])}} .. GENERATED FROM PYTHON SOURCE LINES 57-61 Then, 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 61-64 .. 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 .. code-block:: none inputs outputs a b y 0 0 0 0 1.0 2.0 2.0 1 2.0 3.0 6.0 .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.035 seconds) .. _sphx_glr_download_examples_doe_plot_doe_from_array.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_doe_from_array.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_doe_from_array.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_