sequince.checkpoint#

Attributes#

Classes#

CheckpointWriter

Base class for persisting committed SMC checkpoints.

StepState

Checkpoint state associated with one configured SMC step.

SMCCheckpoint

Detached end-of-iteration state for resuming an SMC run.

HDF5CheckpointWriter

Persist committed SMC checkpoints to HDF5 at a fixed cadence.

PickleCheckpointWriter

Atomically persist committed SMC checkpoints as pickle files.

Functions#

capture_step_states(steps)

Capture mutable state from a configured step pipeline.

restore_steps(steps, states)

Restore step state after validating pipeline identity and order.

Module Contents#

sequince.checkpoint.CHECKPOINT_VERSION = 1#
class sequince.checkpoint.CheckpointWriter(*, every=1, save_rng=True)[source]#

Bases: abc.ABC

Base class for persisting committed SMC checkpoints.

Parameters:
requires_detached_checkpoint = True#

Whether the writer may retain the checkpoint after write returns.

every = 1#
save_rng = True#
is_due(next_iteration)[source]#

Return whether a checkpoint is due after this iteration.

Parameters:

next_iteration (int)

Return type:

bool

write(checkpoint)[source]#

Apply this writer’s options and persist the checkpoint.

Parameters:

checkpoint (SMCCheckpoint)

Return type:

None

class sequince.checkpoint.StepState[source]#

Checkpoint state associated with one configured SMC step.

index: int#
module: str#
qualname: str#
state: dict[str, Any]#
classmethod from_step(index, step)[source]#
Parameters:
  • index (int)

  • step (Any)

Return type:

StepState

to_dict()[source]#
Return type:

dict[str, Any]

classmethod from_dict(payload)[source]#
Parameters:

payload (collections.abc.Mapping[str, Any])

Return type:

StepState

sequince.checkpoint.capture_step_states(steps)[source]#

Capture mutable state from a configured step pipeline.

Parameters:

steps (collections.abc.Sequence[Any])

Return type:

tuple[StepState, …]

sequince.checkpoint.restore_steps(steps, states)[source]#

Restore step state after validating pipeline identity and order.

Parameters:
Return type:

None

class sequince.checkpoint.SMCCheckpoint[source]#

Detached end-of-iteration state for resuming an SMC run.

states: tuple[sequince.state.ParticleState, ...]#
next_iteration: int#
next_observation_index: int#
metadata: dict[str, Any]#
outputs: tuple[tuple[Any, ...], ...]#
step_states: tuple[StepState, ...]#
evaluation_counts: sequince.target.EvaluationCounts#
rng_state: dict[str, Any] | None = None#
observation: Any = None#
initial_state: sequince.state.ParticleState | None = None#
version: int = 1#
property state: sequince.state.ParticleState#

Return the current state represented by this checkpoint.

Return type:

sequince.state.ParticleState

classmethod from_runtime(state, context, result, steps, rng=None, *, detach=True)[source]#

Capture a checkpoint after a completed SMC iteration.

Parameters:
Return type:

SMCCheckpoint

to_dict()[source]#

Return a detached plain-Python checkpoint representation.

Return type:

dict[str, Any]

classmethod from_dict(payload, *, copy_values=True)[source]#

Reconstruct a checkpoint from to_dict() output.

Parameters:
Return type:

SMCCheckpoint

restore_rng()[source]#

Return a live ORNG generator restored from this checkpoint.

Return type:

Any | None

result(shared_context=None)[source]#

Return the result states represented by this checkpoint.

Parameters:

shared_context (collections.abc.Mapping[str, Any] | None)

Return type:

sequince.result.SMCResult

save_pickle(file_path, protocol=None)[source]#

Save this checkpoint as a versioned pickle payload.

Parameters:
Return type:

None

classmethod load_pickle(file_path)[source]#

Load a trusted checkpoint from a pickle file.

Parameters:

file_path (str | pathlib.Path)

Return type:

SMCCheckpoint

save_hdf5(h5_file, path='checkpoint', dsetname='runtime', protocol=None, *, replace_states=False)[source]#

Append states and commit their count with the runtime payload.

Interrupted writes leave the previous runtime readable. This protects against incomplete writes in a readable HDF5 file, not file corruption.

Parameters:
  • path (str)

  • dsetname (str)

  • protocol (int | None)

  • replace_states (bool)

Return type:

None

classmethod load_hdf5(h5_file, path='checkpoint', dsetname='runtime')[source]#

Load a checkpoint from its recursive HDF5 representation.

Parameters:
Return type:

SMCCheckpoint

class sequince.checkpoint.HDF5CheckpointWriter(file_path, *, every=1, path='checkpoint', dsetname='runtime', save_rng=True)[source]#

Bases: CheckpointWriter

Persist committed SMC checkpoints to HDF5 at a fixed cadence.

Parameters:
requires_detached_checkpoint = False#

Whether the writer may retain the checkpoint after write returns.

file_path#
path = 'checkpoint'#
dsetname = 'runtime'#
class sequince.checkpoint.PickleCheckpointWriter(file_path, *, every=1, save_rng=True, protocol=None)[source]#

Bases: CheckpointWriter

Atomically persist committed SMC checkpoints as pickle files.

Parameters:
requires_detached_checkpoint = False#

Whether the writer may retain the checkpoint after write returns.

file_path#
protocol = None#