ForecastingCallback#

class openstef_models.workflows.custom_forecasting_workflow.ForecastingCallback[source]

Bases: PredictorCallback[CustomForecastingWorkflow, VersionedTimeSeriesDataset | TimeSeriesDataset, ModelFitResult, ForecastDataset]

Base callback interface for monitoring forecasting workflow lifecycle events.

Provides hooks at key stages of the forecasting process to enable custom functionality such as logging, metrics collection, model validation, data preprocessing, and integration with monitoring systems.

All methods have default no-op implementations, so subclasses only need to override the specific events they care about.

Example

Creating a logging callback

>>> class LoggingCallback(ForecastingCallback):
...     def on_fit_start(self, pipeline, dataset):
...         print(f"Starting training with {len(dataset.data)} samples")
...
...     def on_predict_end(self, pipeline, dataset, forecasts):
...         print(f"Generated {len(forecasts.data)} forecasts")
>>>
>>> callback = LoggingCallback()
>>> workflow = CustomForecastingWorkflow(model, callbacks=callback)
on_predict_batch_start(context: WorkflowContext[CustomForecastingWorkflow], data: list[TimeSeriesDataset]) None[source]

Called before a batched prediction begins. Default no-op.

Parameters:
  • context (WorkflowContext[CustomForecastingWorkflow]) – The workflow context performing the batched prediction.

  • data (list[TimeSeriesDataset]) – Input datasets being used for the batched prediction.

  • context

  • data

Return type:

None

on_predict_batch_end(context: WorkflowContext[CustomForecastingWorkflow], data: list[TimeSeriesDataset], result: list[ForecastDataset]) None[source]

Called after a batched prediction completes. Default no-op.

Parameters:
  • context (WorkflowContext[CustomForecastingWorkflow]) – The workflow context that completed the batched prediction.

  • data (list[TimeSeriesDataset]) – Input datasets that were used for the batched prediction.

  • result (list[ForecastDataset]) – Generated forecasts, one per input.

  • context

  • data

  • result

Return type:

None