.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/doe/algorithms/plot_doe_from_array.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_algorithms_plot_doe_from_array.py: DOE from an array ================= .. GENERATED FROM PYTHON SOURCE LINES 24-33 .. code-block:: Python from __future__ import annotations import numpy as np 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 following input samples: .. GENERATED FROM PYTHON SOURCE LINES 46-50 .. code-block:: Python sample_1 = [1.0, 2.0] sample_2 = [2.0, 3.0] samples = np.array([sample_1, sample_2]) .. GENERATED FROM PYTHON SOURCE LINES 51-53 For that, we can create a scenario and execute it with a :class:`.CustomDOE` with the setting "samples": .. GENERATED FROM PYTHON SOURCE LINES 53-62 .. code-block:: Python scenario = create_scenario( [discipline], "y", design_space, scenario_type="DOE", formulation_name="DisciplinaryOpt", ) scenario.execute(algo_name="CustomDOE", samples=samples) .. rst-class:: sphx-glr-script-out .. code-block:: none INFO - 16:25:03: *** Start DOEScenario execution *** INFO - 16:25:03: DOEScenario INFO - 16:25:03: Disciplines: AnalyticDiscipline INFO - 16:25:03: MDO formulation: DisciplinaryOpt INFO - 16:25:03: Optimization problem: INFO - 16:25:03: minimize y(a, b) INFO - 16:25:03: with respect to a, b INFO - 16:25:03: over the design space: INFO - 16:25:03: +------+-------------+-------+-------------+---------+ INFO - 16:25:03: | Name | Lower bound | Value | Upper bound | Type | INFO - 16:25:03: +------+-------------+-------+-------------+---------+ INFO - 16:25:03: | a | 1 | None | 10 | integer | INFO - 16:25:03: | b | 1 | None | 10 | integer | INFO - 16:25:03: +------+-------------+-------+-------------+---------+ INFO - 16:25:03: Solving optimization problem with algorithm CustomDOE: INFO - 16:25:03: 50%|█████ | 1/2 [00:00<00:00, 528.12 it/sec, feas=True, obj=2] INFO - 16:25:03: 100%|██████████| 2/2 [00:00<00:00, 877.38 it/sec, feas=True, obj=6] INFO - 16:25:03: Optimization result: INFO - 16:25:03: Optimizer info: INFO - 16:25:03: Status: None INFO - 16:25:03: Message: None INFO - 16:25:03: Solution: INFO - 16:25:03: Objective: 2.0 INFO - 16:25:03: Design space: INFO - 16:25:03: +------+-------------+-------+-------------+---------+ INFO - 16:25:03: | Name | Lower bound | Value | Upper bound | Type | INFO - 16:25:03: +------+-------------+-------+-------------+---------+ INFO - 16:25:03: | a | 1 | 1 | 10 | integer | INFO - 16:25:03: | b | 1 | 2 | 10 | integer | INFO - 16:25:03: +------+-------------+-------+-------------+---------+ INFO - 16:25:03: *** End DOEScenario execution (time: 0:00:00.004791) *** .. GENERATED FROM PYTHON SOURCE LINES 63-66 Note that both the formulation settings passed to :func:`.create_scenario` and the algorithm settings passed to :meth:`~.BaseDriverLibrary.execute` can be provided via a Pydantic model. For more information, see :ref:`formulation_settings` and :ref:`algorithm_settings`. .. GENERATED FROM PYTHON SOURCE LINES 68-72 Then, 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 72-75 .. code-block:: Python opt_problem = scenario.formulation.optimization_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 2 2.0
1 2 3 6.0


.. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.016 seconds) .. _sphx_glr_download_examples_doe_algorithms_plot_doe_from_array.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_array.ipynb ` .. 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-zip :download:`Download zipped: plot_doe_from_array.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_