Design space#

In this example, we will discover the different functions of the API related to design space, which is a key element to represent the space of parameters on which a scenario will evaluate a list of disciplines.

from __future__ import annotations

from numpy import array

from gemseo import configure_logger
from gemseo import create_design_space
from gemseo import read_design_space
from gemseo import write_design_space

configure_logger()
<RootLogger root (INFO)>

Create a design space#

To create a standard DesignSpace, the API function create_design_space() can be used.

  • This function does not take any argument.

  • This function returns an empty instance of DesignSpace.

design_space = create_design_space()
design_space
Design space:
Name Lower bound Value Upper bound Type


Once built, we can add variables. E.g.

design_space.add_variable(
    "x",
    2,
    lower_bound=array([0.0] * 2),
    upper_bound=array([1.0] * 2),
    value=array([0.5] * 2),
)
design_space
Design space:
Name Lower bound Value Upper bound Type
x[0] 0 0.5 1 float
x[1] 0 0.5 1 float


Read a design space#

In presence of a design space specified in a CSV file, the API function read_design_space() can be used.

  • Its first argument is the file path of the design space. Its second argument is the list of fields available in the file and is optional.

  • By default, the design space reads these information from the file.

  • This function returns an instance of DesignSpace.

design_space.to_csv("saved_design_space.csv")
loaded_design_space = read_design_space("saved_design_space.csv")

Write a design space#

To export an instance of DesignSpace into an HDF or CSV file, the write_design_space() API function can be used:

loaded_design_space.add_variable("y", lower_bound=-1, upper_bound=3, value=0.0)
write_design_space(loaded_design_space, "saved_design_space.csv")
read_design_space("saved_design_space.csv")
Design space:
Name Lower bound Value Upper bound Type
x[0] 0 0.5 1 float
x[1] 0 0.5 1 float
y -1 0 3 float


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

Gallery generated by Sphinx-Gallery