Hdf5Loader

Inheritance Diagram

Inheritance diagram of tenpy.tools.hdf5_io.Hdf5Loader

Methods

Hdf5Loader.__init__(h5group[, ignore_unknown])

Initialize self.

Hdf5Loader.find_class(module, classname)

Get the class of the qualified classname in a given python module.

Hdf5Loader.get_attr(h5gr, attr_name)

Return attribute h5gr.attrs[attr_name], if existent.

Hdf5Loader.load([path])

Load a Python object from the dataset.

Hdf5Loader.load_dataset(h5gr, type_info, subpath)

Load a h5py Dataset and convert it into the desired type.

Hdf5Loader.load_dict(h5gr, type_info, subpath)

Load a dictionary in the format according to type_info.

Hdf5Loader.load_dtype(h5gr, type_info, subpath)

Load a numpy.dtype.

Hdf5Loader.load_general_dict(h5gr, …)

Load a dictionary with general keys.

Hdf5Loader.load_hdf5exportable(h5gr, …)

Load an instance of a userdefined class.

Hdf5Loader.load_ignored(h5gr, type_info, subpath)

Ignore the group to be loaded.

Hdf5Loader.load_list(h5gr, type_info, subpath)

Load a list.

Hdf5Loader.load_none(h5gr, type_info, subpath)

Load the None object from a dataset.

Hdf5Loader.load_range(h5gr, type_info, subpath)

Load a range.

Hdf5Loader.load_set(h5gr, type_info, subpath)

Load a set.

Hdf5Loader.load_simple_dict(h5gr, type_info, …)

Load a dictionary with simple keys.

Hdf5Loader.load_tuple(h5gr, type_info, subpath)

Load a tuple.

Hdf5Loader.memorize_load(h5gr, obj)

Store objects already loaded in the memo_load.

Class Attributes and Properties

Hdf5Loader.dispatch_load

class tenpy.tools.hdf5_io.Hdf5Loader(h5group, ignore_unknown=True)[source]

Bases: object

Class to load and import object from a HDF5 file.

The intended use of this class is through load_from_hdf5(), which is simply an alias for Hdf5Loader(h5group).load(path).

It can load data exported with save_to_hdf5() or the Hdf5Saver, respectively.

The basic structure of this class is similar as the Unpickler from pickle.

See Saving to disk: input/output for a specification of what can be saved and what the resulting datastructure is.

Parameters
  • h5group (Group) – The HDF5 group (or file) where to save the data.

  • ignore_unknown (bool) – Whether to just warn (True) or raise an Error (False) if a class to be loaded is not found.

h5group

The HDF5 group (or HDF5 File) where to save the data.

Type

Group

ignore_unknown

Whether to just warn (True) or raise an Error (False) if a class to be loaded is not found.

Type

bool

dispatch_load

Mapping from a np.string_, which is one of the global REPR_* variables, to methods f of this class. The method is called as f(self, h5gr, type_info, subpath). The call to f should load and return an object obj from the h5py Group or Dataset h5gr; and memorize the loaded obj with memorize_load(). subpath is just the name of h5gr with a guaranteed '/' in the end. type_info is often the REPR_* variable of the type or some other information about the type, which allows to use a single dispatch_load function for different datatypes.

Type

dict

memo_load

A dictionary to remember all the objects which we already loaded from h5group. The dictionary key is a h5py group- or dataset id; the value is the loaded object. See memorize_load().

Type

dict

load(path=None)[source]

Load a Python object from the dataset.

See load_from_hdf5() for more details.

Parameters

path (None | str | Reference) – Path within h5group to be used for loading. Defaults to the name of h5group itself.

Returns

obj – The Python object loaded from h5group (specified by path).

Return type

object

memorize_load(h5gr, obj)[source]

Store objects already loaded in the memo_load.

This allows to avoid copies, if the same dataset appears multiple times in the hdf5 group of obj. Examples can be shared LegCharge objects or even shared Array.

To handle cyclic references correctly, this function should be called before loading data from subgroups with new calls of load().

static get_attr(h5gr, attr_name)[source]

Return attribute h5gr.attrs[attr_name], if existent.

Raises

Hdf5ImportError – If the attribute does not exist.

static find_class(module, classname)[source]

Get the class of the qualified classname in a given python module.

Imports the module.

load_none(h5gr, type_info, subpath)[source]

Load the None object from a dataset.

load_dataset(h5gr, type_info, subpath)[source]

Load a h5py Dataset and convert it into the desired type.

load_list(h5gr, type_info, subpath)[source]

Load a list.

load_set(h5gr, type_info, subpath)[source]

Load a set.

load_tuple(h5gr, type_info, subpath)[source]

Load a tuple.

load_dict(h5gr, type_info, subpath)[source]

Load a dictionary in the format according to type_info.

load_general_dict(h5gr, type_info, subpath)[source]

Load a dictionary with general keys.

load_simple_dict(h5gr, type_info, subpath)[source]

Load a dictionary with simple keys.

load_range(h5gr, type_info, subpath)[source]

Load a range.

load_dtype(h5gr, type_info, subpath)[source]

Load a numpy.dtype.

load_hdf5exportable(h5gr, type_info, subpath)[source]

Load an instance of a userdefined class.

load_ignored(h5gr, type_info, subpath)[source]

Ignore the group to be loaded.