Skip to content

loqs.internal.checkpointstore

Durable checkpoint storage for streamed, int-keyed dict attributes.

A store holds entries keyed by an integer (a shot or item index). Each entry carries one value per streamed attribute. Entries live in a canonical HDF5 file and, until consolidated, in atomically written per-worker payload files. CheckpointStore is the durable implementation and MemoryCheckpointStore is an in-memory twin with the same interface.

Classes

Attributes

Name Type Value Doc
COMMIT_MARKER_ATTR 'checkpoint_store_committed' Name of the file-root attribute holding the committed lengths.
NEXT_CACHE_ID_ATTR 'checkpoint_store_next_cache_id' Name of the int file-root attribute of a canonical file holding the next free encode cache ID. Every cache ID in the file is below it.
SHOT_LAYOUT StoreLayout('results.h5', 'checkpoint', 'shots', (StreamedAttr('shot_histories', False), StreamedAttr('shot_wall_clock_times', True)), 'parent_program') Shot-level layout, as ProgramResults checkpoints today. Shot payloads reference the parent program stored in the canonical file.
ITEM_LAYOUT StoreLayout('runner.h5', 'runner', 'item', (StreamedAttr('results', False, '_reduced_results'), StreamedAttr('item_wall_clock_times', True), StreamedAttr('shot_wall_clock_times', False), StreamedAttr('_program_results', False))) Item-level layout, as MultiProgramRunner checkpoints today.

Functions

atomic_h5_file

atomic_h5_file(path: str | PathLike) -> Iterator[h5py.File]

Write an HDF5 file atomically.

Opens <path>.tmp in mode "w" and yields it. On a normal exit the file is closed and renamed onto path. On any BaseException the file is closed, the temp file is removed and the exception propagates.

Windows can't replace a file that a handle holds open, so a caller holding a handle on path closes it inside the block.


open_h5

open_h5(path: str | PathLike, mode: str) -> h5py.File

Open an HDF5 file, retrying only on BlockingIOError.

Lock contention is retried up to 5 attempts in all, waiting delay + random.uniform(0, delay) with delay = 0.01 * 2**attempt. The last BlockingIOError is re-raised. Any other error propagates at once.


raise_if_uncommitted

raise_if_uncommitted(f: File) -> None

Raise CheckpointReadError if a canonical file holds entries past its commit marker. A file with no marker passes.