.. 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_cache.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_cache.py: Convert a cache to a dataset ============================ In this example, we will see how to convert a cache to a :class:`.Dataset`. .. GENERATED FROM PYTHON SOURCE LINES 28-38 .. code-block:: Python from __future__ import annotations from numpy import array from gemseo import configure_logger from gemseo.caches.memory_full_cache import MemoryFullCache configure_logger() .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 39-43 Let us consider an :class:`.MemoryFullCache` storing two parameters: - x with dimension 1 which is a cache input, - y with dimension 2 which is a cache output. .. GENERATED FROM PYTHON SOURCE LINES 43-48 .. code-block:: Python 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) .. GENERATED FROM PYTHON SOURCE LINES 49-51 This cache can be converted to an :class:`.IODataset` using its method :meth:`~.MemoryFullCache.to_dataset`: .. GENERATED FROM PYTHON SOURCE LINES 51-54 .. code-block:: Python dataset = cache.to_dataset("toy_cache") dataset .. raw:: html
GROUP inputs outputs
VARIABLE x y
COMPONENT 0 0 1
0 1.0 2.0 3.0
1 4.0 5.0 6.0


.. GENERATED FROM PYTHON SOURCE LINES 55-58 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 :class:`.Dataset`: .. GENERATED FROM PYTHON SOURCE LINES 58-60 .. code-block:: Python dataset = cache.to_dataset("toy_cache", categorize=False) dataset .. raw:: html
GROUP parameters
VARIABLE x y
COMPONENT 0 0 1
0 1.0 2.0 3.0
1 4.0 5.0 6.0


.. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.020 seconds) .. _sphx_glr_download_examples_dataset_creation_plot_dataset_from_cache.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_dataset_from_cache.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_dataset_from_cache.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_