Note
Go to the end to download the full example code
Convert a database to a dataset¶
In this example,
we will see how to convert a Database
to a Dataset
.
from __future__ import annotations
from gemseo import execute_algo
from gemseo.problems.analytical.rosenbrock import Rosenbrock
Let us solve the Rosenbrock
optimization problem
with the SLSQP algorithm and 10 iterations:
optimization_problem = Rosenbrock()
execute_algo(optimization_problem, "SLSQP", max_iter=10)
Then,
the Database
attached to this OptimizationProblem
can be converted to an OptimizationDataset
using its method to_dataset()
:
dataset = optimization_problem.to_dataset()
dataset
The design variables and output variables are in separate groups.
You can also use an IODataset
instead of an OptimizationDataset
:
dataset = optimization_problem.to_dataset(opt_naming=False)
dataset
or simply do not separate the variables
dataset = optimization_problem.to_dataset(categorize=False)
dataset
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
add_observable()
method.
Total running time of the script: (0 minutes 0.060 seconds)