Hdf5Storage

  • full name: tenpy.tools.cache.Hdf5Storage

  • parent module: tenpy.tools.cache

  • type: class

Inheritance Diagram

Inheritance diagram of tenpy.tools.cache.Hdf5Storage

Methods

Hdf5Storage.__init__(h5group)

Hdf5Storage.close()

Close opened files, free memory and clean up temporary files/directories.

Hdf5Storage.delete(key)

Interface for cleaning up a previously saved data from disk in subclasses.

Hdf5Storage.load(key)

Interface for loading data from disk in subclasses.

Hdf5Storage.open([filename, subgroup, mode, ...])

Create an hdf5 file and use it to initialize an Hdf5Cache.

Hdf5Storage.preload(key)

Interface for preloading data into the given dictionary into.

Hdf5Storage.save(key, value)

Interface for saving data to disk in subclasses.

Hdf5Storage.subcontainer(name)

Create another instance of the same class saving in a subdirectory/subgroup.

Class Attributes and Properties

Hdf5Storage.trivial

Whether the storage is actually kept in memory, instead of saving to disk.

class tenpy.tools.cache.Hdf5Storage(h5group)[source]

Bases: Storage

Subclass of Storage which saves long-term data on disk with h5py.

Warning

Some benchmarks that I ran when implementing this indicate that PickleStorage has a much lower overhead than the Hdf5Storage. Unless you have benchmarks indicated the opposite, I highly recommend sticking to PickleStorage.

Parameters:

h5group (Group) – The hdf5 group in which data will be saved using save_to_hdf5() under the specified keys.

trivial = False

Whether the storage is actually kept in memory, instead of saving to disk.

classmethod open(filename=None, subgroup=None, mode='w-', delete=True, tmpdir=None)[source]

Create an hdf5 file and use it to initialize an Hdf5Cache.

Parameters:
  • filename (path-like | None) – Filename of the Hdf5 file to be created. If None, create a temporary file with tempfile tools.

  • tmpdir (path-like | None) – Only used if filename is None. Used as base dir for tempfile.mkdtemp(), i.e., a temporary directory is created within this path, and inside that the hdf5 file.

  • mode (str) – Filemode for opening the Hdf5 file.

  • delete (bool) – Whether to automatically remove the corresponding file when closing the cache.

close()[source]

Close opened files, free memory and clean up temporary files/directories.

subcontainer(name)[source]

Create another instance of the same class saving in a subdirectory/subgroup.

This method allows multiple DictCache instance re-using open resources. Subcontainers will explicitly be closed when any of the parent containers (on which subcontainer() was called) is closed.

load(key)[source]

Interface for loading data from disk in subclasses.

save(key, value)[source]

Interface for saving data to disk in subclasses.

delete(key)[source]

Interface for cleaning up a previously saved data from disk in subclasses.

preload(key)[source]

Interface for preloading data into the given dictionary into.

Only overridden in ThreadedStorage for thread-parallelized pre-loading; in other cases it does nothing.