tasks.task_safe_demo

tasks.task_safe_demo

Task demo: compare baseline, covariate, and custom LightGBM forecasts against ground truth.

This script executes the baseline N-to-1 task, the covariate-enhanced N-to-1 pipeline, and a custom LightGBM model with optimized hyperparameters, then loads the ground truth from a specified data directory. Logging Mechanism: This script uses a dual-handler logging system designed for safety-critical MLOps:

Examples

# These are shell commands; they cannot run inside a Python kernel.
# Run with default settings (force training):
#   uv run spotforecast-safe-demo
# Skip training (use cached models if available):
#   uv run spotforecast-safe-demo --force_train false
# Specify a custom data path:
#   uv run spotforecast-safe-demo --data_path /path/to/data.csv
# Enable logging:
#   uv run spotforecast-safe-demo --logging true

Functions

Name Description
main Main execution entry point.

main

tasks.task_safe_demo.main(
    force_train=True,
    data_path=None,
    logging_enabled=False,
)

Main execution entry point. Returns 0 on success, non-zero on failure.

Examples

from pathlib import Path
from spotforecast2_safe.tasks.task_safe_demo import main

# Fail-fast path: when the ground truth file does not exist,
# main() returns 1 immediately without attempting any training.
result = main(
    force_train=False,
    data_path=Path("/nonexistent/path/data.csv"),
    logging_enabled=False,
)
print(f"Return code (missing data): {result}")
assert result == 1, f"Expected 1, got {result}"
Return code (missing data): 1