Skip to main content

functions

Helpers for the model_inference step (v1), kept apart from the task body.

task.py holds the Prefect task; what the task drives lives here.

Classes​

InferenceWriter​

class InferenceWriter(    write: Callable[[pd.DataFrame], None],    *,    interval: float | None = None,    clock: Callable[[], float] = <built-in function monotonic>,):

Writes a step's predictions to the cache while the step runs.

A step can stop part way through: a background wave that outlives its time bound is cancelled at the next batch, and a batch can fail. Predictions held in memory until the step ends are lost with it, and the next run plans the same files again. So finished batches are written once the interval has passed since the last write, and the step writes whatever is left when it ends, however it ends. The interval bounds what a process that dies outright, with no chance to write on the way out, loses.

Arguments

  • write: Stores one frame of predictions. Rows are upserted, so writing in parts stores the same rows as writing once.
  • interval: Seconds between writes; zero writes after every batch. Defaults to model_inference_write_interval.
  • clock: Time source, in seconds. Injectable for testing.

Initialise the writer (see the class docstring).

Variables​

  • written : pd.DataFrame - Every prediction written so far, as one frame.

Methods​


add​

def add(self, predictions: pd.DataFrame) ‑> None:

Hold one batch's predictions, writing if the interval has passed.

Arguments

  • predictions: The batch's predictions.

write_pending​

def write_pending(self) ‑> None:

Write the predictions held since the last write, if there are any.

write_pending_on_error​

def write_pending_on_error(self) ‑> None:

Write what is held when the step is stopping on an error.

Never raises: the error that stopped the step is the one to report.