SteppingRecipeRunner
Step-by-step recipe execution with checkpointing.
Enables stepping through recipes one action at a time, with the ability to rewind to previous states and branch to create new variations.
See ADR-014 for architecture decisions.
Classes
- class SegmentationCheckpoint
A saved state of the segmentation at a specific step.
Stores the labelmap as a numpy array for fast restoration.
- Attributes:
step_index: The step index this checkpoint represents (after executing that step). labelmap_array: The segmentation labelmap as a numpy array. timestamp: When the checkpoint was created.
Methods:
- size_bytes()
Return the size of the labelmap in bytes.
- class SteppingRecipeRunner
Execute recipes step-by-step with checkpoint and rewind support.
- Usage:
runner = SteppingRecipeRunner(action_recipe)
# Set up the scene runner.setup()
# Step through the recipe while runner.step_forward():
action = runner.get_current_action() print(f”Executed step {runner.current_step}: {action.type}”)
# Rewind to step 2 runner.goto_step(2)
# Branch from here runner.start_branch() # … user performs manual actions … runner.add_manual_action(RecipeAction.paint(…)) branched_recipe = runner.save_branch()
- Attributes:
recipe: The ActionRecipe being executed. current_step: Current step index (-1 = before any steps). checkpoints: List of saved segmentation states.
Methods:
- __init__()
Initialize the stepping runner.
- total_steps()
Return total number of steps in the recipe.
- is_at_start()
Return True if at the start (before any steps).
- is_at_end()
Return True if at the end (all steps executed).
- is_branching()
Return True if currently recording a branch.
- set_step_callback()
Set callback to be called after each step.
- set_checkpoint_callback()
Set callback to be called when a checkpoint is created.
- setup()
Set up the scene for recipe execution.
- step_forward()
Execute the next step in the recipe.
- step_backward()
Rewind to the previous step by restoring checkpoint.
- goto_step()
Go to a specific step by restoring checkpoint.
- run_to_end()
Execute all remaining steps.
- get_current_action()
Get the action for the current step.
- get_next_action()
Get the action for the next step.
- start_branch()
Start recording a branch from the current step.
- stop_branch()
Stop recording the branch without saving.
- add_manual_action()
Add a manually recorded action to the branch.
- save_branch()
Save the current branch as a new ActionRecipe.
- get_checkpoint_stats()
Get statistics about stored checkpoints.
- cleanup()
Clean up resources.
Functions
- size_bytes()
Return the size of the labelmap in bytes.
- total_steps()
Return total number of steps in the recipe.
- is_at_start()
Return True if at the start (before any steps).
- is_at_end()
Return True if at the end (all steps executed).
- is_branching()
Return True if currently recording a branch.
- set_step_callback()
Set callback to be called after each step.
- Args:
callback: Function taking (step_index, action) or None to clear.
- set_checkpoint_callback()
Set callback to be called when a checkpoint is created.
- Args:
callback: Function taking (checkpoint) or None to clear.
- setup()
Set up the scene for recipe execution.
Loads sample data, creates segmentation, and activates the effect.
- Returns:
True if setup succeeded, False otherwise.
- step_forward()
Execute the next step in the recipe.
- Returns:
True if a step was executed, False if already at the end.
- step_backward()
Rewind to the previous step by restoring checkpoint.
- Returns:
True if rewound successfully, False if already at start.
- goto_step()
Go to a specific step by restoring checkpoint.
- Args:
step_index: Target step index (-1 for initial state).
- Returns:
True if successful, False otherwise.
- run_to_end()
Execute all remaining steps.
- Returns:
Number of steps executed.
- get_current_action()
Get the action for the current step.
- Returns:
The current action, or None if at start.
- get_next_action()
Get the action for the next step.
- Returns:
The next action, or None if at end.
- start_branch()
Start recording a branch from the current step.
After calling this, manual actions can be added and saved as a new recipe.
- stop_branch()
Stop recording the branch without saving.
- add_manual_action()
Add a manually recorded action to the branch.
- Args:
action: The action to add.
- save_branch()
Save the current branch as a new ActionRecipe.
- Args:
name: Name for the branched recipe. If None, auto-generated.
- Returns:
The branched ActionRecipe.
- get_checkpoint_stats()
Get statistics about stored checkpoints.
- Returns:
Dictionary with checkpoint statistics.
- cleanup()
Clean up resources.