.. 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:`~.IODataset.DESIGN_GROUP`, :attr:`~.IODataset.OBJECTIVE_GROUP`, :attr:`~.IODataset.OBSERVABLE_GROUP`, and :attr:`~.IODataset.CONSTRAINT_GROUP`. This particular :class:`.Dataset` is useful to post-process an optimization history. .. GENERATED FROM PYTHON SOURCE LINES 33-38 .. code-block:: Python from __future__ import annotations from gemseo.datasets.optimization_dataset import OptimizationDataset .. GENERATED FROM PYTHON SOURCE LINES 39-41 First, we instantiate the :class:`.OptimizationDataset`: .. GENERATED FROM PYTHON SOURCE LINES 41-43 .. code-block:: Python dataset = OptimizationDataset() .. GENERATED FROM PYTHON SOURCE LINES 44-51 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 51-56 .. 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 57-58 as well as another variable: .. GENERATED FROM PYTHON SOURCE LINES 58-61 .. 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 62-67 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 67-77 .. 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 78-80 Then, we can easily access the names of the different input variables .. GENERATED FROM PYTHON SOURCE LINES 80-81 .. code-block:: Python dataset.design_variable_names .. rst-class:: sphx-glr-script-out .. code-block:: none ['x', 'y'] .. GENERATED FROM PYTHON SOURCE LINES 82-83 the names of the output variables .. GENERATED FROM PYTHON SOURCE LINES 83-84 .. code-block:: Python dataset.constraint_names, dataset.objective_names, dataset.observable_names .. rst-class:: sphx-glr-script-out .. code-block:: none (['c'], ['f'], ['o']) .. GENERATED FROM PYTHON SOURCE LINES 85-86 and the names of all variables: .. GENERATED FROM PYTHON SOURCE LINES 86-88 .. code-block:: Python dataset.variable_names .. rst-class:: sphx-glr-script-out .. code-block:: none ['a', 'c', 'f', 'o', 'x', 'y'] .. GENERATED FROM PYTHON SOURCE LINES 89-90 The :class:`.OptimizationDataset` provides also the number of iterations: .. GENERATED FROM PYTHON SOURCE LINES 90-91 .. code-block:: Python dataset.n_iterations .. rst-class:: sphx-glr-script-out .. code-block:: none 2 .. GENERATED FROM PYTHON SOURCE LINES 92-93 and the iterations: .. GENERATED FROM PYTHON SOURCE LINES 93-95 .. code-block:: Python dataset.iterations .. rst-class:: sphx-glr-script-out .. code-block:: none [1, 2] .. GENERATED FROM PYTHON SOURCE LINES 96-98 Lastly, we can get the design data as an :class:`.OptimizationDataset` view: .. GENERATED FROM PYTHON SOURCE LINES 98-100 .. 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 101-102 and the same for the other data groups, .. GENERATED FROM PYTHON SOURCE LINES 102-103 .. 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 104-105 .. 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 106-107 .. 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.045 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 ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_