DesignSpace import and export from disk

In this example, we will see how to read, filter, and export a design space from the disk.

from __future__ import annotations

from gemseo.api import configure_logger
from gemseo.api import export_design_space
from gemseo.api import read_design_space

configure_logger()
<RootLogger root (INFO)>

Read a design space from a file

The user can read a design space from a file using the create_design_space() function.

design_space = read_design_space("design_space.txt")
print(design_space)
Design space:
+------+-------------+-------+-------------+---------+
| name | lower_bound | value | upper_bound | type    |
+------+-------------+-------+-------------+---------+
| x1   |      -1     |   0   |      1      | float   |
| x2   |      5      |   6   |      8      | float   |
| x    |      2      |   3   |      5      | integer |
+------+-------------+-------+-------------+---------+

Filtering the design space

The user can filter the design space in order to only keep some variables. To do so, the user can use the DesignSpace.filter() method:

design_space.filter(["x1", "x2"])
print(design_space)
Design space:
+------+-------------+-------+-------------+-------+
| name | lower_bound | value | upper_bound | type  |
+------+-------------+-------+-------------+-------+
| x1   |      -1     |   0   |      1      | float |
| x2   |      5      |   6   |      8      | float |
+------+-------------+-------+-------------+-------+

Export the design space

The user can export a DesignSpace instance by using the export_design_space() function.

export_design_space(design_space, "new_design_space.txt")

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

Gallery generated by Sphinx-Gallery