.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/dataset/creation/plot_dataset_from_optimization_problem.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_dataset_from_optimization_problem.py: Convert a database to a dataset =============================== In this example, we will see how to convert a :class:`.Database` to a :class:`.Dataset`. .. GENERATED FROM PYTHON SOURCE LINES 28-34 .. code-block:: default from __future__ import annotations from gemseo import execute_algo from gemseo.problems.analytical.rosenbrock import Rosenbrock .. GENERATED FROM PYTHON SOURCE LINES 35-37 Let us solve the :class:`.Rosenbrock` optimization problem with the SLSQP algorithm and 10 iterations: .. GENERATED FROM PYTHON SOURCE LINES 37-40 .. code-block:: default optimization_problem = Rosenbrock() execute_algo(optimization_problem, "SLSQP", max_iter=10) .. rst-class:: sphx-glr-script-out .. code-block:: none Optimization result: Design variables: [0.57066585 0.31608705] Objective function: 0.19349100516217954 Feasible solution: True .. GENERATED FROM PYTHON SOURCE LINES 41-45 Then, the :class:`.Database` attached to this :class:`.OptimizationProblem` can be converted to an :class:`.OptimizationDataset` using its method :meth:`~.OptimizationDataset.to_dataset`: .. GENERATED FROM PYTHON SOURCE LINES 45-48 .. code-block:: default dataset = optimization_problem.to_dataset() print(dataset) .. rst-class:: sphx-glr-script-out .. code-block:: none GROUP designs functions VARIABLE x rosen COMPONENT 0 1 0 1 0.000000 0.000000 1.000000 2 2.000000 0.000000 1601.000000 3 0.200000 0.000000 0.800000 4 2.000000 0.899368 962.392108 5 0.380000 0.089937 0.681024 6 1.309049 2.000000 8.297426 7 0.682846 0.712569 6.166440 8 0.449476 0.232774 0.397606 9 0.551433 0.290027 0.220957 10 0.570666 0.316087 0.193491 .. GENERATED FROM PYTHON SOURCE LINES 49-51 The design variables and output variables are in separate groups. You can also use an :class:`.IODataset` instead of an :class:`.OptimizationDataset`: .. GENERATED FROM PYTHON SOURCE LINES 51-54 .. code-block:: default dataset = optimization_problem.to_dataset(opt_naming=False) print(dataset) .. rst-class:: sphx-glr-script-out .. code-block:: none GROUP inputs outputs VARIABLE x rosen COMPONENT 0 1 0 0 0.000000 0.000000 1.000000 1 2.000000 0.000000 1601.000000 2 0.200000 0.000000 0.800000 3 2.000000 0.899368 962.392108 4 0.380000 0.089937 0.681024 5 1.309049 2.000000 8.297426 6 0.682846 0.712569 6.166440 7 0.449476 0.232774 0.397606 8 0.551433 0.290027 0.220957 9 0.570666 0.316087 0.193491 .. GENERATED FROM PYTHON SOURCE LINES 55-56 or simply do not separate the variables .. GENERATED FROM PYTHON SOURCE LINES 56-58 .. code-block:: default dataset = optimization_problem.to_dataset(categorize=False) print(dataset) .. rst-class:: sphx-glr-script-out .. code-block:: none GROUP parameters VARIABLE x rosen COMPONENT 0 1 0 0 0.000000 0.000000 1.000000 1 2.000000 0.000000 1601.000000 2 0.200000 0.000000 0.800000 3 2.000000 0.899368 962.392108 4 0.380000 0.089937 0.681024 5 1.309049 2.000000 8.297426 6 0.682846 0.712569 6.166440 7 0.449476 0.232774 0.397606 8 0.551433 0.290027 0.220957 9 0.570666 0.316087 0.193491 .. GENERATED FROM PYTHON SOURCE LINES 59-64 .. note:: Only design variables and functions (objective function, constraints) are stored in the database. If you want to store state variables, you must add them as observables before the problem is executed. Use the :func:`~.OptimizationProblem.add_observable` method. .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.060 seconds) .. _sphx_glr_download_examples_dataset_creation_plot_dataset_from_optimization_problem.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_dataset_from_optimization_problem.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_dataset_from_optimization_problem.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_