qimpy.io.CheckpointPath

class CheckpointPath(checkpoint=None, path='')

Bases: NamedTuple

Combination of optional checkpoint and path within it. Useful as construction parameter for objects, to load data from checkpoint when available.

Parameters:
__init__()

Methods

__init__

count

Return number of occurrences of value.

create_dataset

Create dataset with name within current checkpoint path.

index

Return first index of value.

member

Member name at path within checkpoint, if present.

override

Read var_name from checkpoint, optionally overridden by var.

read

Read entire dataset from name, reporting to log if report.

read_optional

Handle optional dataset with read, returning None if not found.

read_str

Read fixed-length byte string from checkpoint as a regular string.

relative

Create CpPath with path relative to current one.

write

Write data available on all processes to name within current path.

write_str

Write string str available on all processes to name within current path.

Attributes

attrs

Access attributes at path within checkpoint.

checkpoint

Checkpoint, if available.

path

Path within checkpoint

create_dataset(name, shape, dtype, **kwargs)

Create dataset with name within current checkpoint path.

Parameters:
  • name (str)

  • shape (Sequence[int])

  • dtype (dtype)

Return type:

Any

member(name)

Member name at path within checkpoint, if present. Otherwise, return an empty CpPath.

Parameters:

name (str)

Return type:

CheckpointPath

override(var_name, var, overridable=False)

Read var_name from checkpoint, optionally overridden by var. If not overrideable, raise error if var is not a default.

Parameters:
  • var_name (str)

  • var (T | Default[T])

  • overridable (bool)

Return type:

T

read(name, report=True)

Read entire dataset from name, reporting to log if report.

Parameters:
  • name (str)

  • report (bool)

Return type:

Tensor

read_optional(name, report=True)

Handle optional dataset with read, returning None if not found.

Parameters:
  • name (str)

  • report (bool)

Return type:

Tensor | None

read_str(name)

Read fixed-length byte string from checkpoint as a regular string.

Parameters:

name (str)

Return type:

str

relative(relative_path)

Create CpPath with path relative to current one. Specifically, relative_path is the path of the result relative to self.path.

Parameters:

relative_path (str)

Return type:

CheckpointPath

write(name, data)

Write data available on all processes to name within current path. This is convenient for small tensors that are not split over MPI. For complex data, pass a real view that has a final dimension of length 2. Returns name, which is convenient for accumulating the names of written datasets during reporting.

Parameters:
  • name (str)

  • data (Tensor)

Return type:

str

write_str(name, data)

Write string str available on all processes to name within current path. Data is written as a fixed-length byte string to support parallel access. Returns name, which is convenient for accumulating the names of written datasets during reporting.

Parameters:
  • name (str)

  • data (str)

Return type:

str

property attrs

Access attributes at path within checkpoint.

checkpoint: Checkpoint | None

Checkpoint, if available.

path: str

Path within checkpoint