.. 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 :ref:`Go to the end ` 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 28-39 .. code-block:: Python from __future__ import annotations from numpy import array from gemseo import configure_logger from gemseo import create_design_space configure_logger() .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 40-45 Create a design space --------------------- The user can create an instance of the :class:`.DesignSpace` using the high-level function :func:`.create_design_space`. .. GENERATED FROM PYTHON SOURCE LINES 45-47 .. code-block:: Python design_space = create_design_space() .. GENERATED FROM PYTHON SOURCE LINES 48-56 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 56-59 .. code-block:: Python design_space.add_variable("x", l_b=array([-2.0]), u_b=array([2.0]), value=array([0.0])) design_space .. raw:: html
Design space:
Name Lower bound Value Upper bound Type
x -2 0 2 float


.. GENERATED FROM PYTHON SOURCE LINES 60-62 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 62-67 .. code-block:: Python 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 ) design_space .. raw:: html
Design space:
Name Lower bound Value Upper bound Type
x -2 0 2 float
y[0] -2 0 2 float
y[1] -1 0 1 float


.. GENERATED FROM PYTHON SOURCE LINES 68-70 By default, each variable infers its type from the given values. One may also specify it with the `var_type` keyword .. GENERATED FROM PYTHON SOURCE LINES 70-88 .. code-block:: Python design_space.add_variable( "z", l_b=array([0, -1]), u_b=array([3, 1]), value=array([0, 1]), size=2, var_type="integer", ) design_space.add_variable( "w", l_b=array([-2, -5]), u_b=array([3, 1]), value=array([2, -2]), size=2, var_type=["integer", "integer"], ) design_space .. raw:: html
Design space:
Name Lower bound Value Upper bound Type
x -2 0 2 float
y[0] -2 0 2 float
y[1] -1 0 1 float
z[0] 0 0 3 integer
z[1] -1 1 1 integer
w[0] -2 2 3 integer
w[1] -5 -2 1 integer


.. GENERATED FROM PYTHON SOURCE LINES 89-103 .. note:: Some optimization algorithms may not handle integer variables properly. For updated information about the optimization algorithms that handle integer variables, refer to :ref:`gen_opt_algos`. For additional information on how |g| handles integer variables, refer to :ref:`nutshell_design_space`. 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 103-105 .. code-block:: Python design_space.remove_variable("x") design_space .. raw:: html
Design space:
Name Lower bound Value Upper bound Type
y[0] -2 0 2 float
y[1] -1 0 1 float
z[0] 0 0 3 integer
z[1] -1 1 1 integer
w[0] -2 2 3 integer
w[1] -5 -2 1 integer


.. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.006 seconds) .. _sphx_glr_download_examples_design_space_plot_create_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_create_design_space.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_create_design_space.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_