babylon.engine.history.auto_checkpoint
Auto-checkpointing for the History Stack system.
This module provides: - AutoCheckpointer: A stateful class managing periodic checkpoint creation - create_checkpointed_step: A wrapper for integrating checkpoints with game loop
The checkpointing system follows the Observer pattern: - The game loop (step function) remains pure - The AutoCheckpointer observes state changes and creates checkpoints as side effects
Sprint D: Auto-checkpointing for Phase 3 persistence layer.
Functions
|
Create a wrapper function that checkpoints after each step. |
Classes
|
Stateful checkpoint manager for automatic periodic saves. |
- class babylon.engine.history.auto_checkpoint.AutoCheckpointer(config, base_dir=None)[source]
Bases:
objectStateful checkpoint manager for automatic periodic saves.
AutoCheckpointer integrates with the game loop to create checkpoints at configurable intervals without modifying the pure step function.
- Parameters:
config (CheckpointConfig)
base_dir (Path | None)
- config
The CheckpointConfig controlling behavior.
- checkpoint_dir
The directory where checkpoints are saved.
- __init__(config, base_dir=None)[source]
Initialize the auto-checkpointer.
- Parameters:
config (
CheckpointConfig) – Configuration for checkpointing behavior.base_dir (
Path|None) – Base directory for checkpoint storage. Defaults to current dir.
- Return type:
None
- on_step(state, sim_config)[source]
Check if a checkpoint should be created after a step.
Called after each simulation step. Creates a checkpoint if: - Auto-checkpointing is enabled - The current tick is a multiple of the interval (including 0)
- Parameters:
state (
WorldState) – The current WorldState after the step.sim_config (
SimulationConfig) – The SimulationConfig in use.
- Return type:
- Returns:
Path to the created checkpoint, or None if no checkpoint was created.
- force_checkpoint(state, sim_config, description='')[source]
Force creation of a checkpoint regardless of interval.
Useful for manual saves or important milestones.
- Parameters:
state (
WorldState) – The WorldState to checkpoint.sim_config (
SimulationConfig) – The SimulationConfig to include.description (
str) – Optional description for the checkpoint.
- Return type:
- Returns:
Path to the created checkpoint.
- babylon.engine.history.auto_checkpoint.create_checkpointed_step(sim_config, checkpointer)[source]
Create a wrapper function that checkpoints after each step.
This enables integration of checkpointing with the pure game loop without modifying the step function itself.
- Usage:
checkpointer = AutoCheckpointer(checkpoint_config) checkpointed_step = create_checkpointed_step(sim_config, checkpointer)
- for _ in range(100):
state, checkpoint_path = checkpointed_step(state) # checkpoint_path is None unless a checkpoint was created
- Parameters:
sim_config (
SimulationConfig) – The SimulationConfig for checkpoints.checkpointer (
AutoCheckpointer) – The AutoCheckpointer instance.
- Return type:
Callable[[WorldState],tuple[WorldState,Path|None]]- Returns:
A callable that takes WorldState and returns (WorldState, Path | None).