multitask.runner.run

multitask.runner.run(
    config=None,
    *,
    task='lazy',
    dataframe=None,
    data_test=None,
    project_name='test_project',
    cache_home=None,
    plot_with_outliers=False,
    show=False,
    show_progress=False,
    dry_run=False,
    log_level=40,
    **overrides,
)

Run the MultiTask forecasting pipeline and return predictions.

Wraps the standard pipeline sequence into a single call. For the "clean" task only the cache directory is wiped and an empty DataFrame is returned. For all other tasks the full sequence

prepare_data -> detect_outliers -> impute ->
build_exogenous_features -> run

is executed and the aggregated future predictions are returned as a DataFrame.

Available tasks: "lazy", "defaults", "predict", "clean". Passing task="optuna" or task="spotoptim" raises ValueError; use the spotforecast2 sibling package for auto-tuning.

When plot_with_outliers=True the call reaches plot_with_outliers() on the BaseTask instance, which raises NotImplementedError because plotting is not available in spotforecast2-safe.

Parameters

Name Type Description Default
config Optional[PipelineConfig] A PipelineConfig-conforming object (typically ConfigMulti). When None, a fresh ConfigMulti() is constructed with default fields. Outlier bounds and aggregation agg_weights are domain-specific calibrations and must be supplied explicitly on ConfigMulti. None
task str Pipeline mode — one of "lazy", "defaults", "predict", or "clean". Defaults to "lazy". 'lazy'
dataframe Optional[pd.DataFrame] Input time-series data. Must contain a datetime column matching config.index_name and at least one numeric target column. Optional for "clean", required otherwise. None
data_test Optional[pd.DataFrame] Ground-truth DataFrame covering the prediction horizon. When supplied, populates test_actual and metrics_future in the prediction package. Optional. None
project_name str Active-dataset identifier. Sets config.data_frame_name, which drives cache-subdirectory and model-file naming. 'test_project'
cache_home Optional[str] Cache directory override. When None, the package default from get_cache_home() is used. None
plot_with_outliers bool Whether to render the optional outlier-visualisation step. Calling this will raise NotImplementedError in spotforecast2-safe; set to False (the default) to skip it. False
show bool Whether to invoke the prediction display hooks after the task runs. False
show_progress bool Whether to print progress messages during pipeline execution. False
dry_run bool Forwarded to MultiTask; only meaningful for the "clean" task. False
log_level int Logging level. Defaults to 40 (ERROR). 40
**overrides Any Forwarded to config.set_params(**overrides). Mutates the caller’s config object. {}

Returns

Name Type Description
pd.DataFrame DataFrame whose index is the forecast horizon timestamps and
pd.DataFrame whose single column "forecast" contains the aggregated
pd.DataFrame predicted values. For the "clean" task an empty DataFrame is
pd.DataFrame returned.

Raises

Name Type Description
ValueError If task is not one of the supported task names.

Examples

Run the pipeline using cached or default model parameters ("lazy" task):

import pandas as pd
import warnings
warnings.filterwarnings("ignore")
from spotforecast2_safe.multitask.runner import run
from spotforecast2_safe.configurator.config_multi import ConfigMulti
from spotforecast2_safe.data.fetch_data import fetch_data, get_package_data_home

data_home = get_package_data_home()
df = fetch_data(filename=str(data_home / "demo02.csv"))

cfg = ConfigMulti(
    train_size=pd.Timedelta(days=365),
    predict_size=24,
    imputation_method="weighted",
    use_exogenous_features=False,
)
forecast = run(cfg, task="lazy", dataframe=df, project_name="demo02")
print(forecast)
                             forecast
1975-06-18 19:00:00+00:00  257.156070
1975-06-18 20:00:00+00:00  260.514415
1975-06-18 21:00:00+00:00  252.231531
1975-06-18 22:00:00+00:00  236.053322
1975-06-18 23:00:00+00:00  218.720506
1975-06-19 00:00:00+00:00  202.678296
1975-06-19 01:00:00+00:00  203.727121
1975-06-19 02:00:00+00:00  209.192987
1975-06-19 03:00:00+00:00  229.816369
1975-06-19 04:00:00+00:00  239.978587
1975-06-19 05:00:00+00:00  238.354498
1975-06-19 06:00:00+00:00  249.300717
1975-06-19 07:00:00+00:00  246.308851
1975-06-19 08:00:00+00:00  232.155814
1975-06-19 09:00:00+00:00  231.625450
1975-06-19 10:00:00+00:00  241.429918
1975-06-19 11:00:00+00:00  242.437420
1975-06-19 12:00:00+00:00  241.005952
1975-06-19 13:00:00+00:00  245.711331
1975-06-19 14:00:00+00:00  246.732151
1975-06-19 15:00:00+00:00  258.889494
1975-06-19 16:00:00+00:00  267.417546
1975-06-19 17:00:00+00:00  274.056499
1975-06-19 18:00:00+00:00  280.208008

Remove all cached models and artefacts for a project ("clean" task). Returns an empty DataFrame:

from spotforecast2_safe.multitask.runner import run

result = run(task="clean", project_name="demo02")
print(result.empty)
[clean] Cache removed successfully: /home/runner/.spotforecast2_cache
True