Use a design of experiments from a file

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


In this example, we consider a discipline implementing the function \(y=a+b\) where \(a,b\in\{1,2,\ldots,10\}\) and evaluate it over a design of experiments defined in a txt file:

f = open("doe.txt", "r")



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 \(a=1\) and \(b=2\).

First, we define the discipline.

discipline = create_discipline("AnalyticDiscipline", expressions_dict={"y": "a*b"})

Then, we create the design space:

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)

Lastly, we create a scenario and execute it with a CustomDOE. For that, we use the file as option. We could also change the delimiter (default: ‘,’) or skip the first rows in the file.

scenario = create_scenario(
    [discipline], "DisciplinaryOpt", "y", design_space, scenario_type="DOE"
scenario.execute({"algo": "CustomDOE", "algo_options": {"doe_file": "doe.txt"}})


{'eval_jac': False, 'algo': 'CustomDOE', 'algo_options': {'doe_file': 'doe.txt'}}

We can display the content of the database as a dataframe and check the values of the output, which should be the product of \(a\) and \(b\).

opt_problem = scenario.formulation.opt_problem
dataset = opt_problem.export_to_dataset(name="custom_sampling", opt_naming=False)


  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

Total running time of the script: ( 0 minutes 0.035 seconds)

Gallery generated by Sphinx-Gallery