jaxdem.writers.checkpoints#
Orbax checkpoint writers and loaders for simulations and RL models.
Classes
|
Base class that provides context management and shared setup for Orbax checkpointers. |
|
Restore current manifests and legacy JaxDEM schema versions 1 and 2. |
|
Thin wrapper around Orbax checkpoint restoring for jaxdem.rl.models.Model. |
|
Thin wrapper around Orbax checkpoint saving for jaxdem.rl.models.Model. |
|
Thin wrapper around Orbax checkpoint saving. |
- class jaxdem.writers.checkpoints.BaseCheckpointManager(directory: Path | str = PosixPath('checkpoints'))#
Bases:
objectBase class that provides context management and shared setup for Orbax checkpointers.
- directory: Path | str#
- checkpointer: CheckpointManager#
- class jaxdem.writers.checkpoints.CheckpointWriter(directory: Path | str = PosixPath('checkpoints'), max_to_keep: int | None = None, save_every: int = 1, clean: bool = False)#
Bases:
BaseCheckpointManagerThin wrapper around Orbax checkpoint saving.
Notes
The writer serializes custom force functions passed via
force_manager_kwby their fully-qualified module path (e.g.mypackage.forces.trap). A different script cannot restore functions defined in the top-level script (__main__). Nonportable callables are rejected at save time: force, energy, target, and callback functions must round-trip by import-path identity. Define these functions in an importable module.- max_to_keep: int | None#
Keep the last max_to_keep checkpoints. If None, keep all checkpoints.
- save_every: int#
Checkpoint interval measured in the step supplied to
save(), rather than in save calls.
- clean: bool#
If True, erase and recreate the target directory on construction. If False (the default), keep existing checkpoints in the directory, so a resumed run does not destroy earlier checkpoints.
- class jaxdem.writers.checkpoints.CheckpointLoader(directory: Path | str = PosixPath('checkpoints'))#
Bases:
BaseCheckpointManagerRestore current manifests and legacy JaxDEM schema versions 1 and 2.
Checkpoints are trusted input: restoration imports Python modules named in callable metadata, so untrusted checkpoint directories must not be loaded. Unknown schema versions are rejected rather than guessed or partially migrated.
- load(step: int | None = None, *, strict: bool = True) tuple[State, System][source]#
Restore a checkpoint.
- Parameters:
step (Optional[int]) –
If None, load the latest checkpoint.
Otherwise, load the specified step.
strict (bool, optional) – If
True(default), raise aRuntimeErrorwhen the loader cannot re-import a custom force function recorded in the checkpoint. IfFalse, skip force functions that do not load, with a warning.
- Returns:
The restored State and System.
- Return type:
- class jaxdem.writers.checkpoints.CheckpointModelWriter(directory: Path | str = PosixPath('checkpoints'), max_to_keep: int | None = None, save_every: int = 1, clean: bool = False)#
Bases:
BaseCheckpointManagerThin wrapper around Orbax checkpoint saving for jaxdem.rl.models.Model.
- max_to_keep: int | None#
Keep the last max_to_keep checkpoints. If None, keep all checkpoints.
- save_every: int#
Checkpoint interval measured in the step supplied to
save(), rather than in save calls.
- clean: bool#
If True, erase and recreate the target directory on construction. If False (the default), keep existing checkpoints in the directory, so a resumed run does not destroy earlier checkpoints.
- class jaxdem.writers.checkpoints.CheckpointModelLoader(directory: Path | str = PosixPath('checkpoints'))#
Bases:
BaseCheckpointManagerThin wrapper around Orbax checkpoint restoring for jaxdem.rl.models.Model.