qimpy.io.Checkpoint
- class Checkpoint(filename, *, writable=False, rotate=True)
Bases:
FileHelper for checkpoint load/save from HDF5 files.
- Parameters:
filename (str)
writable (bool)
rotate (bool)
- __init__(filename, *, writable=False, rotate=True)
Open a HDF5 checkpoint file filename for read or write based on writable.
In write mode, if rotate (the default), the file is first written to filename + ‘.part’ and then rotated into filename upon closing (with a previously existing filename moved into filename + ‘.bak’). This prevents corruption of the checkpoint if the job is terminated due to time limit while the checkpoint is being written.
- Parameters:
filename (str)
writable (bool)
rotate (bool)
- Return type:
None
Methods
Open a HDF5 checkpoint file filename for read or write based on writable.
build_virtual_datasetAssemble a virtual dataset in this group.
clearD.clear() -> None.
Close the file, and perform rotations if applicable.
copyCopy an object or group.
create_datasetCreate a new HDF5 dataset
Create a dataset at path suitable for a complex array of size shape.
create_dataset_likeCreate a dataset similar to other.
Create a dataset at path suitable for a real array of size shape.
create_groupCreate and return a new subgroup.
create_virtual_datasetCreate a new virtual dataset in this group.
flushTell the HDF5 library to flush its buffers.
getRetrieve an item or other information.
in_memoryCreate an HDF5 file in memory, without an underlying file
itemsGet a view object on member items
keysGet a view object on member names
moveMove a link to a new location in the file.
popD.pop(k[,d]) -> v, remove specified key and return the corresponding value.
popitemD.popitem() -> (k, v), remove and return some (key, value) pair as a 2-tuple; but raise KeyError if D is empty.
Read a slice of data from data set dset in file, starting at offset and of length size in each dimension.
Same as
read_slice(), but for complex data.require_datasetOpen a dataset, creating it if it doesn't exist.
require_groupReturn a group, creating it if it doesn't exist.
setdefaultD.setdefault(k[,d]) -> D.get(k,d), also set D[k]=d if k not in D
updateD.update([E, ]**F) -> None.
valuesGet a view object on member objects
visitRecursively visit all names in this group and subgroups.
visit_linksRecursively visit all names in this group and subgroups.
visititemsRecursively visit names and objects in this group.
visititems_linksRecursively visit links in this group.
Write a slice of data to dataset dset at offset offset from data (taking care of transfer to CPU if needed).
Same as
write_slice(), but for complex data.Attributes
attrsAttributes attached to this object
driverLow-level HDF5 file driver used to open file
fileReturn a File instance associated with this object
filenameFile name on disk
idLow-level identifier appropriate for this object
libverlow, high)
meta_block_sizeMeta block size (in bytes)
modePython mode used to open file
nameReturn the full name of this object.
parentReturn the parent group of this object.
refAn (opaque) HDF5 reference to this object
regionrefCreate a region reference (Datasets only).
swmr_modeControls single-writer multiple-reader mode
userblock_sizeUser block size (in bytes)
Whether file has been opened for writing
If non-empty, move to this filename upon closing
- close()
Close the file, and perform rotations if applicable.
- create_dataset_complex(path, shape, dtype=torch.complex128)
Create a dataset at path suitable for a complex array of size shape. This creates a real array with a final dimension of length 2. This format is used by
write_slice_complex()andread_slice_complex().- Parameters:
path (str)
shape (tuple[int, ...])
dtype (dtype)
- Return type:
Any
- create_dataset_real(path, shape, dtype=torch.float64)
Create a dataset at path suitable for a real array of size shape. Additionally, dtype is translated from torch to numpy for convenience.
- Parameters:
path (str)
shape (tuple[int, ...])
dtype (dtype)
- Return type:
Any
- read_slice(dset, offset, size)
Read a slice of data from data set dset in file, starting at offset and of length size in each dimension. Returns data on CPU or GPU as specified by qimpy.rc.device.
- Parameters:
dset (Any)
offset (tuple[int, ...])
size (tuple[int, ...])
- Return type:
Tensor
- read_slice_complex(dset, offset, size)
Same as
read_slice(), but for complex data. Converts data from real storage as created bycreate_dataset_complex()to a complex tensor on output.- Parameters:
dset (Any)
offset (tuple[int, ...])
size (tuple[int, ...])
- Return type:
Tensor
- write_slice(dset, offset, data)
Write a slice of data to dataset dset at offset offset from data (taking care of transfer to CPU if needed). Note that all of data is written, so pass in the slice to be written from current process. This may be called from any subset of MPI processes independently, as no metadata modification such as dataset creation is done here.
- Parameters:
dset (Any)
offset (tuple[int, ...])
data (Tensor)
- Return type:
None
- write_slice_complex(dset, offset, data)
Same as
write_slice(), but for complex data. Converts data to real storage compatible withcreate_dataset_complex()- Parameters:
dset (Any)
offset (tuple[int, ...])
data (Tensor)
- Return type:
None
- filename_move: str
If non-empty, move to this filename upon closing
- writable: bool
Whether file has been opened for writing