instancespace.stage_runner
A runner to run a list of stages, and a builder to attach extra stages to one.
build_stage_runner() is the entry point: given a caller-supplied, already
-ordered base schedule plus any extra/plugin stages to attach via
RunBefore/RunAfter, it produces a ready-to-use StageRunner.
An error attaching an extra stage to a base schedule.
An error during stage running.
The yielded output of running a stage.
Create new instance of AnnotatedStageOutput(stage, output)
A runner to run a list of stages.
Run all stages, yielding after every run.
Parameters
- additional_arguments (NamedTuple): The initial inputs for the first stages.
Yields
- AnnotatedStageOutput: The stage that just ran and its output.
Returns
- dict[str, Any]: All the available inputs and outputs after the last stage.
Run a single stage.
Raises an error if the prerequisite stages did not run.
Parameters
- stage (type[Stage[Any, OUT]]): The stage to run.
- **additional_arguments (Any): Inputs for the stage. If an input is missing, the runner gets it from the outputs of the stages that ran before. If the input is still missing, the stage raises an error.
Returns
- OUT: The output of the stage.
Run all stages from start to finish.
Return the entire outputs data object when finished.
Parameters
- additional_arguments (NamedTuple): The initial inputs for the first stages.
Returns
- dict[str, Any]: All the available inputs and outputs after the last stage.
Run every wave through the wave containing stop_at_stage.
Stages in one wave are unordered siblings. Running only the named sibling would leave the runner in an ambiguous half-wave state, so the complete target wave is always executed.
Parameters
- stop_at_stage (StageClass): The runner stops after the wave that contains this stage.
- initial_arguments (NamedTuple): The initial inputs for the first stages.
- **additional_arguments (Any): More inputs. The runner adds them to the initial inputs.
Returns
- dict[str, Any]: The available inputs and outputs after the target wave.
Extract a NamedTuple's fields as a set of _StageArguments.
Attach extra stages to a caller-supplied base order and build a StageRunner.
base_order is a caller-supplied list[StageScheduleElement] (a list of
"waves" - stages within the same wave are order-independent of each
other). It is taken as given, not inferred: the caller owns their own
pipeline's shape. This lets InstanceSpace hardcode its own known
7-stage order rather than have it re-derived from scratch on every
construction.
Each stage in extra_stages must declare where it attaches relative to
a stage already in base_order, via a RunBefore[X]/RunAfter[X] field
in its _inputs() NamedTuple - it is not placed by matching its
input/output types against the rest of the pipeline. It is inserted as
its own new wave immediately before/after X's wave; multiple extras
resolving to the same attachment point share that new wave.
Example:
runner = build_stage_runner(
base_order=[[PrelimStage], [SiftedStage]],
extra_stages=[MyPlugin], # MyPlugin's inputs declare RunAfter[SiftedStage]
initial_input_arguments=initial_input_arguments,
)