.. 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-37 .. code-block:: default from __future__ import annotations from gemseo.datasets.optimization_dataset import OptimizationDataset .. GENERATED FROM PYTHON SOURCE LINES 38-40 First, we instantiate the :class:`.OptimizationDataset`: .. GENERATED FROM PYTHON SOURCE LINES 40-42 .. code-block:: default dataset = OptimizationDataset() .. GENERATED FROM PYTHON SOURCE LINES 43-50 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 50-55 .. code-block:: default 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 56-57 as well as another variable: .. GENERATED FROM PYTHON SOURCE LINES 57-60 .. code-block:: default dataset.add_variable("a", [[10.0], [20.0]]) print(dataset) .. rst-class:: sphx-glr-script-out .. code-block:: none 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 61-66 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 66-76 .. code-block:: default 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]]) print(dataset) .. rst-class:: sphx-glr-script-out .. code-block:: none 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 77-79 Then, we can easily access the names of the input and output variables: .. GENERATED FROM PYTHON SOURCE LINES 79-83 .. code-block:: default print(dataset.design_variable_names) print(dataset.constraint_names) print(dataset.objective_names) print(dataset.observable_names) .. rst-class:: sphx-glr-script-out .. code-block:: none ['x', 'y'] ['c'] ['f'] ['o'] .. GENERATED FROM PYTHON SOURCE LINES 84-85 and those of all variables: .. GENERATED FROM PYTHON SOURCE LINES 85-87 .. code-block:: default print(dataset.variable_names) .. rst-class:: sphx-glr-script-out .. code-block:: none ['a', 'c', 'f', 'o', 'x', 'y'] .. GENERATED FROM PYTHON SOURCE LINES 88-89 The :class:`.OptimizationDataset` provides also the number of iterations: .. GENERATED FROM PYTHON SOURCE LINES 89-90 .. code-block:: default print(dataset.n_iterations) .. rst-class:: sphx-glr-script-out .. code-block:: none 2 .. GENERATED FROM PYTHON SOURCE LINES 91-92 and the iterations: .. GENERATED FROM PYTHON SOURCE LINES 92-94 .. code-block:: default print(dataset.iterations) .. rst-class:: sphx-glr-script-out .. code-block:: none [1, 2] .. GENERATED FROM PYTHON SOURCE LINES 95-97 Lastly, we can get the design data as an :class:`.OptimizationDataset` view: .. GENERATED FROM PYTHON SOURCE LINES 97-100 .. code-block:: default print(dataset.design_dataset) .. rst-class:: sphx-glr-script-out .. code-block:: none 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-105 .. code-block:: default print(dataset.constraint_dataset) print(dataset.objective_dataset) print(dataset.observable_dataset) .. rst-class:: sphx-glr-script-out .. code-block:: none GROUP constraints VARIABLE c COMPONENT 0 1 -0.5 2 0.1 GROUP objectives VARIABLE f COMPONENT 0 1 -1.0 2 -2.0 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.070 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-python :download:`Download Python source code: plot_optimization_dataset.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_optimization_dataset.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_