Hdf5Saver
full name: tenpy.tools.hdf5_io.Hdf5Saver
parent module:
tenpy.tools.hdf5_io
type: class
Inheritance Diagram
Methods
|
|
|
Create an HDF5 group |
|
Store objects already saved in the |
|
Save obj in |
|
Save obj as a hdf5 dataset; in dispatch table. |
|
Save the dictionary obj; in dispatch table. |
|
Save contents of a dictionary obj in the existing h5gr. |
|
Save a |
|
Save a global object like a function or class. |
|
Don't save the Hdf5Ignored object; just return None. |
|
Save an iterable obj like a list, tuple or set; in dispatch table. |
|
Save contents of an iterable obj in the existing h5gr. |
|
Save a (numpy) masked array. |
|
Save the None object as a string (dataset); in dispatch table. |
|
Save a range object; in dispatch table. |
|
Save the return values of |
Class Attributes and Properties
- class tenpy.tools.hdf5_io.Hdf5Saver(h5group, format_selection=None)[source]
Bases:
object
Class to save simple enough objects into a HDF5 file.
The intended use of this class is through
save_to_hdf5()
, which is simply an alias forHdf5Saver(h5group).save(obj, path)
.It exports python objects to a HDF5 file such that they can be loaded with the
Hdf5Loader
, or a call toload_from_hdf5()
, respectively.The basic structure of this class is similar as the Pickler 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 HDF5File
) where to save the data.format_selection (dict) – This dictionary allows to set a output format selection for user-defined
Hdf5Exportable.save_hdf5()
implementations. For example,LegCharge
checks it for the key"LegCharge"
.
- h5group
The HDF5 group (or HDF5
File
) where to save the data.- Type:
Group
- dispatch_save
Mapping from a type keytype to methods f of this class. The method is called as
f(self, obj, path, type_repr)
. The call to f should save the object obj inself.h5group[path]
, callmemorize_save()
, and seth5gr.attr[ATTR_TYPE] = type_repr
to a string type_repr in order to allow loading with the dispatcher inHdf5Loader.dispatch_save[type_repr]
.- Type:
- memo_save
A dictionary to remember all the objects which we already stored to
h5group
. The dictionary key is the object id; the value is a two-tuple of the hdf5 group or dataset where an object was stored, and the object itself. Seememorize_save()
.- Type:
- format_selection
This dictionary allows to set a output format selection for user-defined
Hdf5Exportable.save_hdf5()
implementations. For example,LegCharge
checks it for the key"LegCharge"
.- Type:
- save(obj, path='/')[source]
Save obj in
self.h5group[path]
.- Parameters:
- Returns:
h5gr – The h5py group or dataset in which obj was saved.
- Return type:
Group
|Dataset
- create_group_for_obj(path, obj)[source]
Create an HDF5 group
self.h5group[path]
to store obj.Also handle ending of path with
'/'
, and memorize obj inmemo_save
.- Parameters:
- Returns:
h5group (
Group
) – Newly created h5py (sub)groupself.h5group[path]
, unless path is'/'
, in which case it is simply the existingself.h5group['/']
.subpath (str) – The group.name ending with
'/'
, such that other names can be appended to get the path for subgroups or datasets in the group.
:raises ValueError : if self.h5group[path]` already existed and path is not
'/'
.:
- memorize_save(h5gr, obj)[source]
Store objects already saved in the
memo_save
.This allows to avoid copies, if the same python object appears multiple times in the data of obj. Examples can be shared
LegCharge
objects or even sharedArray
. Using the memo also avoids crashes from cyclic references, e.g., when a list contains a reference to itself.- Parameters:
h5gr (
Group
|Dataset
) – The h5py group or dataset in which obj was saved.obj (
object
) – The object saved.
- save_reduce(func, args, state=None, listitems=None, dictitems=None, state_setter=None, obj=None, path=None)[source]
Save the return values of
obj.__reduce__
following the pickle protocol.
- save_none(obj, path, type_repr)[source]
Save the None object as a string (dataset); in dispatch table.
- save_iterable(obj, path, type_repr)[source]
Save an iterable obj like a list, tuple or set; in dispatch table.
- save_iterable_content(obj, h5gr, subpath)[source]
Save contents of an iterable obj in the existing h5gr.
- save_dict_content(obj, h5gr, subpath)[source]
Save contents of a dictionary obj in the existing h5gr.
The format depends on whether the dictionary obj has simple keys valid for hdf5 path components (see
valid_hdf5_path_component()
) or not. For simple keys: directly use the keys as path. For non-simple keys: save list of keys und"keys"
and list of values und"values"
.- Parameters:
- Returns:
type_repr – Indicates whether the data was saved in the format for a dictionary with simple keys or general keys, see comment above.
- Return type:
REPR_DICT_SIMPLE | REPR_DICT_GENERAL
- t
alias of
StringDType
- t2
alias of
_PyComplexDType