|
| | Periodic_Checkpoint_Observer (Engine &engine, const std::size_t every, std::string path_pattern, const std::size_t zero_pad=6) |
| | Build a synchronous periodic checkpoint observer.
|
| |
| | Periodic_Checkpoint_Observer (Engine &engine, const std::size_t every, std::string path_pattern, Async_Checkpoint_Writer< Engine > &writer, Checkpoint_Options options={}, const std::size_t zero_pad=6) |
| | Build a periodic observer routing writes through an Async_Checkpoint_Writer.
|
| |
| template<typename Lattice > |
| void | on_step_begin (const std::size_t step, const Lattice &frame) noexcept |
| | Pre-step hook.
|
| |
| template<typename Lattice > |
| void | on_step_end (const std::size_t step, const Lattice &) |
| | Snapshot when step % every == 0.
|
| |
| const std::filesystem::path & | last_path () const noexcept |
| | Path of the most recent checkpoint scheduled by this observer.
|
| |
template<typename Engine>
class Aleph::CA::Periodic_Checkpoint_Observer< Engine >
Observer that auto-saves the engine state every every steps to a templated path.
The path pattern accepts a single {step} token which is replaced with the zero-padded step index. Snapshots are written after on_step_end, so the file always reflects the state after the step has completed.
When constructed with an Async_Checkpoint_Writer, every snapshot is forwarded to the writer's worker thread, keeping the engine's step loop free of disk I/O. Otherwise save_checkpoint is invoked synchronously.
Typical usage:
"checkpoints/run_{step}.bin");
Observer that auto-saves the engine state every every steps to a templated path.
Or, with the async writer:
"ckpt/run_{step}.bin",
writer);
Background writer pumping snapshots onto a dedicated thread.
- Precondition
- The engine reference passed to the constructor must outlive the observer.
-
The optional
Async_Checkpoint_Writer reference must outlive the observer.
-
every >= 1 (enforced by the constructor).
- Note
- This class is not thread-safe. The engine, the observer and the underlying filesystem are assumed to be driven by a single thread. Use external synchronisation if a parallel engine fires
on_step_end from multiple workers.
- Template Parameters
-
| Engine | engine type to checkpoint. |
Definition at line 1563 of file ca-checkpoint.H.
template<typename Engine >
Path of the most recent checkpoint scheduled by this observer.
Empty when no snapshot has been taken yet (e.g. because the total number of completed steps is still below every, or because on_step_end was never invoked). When the observer routes writes through Async_Checkpoint_Writer, this is the path the worker thread will (or has) written to — not a guarantee the file exists on disk; callers may need to call writer.flush() first.
- Returns
- const reference to the cached path, or an empty path when none was produced.
Definition at line 1688 of file ca-checkpoint.H.