.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/dataset/creation/plot_optimization_dataset.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_dataset_creation_plot_optimization_dataset.py: The optimisation dataset ======================== The :class:`.OptimizationDataset` proposes several particular group names, namely :attr:`~.OptimizationDataset.DESIGN_GROUP`, :attr:`~.OptimizationDataset.OBJECTIVE_GROUP`, :attr:`~.OptimizationDataset.OBSERVABLE_GROUP`, :attr:`~.OptimizationDataset.CONSTRAINT_GROUP`, :attr:`~.OptimizationDataset.EQUALITY_CONSTRAINT_GROUP`, and :attr:`~.OptimizationDataset.INEQUALITY_CONSTRAINT_GROUP`. This particular :class:`.Dataset` is useful to post-process an optimization history. .. GENERATED FROM PYTHON SOURCE LINES 35-40 .. code-block:: Python from __future__ import annotations from gemseo.datasets.optimization_dataset import OptimizationDataset .. GENERATED FROM PYTHON SOURCE LINES 41-43 First, we instantiate the :class:`.OptimizationDataset`: .. GENERATED FROM PYTHON SOURCE LINES 43-45 .. code-block:: Python dataset = OptimizationDataset() .. GENERATED FROM PYTHON SOURCE LINES 46-53 and add some data of interest using the methods :meth:`~.OptimizationDataset.add_design_variable`, :meth:`~.OptimizationDataset.add_constraint_variable`, :meth:`~.OptimizationDataset.add_objective_variable`, and :meth:`~.OptimizationDataset.add_observable_variable` that are based on :meth:`.Dataset.add_variable`: .. GENERATED FROM PYTHON SOURCE LINES 53-58 .. code-block:: Python dataset.add_design_variable("x", [[1.0, 2.0], [4.0, 5.0]]) dataset.add_design_variable("z", [[3.0], [6.0]]) dataset.add_objective_variable("f", [[-1.0], [-2.0]]) dataset.add_constraint_variable("c", [[-0.5], [0.1]]) dataset.add_observable_variable("o", [[-3.0], [8.0]]) .. GENERATED FROM PYTHON SOURCE LINES 59-60 as well as another variable: .. GENERATED FROM PYTHON SOURCE LINES 60-63 .. code-block:: Python dataset.add_variable("a", [[10.0], [20.0]]) dataset .. raw:: html
GROUP designs objectives constraints observables parameters
VARIABLE x z f c o a
COMPONENT 0 1 0 0 0 0 0
1 1.0 2.0 3.0 -1.0 -0.5 -3.0 10.0
2 4.0 5.0 6.0 -2.0 0.1 8.0 20.0


.. GENERATED FROM PYTHON SOURCE LINES 64-69 We could also do the same with the methods :meth:`~.OptimizationDataset.add_design_group`, :meth:`~.OptimizationDataset.add_constraint_group`, :meth:`~.OptimizationDataset.add_objective_group`, and :meth:`~.OptimizationDataset.add_observable_group` .. GENERATED FROM PYTHON SOURCE LINES 69-79 .. code-block:: Python dataset = OptimizationDataset() dataset.add_design_group( [[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]], ["x", "y"], {"x": 2, "y": 1} ) dataset.add_objective_group([[-1.0], [-2.0]], ["f"]) dataset.add_constraint_group([[-0.5], [0.1]], ["c"]) dataset.add_observable_group([[-3.0], [8.0]], ["o"]) dataset.add_variable("a", [[10.0], [20.0]]) dataset .. raw:: html
GROUP designs objectives constraints observables parameters
VARIABLE x y f c o a
COMPONENT 0 1 0 0 0 0 0
1 1.0 2.0 3.0 -1.0 -0.5 -3.0 10.0
2 4.0 5.0 6.0 -2.0 0.1 8.0 20.0


.. GENERATED FROM PYTHON SOURCE LINES 80-82 Then, we can easily access the names of the different input variables .. GENERATED FROM PYTHON SOURCE LINES 82-83 .. code-block:: Python dataset.design_variable_names .. rst-class:: sphx-glr-script-out .. code-block:: none [np.str_('x'), np.str_('y')] .. GENERATED FROM PYTHON SOURCE LINES 84-85 the names of the output variables .. GENERATED FROM PYTHON SOURCE LINES 85-86 .. code-block:: Python dataset.constraint_names, dataset.objective_names, dataset.observable_names .. rst-class:: sphx-glr-script-out .. code-block:: none ([np.str_('c')], [np.str_('f')], [np.str_('o')]) .. GENERATED FROM PYTHON SOURCE LINES 87-88 and the names of all variables: .. GENERATED FROM PYTHON SOURCE LINES 88-90 .. code-block:: Python dataset.variable_names .. rst-class:: sphx-glr-script-out .. code-block:: none ['a', np.str_('c'), np.str_('f'), np.str_('o'), np.str_('x'), np.str_('y')] .. GENERATED FROM PYTHON SOURCE LINES 91-92 The :class:`.OptimizationDataset` provides also the number of iterations: .. GENERATED FROM PYTHON SOURCE LINES 92-93 .. code-block:: Python dataset.n_iterations .. rst-class:: sphx-glr-script-out .. code-block:: none 2 .. GENERATED FROM PYTHON SOURCE LINES 94-95 and the iterations: .. GENERATED FROM PYTHON SOURCE LINES 95-97 .. code-block:: Python dataset.iterations .. rst-class:: sphx-glr-script-out .. code-block:: none [1, 2] .. GENERATED FROM PYTHON SOURCE LINES 98-100 Lastly, we can get the design data as an :class:`.OptimizationDataset` view: .. GENERATED FROM PYTHON SOURCE LINES 100-102 .. code-block:: Python dataset.design_dataset .. raw:: html
GROUP designs
VARIABLE x y
COMPONENT 0 1 0
1 1.0 2.0 3.0
2 4.0 5.0 6.0


.. GENERATED FROM PYTHON SOURCE LINES 103-104 and the same for the other data groups, .. GENERATED FROM PYTHON SOURCE LINES 104-105 .. code-block:: Python dataset.constraint_dataset .. raw:: html
GROUP constraints
VARIABLE c
COMPONENT 0
1 -0.5
2 0.1


.. GENERATED FROM PYTHON SOURCE LINES 106-107 .. code-block:: Python dataset.objective_dataset .. raw:: html
GROUP objectives
VARIABLE f
COMPONENT 0
1 -1.0
2 -2.0


.. GENERATED FROM PYTHON SOURCE LINES 108-109 .. code-block:: Python dataset.observable_dataset .. raw:: html
GROUP observables
VARIABLE o
COMPONENT 0
1 -3.0
2 8.0


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