Skip to content

utils.checkpoint.CheckpointSession

Import path: earth2studio.utils.checkpoint.CheckpointSession

View source on GitHub

Documentation

Active checkpoint row or new checkpoint session.

A session is the context-bound handle used by workflows and components to restore bound state, record completed restart boundaries, and commit new checkpoint rows. Sessions created from Checkpoint.select restore an existing catalog row; sessions opened by with checkpoint on an empty catalog create the first row for the checkpoint.

Parameters:

  • catalog (Checkpoint) –

    Checkpoint catalog that owns this session.

  • entry (CheckpointEntry | None, default: None ) –

    Existing catalog row to restore. If None, the session starts as a new write target, by default None.

exists property

exists: bool

Whether this session resolves to an existing checkpoint row.

is_active property

is_active: bool

Whether this checkpoint session is active in the current context.

commit_id property

commit_id: str | None

Selected commit identifier, if one exists.

lead_time property

lead_time: Any | None

Forecast lead time metadata, when present.

device property

device: device

Device used for live checkpoint state tensors.

metadata property

metadata: dict[str, Any]

Load metadata recorded for the selected checkpoint row.

artifacts property

artifacts: dict[str, Any]

Compatibility alias for checkpoint metadata.

metadata_value

metadata_value(name: str) -> Any

Load one metadata value by name.

artifact

artifact(name: str) -> Any

Compatibility alias for metadata_value.

bind

bind(
    state: T | CheckpointState[T],
) -> CheckpointState[T]

Bind and restore a dataclass state object.

write

write(**metadata: Any) -> CheckpointEntry | None

Record a safe restart boundary for the active session.

write increments the session write count and stores the latest checkpoint metadata. If the parent checkpoint's flush_interval is reached, the pending update is committed to disk; otherwise it remains in memory until a later write or flush.

Returns:

  • CheckpointEntry | None –

    The committed catalog entry when this call triggers a flush; otherwise None.

flush

flush(**metadata: Any) -> CheckpointEntry | None

Commit the current session state to the checkpoint catalog.

flush writes an atomic commit directory containing the manifest, bound component state, and checkpoint metadata, then updates the catalog row for this session. If no write is pending and no metadata overrides are supplied, no commit is created.

Returns:

  • CheckpointEntry | None –

    The committed catalog entry, or None when there was nothing new to commit.