.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/api/plot_design_space.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_api_plot_design_space.py: 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. .. GENERATED FROM PYTHON SOURCE LINES 30-43 .. code-block:: Python 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() .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 44-52 Create a design space --------------------- To create a standard :class:`.DesignSpace`, the API function :func:`.create_design_space` can be used. - This function does not take any argument. - This function returns an empty instance of :class:`.DesignSpace`. .. GENERATED FROM PYTHON SOURCE LINES 52-55 .. code-block:: Python design_space = create_design_space() design_space .. raw:: html
Design space:
Name Lower bound Value Upper bound Type


.. GENERATED FROM PYTHON SOURCE LINES 56-57 Once built, we can add variables. E.g. .. GENERATED FROM PYTHON SOURCE LINES 57-63 .. code-block:: Python design_space.add_variable( "x", 2, l_b=array([0.0] * 2), u_b=array([1.0] * 2), value=array([0.5] * 2) ) design_space .. raw:: html
Design space:
Name Lower bound Value Upper bound Type
x[0] 0 0.5 1 float
x[1] 0 0.5 1 float


.. GENERATED FROM PYTHON SOURCE LINES 64-74 Read a design space ------------------- In presence of a design space specified in a CSV file, the API function :func:`.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 :class:`.DesignSpace`. .. GENERATED FROM PYTHON SOURCE LINES 74-77 .. code-block:: Python design_space.to_csv("saved_design_space.csv") loaded_design_space = read_design_space("saved_design_space.csv") .. GENERATED FROM PYTHON SOURCE LINES 78-83 Write a design space -------------------- To export an instance of :class:`.DesignSpace` into an HDF or CSV file, the :func:`.write_design_space` API function can be used: .. GENERATED FROM PYTHON SOURCE LINES 83-86 .. code-block:: Python loaded_design_space.add_variable("y", l_b=-1, u_b=3, value=0.0) write_design_space(loaded_design_space, "saved_design_space.csv") read_design_space("saved_design_space.csv") .. raw:: html
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


.. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.009 seconds) .. _sphx_glr_download_examples_api_plot_design_space.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_design_space.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_design_space.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_