Hdf5Exportable

Inheritance Diagram

Inheritance diagram of tenpy.tools.hdf5_io.Hdf5Exportable

Methods

Hdf5Exportable.__init__()

Hdf5Exportable.from_hdf5(hdf5_loader, h5gr, ...)

Load instance from a HDF5 file.

Hdf5Exportable.save_hdf5(hdf5_saver, h5gr, ...)

Export self into a HDF5 file.

class tenpy.tools.hdf5_io.Hdf5Exportable[source]

Bases: object

Interface specification for a class to be exportable to our HDF5 format.

To allow a class to be exported to HDF5 with save_to_hdf5(), it only needs to implement the save_hdf5() method as documented below. To allow import, a class should implement the classmethod from_hdf5(). During the import, the class already needs to be defined; loading can only initialize instances, not define classes.

The implementation given works for sufficiently simple (sub-)classes, for which all data is stored in __dict__. In particular, this works for python-defined classes which simply store data using self.data = data in their methods.

save_hdf5(hdf5_saver, h5gr, subpath)[source]

Export self into a HDF5 file.

This method saves all the data it needs to reconstruct self with from_hdf5().

This implementation saves the content of __dict__ with save_dict_content(), storing the format under the attribute 'format'.

Parameters:
  • hdf5_saver (Hdf5Saver) – Instance of the saving engine.

  • h5gr (:class`Group`) – HDF5 group which is supposed to represent self.

  • subpath (str) – The name of h5gr with a '/' in the end.

classmethod from_hdf5(hdf5_loader, h5gr, subpath)[source]

Load instance from a HDF5 file.

This method reconstructs a class instance from the data saved with save_hdf5().

Parameters:
  • hdf5_loader (Hdf5Loader) – Instance of the loading engine.

  • h5gr (Group) – HDF5 group which is represent the object to be constructed.

  • subpath (str) – The name of h5gr with a '/' in the end.

Returns:

obj – Newly generated class instance containing the required data.

Return type:

cls