.. 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 Click :ref:`here ` 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 32-48 .. code-block:: default from __future__ import absolute_import, division, print_function, unicode_literals from future import standard_library from numpy import array from gemseo.api import ( configure_logger, create_design_space, export_design_space, read_design_space, ) configure_logger() standard_library.install_aliases() .. GENERATED FROM PYTHON SOURCE LINES 49-57 Create a design space --------------------- To create a standard :class:`.DesignSpace`, the API function :meth:`~gemseo.api.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 57-60 .. code-block:: default design_space = create_design_space() print(design_space) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none Design Space: +------+-------------+-------+-------------+------+ | name | lower_bound | value | upper_bound | type | +------+-------------+-------+-------------+------+ +------+-------------+-------+-------------+------+ .. GENERATED FROM PYTHON SOURCE LINES 61-62 Once built, we can add variables. E.g. .. GENERATED FROM PYTHON SOURCE LINES 62-68 .. code-block:: default design_space.add_variable( "x", 2, l_b=array([0.0] * 2), u_b=array([1.0] * 2), value=array([0.5] * 2) ) print(design_space) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none Design Space: +------+-------------+-------+-------------+-------+ | name | lower_bound | value | upper_bound | type | +------+-------------+-------+-------------+-------+ | x | 0 | 0.5 | 1 | float | | x | 0 | 0.5 | 1 | float | +------+-------------+-------+-------------+-------+ .. GENERATED FROM PYTHON SOURCE LINES 69-79 Read a design space ------------------- In presence of a design space specified in a CSV file, the API function :meth:`~gemseo.api.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 79-82 .. code-block:: default design_space.export_to_txt("saved_design_space.txt") loaded_design_space = read_design_space("saved_design_space.txt") .. GENERATED FROM PYTHON SOURCE LINES 83-88 Write a design space -------------------- To export an instance of :class:`.DesignSpace` into an hdf or txt file, the :meth:`~gemseo.api.export_design_space` API function can be used: .. GENERATED FROM PYTHON SOURCE LINES 88-91 .. code-block:: default loaded_design_space.add_variable("y", l_b=-1, u_b=3, value=0.0) export_design_space(loaded_design_space, "saved_design_space.txt") print(read_design_space("saved_design_space.txt")) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none Design Space: +------+-------------+-------+-------------+-------+ | name | lower_bound | value | upper_bound | type | +------+-------------+-------+-------------+-------+ | x | 0 | 0.5 | 1 | float | | x | 0 | 0.5 | 1 | float | | y | -1 | 0 | 3 | float | +------+-------------+-------+-------------+-------+ .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.008 seconds) .. _sphx_glr_download_examples_api_plot_design_space.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_design_space.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_design_space.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_