Hdf5Loader

Inheritance Diagram

Inheritance diagram of tenpy.tools.hdf5_io.Hdf5Loader

Methods

Hdf5Loader.__init__(h5group[, ...])

Hdf5Loader.get_all_hdf5_keys([h5_group])

Recursively display all keys in the given h5_group.

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_converted_to_str(h5gr, ...)

Load objects converted to string during save, in particular int > 2^64.

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_global(h5gr, type_info, subpath)

Load a global object like a class or function from its qualified name and module.

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_masked_array(h5gr, ...)

Load a masked array.

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_reduce(h5gr, type_info, subpath)

Load an object where the return values of obj.__reduce__ has been exported.

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_str(h5gr, type_info, subpath)

Load a string from a h5py Dataset.

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, exclude=None)[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.

  • exclude (list of str) – List of paths (possibly relative to h5group) for objects to be excluded from loading. References to the corresponding object are replaced by an instance of Hdf5Ignored. Of course, this might break other functions expecting correctly loaded data.

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 one of the global REPR_* variables to (unbound) 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().

get_all_hdf5_keys(h5_group=None)[source]

Recursively display all keys in the given h5_group.

static get_attr(h5gr, attr_name)[source]

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

Raises:

Hdf5ImportError – If the attribute does not exist.

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_str(h5gr, type_info, subpath)[source]

Load a string from a h5py Dataset.

load_converted_to_str(h5gr, type_info, subpath)[source]

Load objects converted to string during save, in particular int > 2^64.

load_masked_array(h5gr, type_info, subpath)[source]

Load a masked array.

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.

load_global(h5gr, type_info, subpath)[source]

Load a global object like a class or function from its qualified name and module.

load_reduce(h5gr, type_info, subpath)[source]

Load an object where the return values of obj.__reduce__ has been exported.