.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/design_space/plot_create_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_design_space_plot_create_design_space.py: DesignSpace creation and manipulation ===================================== In this example, we will see how to create and how to manipulate an instance of :class:`.DesignSpace`. .. GENERATED FROM PYTHON SOURCE LINES 30-41 .. 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 configure_logger() standard_library.install_aliases() .. GENERATED FROM PYTHON SOURCE LINES 42-47 Create a parameter space ------------------------ The user can create an instance of the :class:`.DesignSpace` using the API and the :func:`.create_design_space` function. .. GENERATED FROM PYTHON SOURCE LINES 47-52 .. code-block:: default design_space = create_design_space() .. GENERATED FROM PYTHON SOURCE LINES 53-61 Add design variables -------------------- The user can add new design variables using the :meth:`.DesignSpace.add_variable`. In the following example, we add the `x` variable in the design space. We also define the lower and upper bound of the variable. It is then possible to plot the :class:`.DesignSpace` instance either using a print statement or by using the logger. .. GENERATED FROM PYTHON SOURCE LINES 61-66 .. code-block:: default design_space.add_variable("x", l_b=array([-2.0]), u_b=array([2.0]), value=array([0.0])) print(design_space) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none Design Space: +------+-------------+-------+-------------+-------+ | name | lower_bound | value | upper_bound | type | +------+-------------+-------+-------------+-------+ | x | -2 | 0 | 2 | float | +------+-------------+-------+-------------+-------+ .. GENERATED FROM PYTHON SOURCE LINES 67-69 The user can also add design variables with dimension greater than one. To do that, the user can use the `size` keyword: .. GENERATED FROM PYTHON SOURCE LINES 69-75 .. code-block:: default design_space.add_variable( "y", l_b=array([-2.0, -1.0]), u_b=array([2.0, 1.0]), value=array([0.0, 0.0]), size=2 ) print(design_space) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none Design Space: +------+-------------+-------+-------------+-------+ | name | lower_bound | value | upper_bound | type | +------+-------------+-------+-------------+-------+ | x | -2 | 0 | 2 | float | | y | -2 | 0 | 2 | float | | y | -1 | 0 | 1 | float | +------+-------------+-------+-------------+-------+ .. GENERATED FROM PYTHON SOURCE LINES 76-81 Remove design variables ----------------------- The user can also remove a variable in the design space using the :meth:`.DesignSpace.remove_variable` method: .. GENERATED FROM PYTHON SOURCE LINES 81-84 .. code-block:: default design_space.remove_variable("x") print(design_space) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none Design Space: +------+-------------+-------+-------------+-------+ | name | lower_bound | value | upper_bound | type | +------+-------------+-------+-------------+-------+ | y | -2 | 0 | 2 | float | | y | -1 | 0 | 1 | float | +------+-------------+-------+-------------+-------+ .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.004 seconds) .. _sphx_glr_download_examples_design_space_plot_create_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_create_design_space.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_create_design_space.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_