Note
Go to the end to download the full example code
Convert a cache to a dataset¶
In this example,
we will see how to convert a cache to a Dataset
.
from __future__ import annotations
from numpy import array
from gemseo import configure_logger
from gemseo.caches.memory_full_cache import MemoryFullCache
configure_logger()
<RootLogger root (INFO)>
Let us consider an MemoryFullCache
storing two parameters:
x with dimension 1 which is a cache input,
y with dimension 2 which is a cache output.
cache = MemoryFullCache()
cache[{"x": array([1.0])}] = ({"y": array([2.0, 3.0])}, None)
cache[{"x": array([4.0])}] = ({"y": array([5.0, 6.0])}, None)
This cache can be converted to an IODataset
using its method to_dataset()
:
dataset = cache.to_dataset("toy_cache")
dataset
The input variables belong to the input group
and the output variables to the output group.
We can avoid this categorization and simply build a Dataset
:
dataset = cache.to_dataset("toy_cache", categorize=False)
dataset
Total running time of the script: (0 minutes 0.020 seconds)