Note
Go to the end to download the full example code
The optimisation dataset¶
The OptimizationDataset
proposes several particular group names,
namely DESIGN_GROUP
,
OBJECTIVE_GROUP
,
OBSERVABLE_GROUP
,
and CONSTRAINT_GROUP
.
This particular Dataset
is useful
to post-process an optimization history.
from __future__ import annotations
from gemseo.datasets.optimization_dataset import OptimizationDataset
First,
we instantiate the OptimizationDataset
:
dataset = OptimizationDataset()
and add some data of interest
using the methods
add_design_variable()
,
add_constraint_variable()
,
add_objective_variable()
,
and add_observable_variable()
that are based on Dataset.add_variable()
:
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]])
as well as another variable:
dataset.add_variable("a", [[10.0], [20.0]])
dataset
We could also do the same with the methods
add_design_group()
,
add_constraint_group()
,
add_objective_group()
,
and add_observable_group()
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
Then, we can easily access the names of the different input variables
dataset.design_variable_names
['x', 'y']
the names of the output variables
dataset.constraint_names, dataset.objective_names, dataset.observable_names
(['c'], ['f'], ['o'])
and the names of all variables:
dataset.variable_names
['a', 'c', 'f', 'o', 'x', 'y']
The OptimizationDataset
provides also the number of iterations:
dataset.n_iterations
2
and the iterations:
dataset.iterations
[1, 2]
Lastly,
we can get the design data as an OptimizationDataset
view:
dataset.design_dataset
and the same for the other data groups,
dataset.constraint_dataset
dataset.objective_dataset
dataset.observable_dataset
Total running time of the script: (0 minutes 0.048 seconds)