Skip to content

Repository files navigation

Simulation-aware Distributed Application Development with Predictive Orchestration

This repository implements the time-series forecasting component of a simulation-aware predictive orchestration system for distributed applications. It supports training forecasting models on device metrics and running them either as one-off inference scripts or as long-lived microservices.

Setup

  • Clone the repo
git clone https://github.com/BerasiDavide/Swarmchestrate-TSforecasting.git
cd Swarmchestrate-TSforecasting
  • Setup the virtual environment with uv (sudo snap remove curl && sudo apt install curl might be needed)
# Install uv
curl -LsSf https://astral.sh/uv/install.sh | sh

# Create the venv
uv sync
  • Organize your input data as follows:
data 
└───simulator1
    │   UNC-1-Noise-Sensor-1_1min.csv
    |   ...
    └───UNC-10-Noise-Sensor-1_1min.csv

An example file is provided at data/simulator1/UNC-1-Noise-Sensor-3_1min_test.csv.

Training

  • Train a model by passing the data path, whether to use gpu (0/1), and the number of training samples:
bash scripts/train.sh "simulator1/UNC-1-Noise-Sensor-1_1min.csv" 0 10000

By default, a trained checkpoint is saved under ./checkpoints with a filename derived from the data path and prediction length (e.g. simulator1__UNC-1-Noise-Sensor-1_1min_pl128)

  • Alternatively, you can download the pre-trained checkpoints (pip install gdown might be needed)
gdown 1YnG9iZvVkeT_Etb5ouHmKLvSPnK9Uqck
unzip checkpoints.zip

Inference

  • Run inference:
model_path=./checkpoints/simulator1__UNC-1-Noise-Sensor-3_1min_pl128
input_path=./data/simulator1/UNC-1-Noise-Sensor-3_1min_test.csv
output_path=./predictions/simulator1/UNC-1-Noise-Sensor-3_1min_predictions.csv

uv run Time-Series-Library/predict.py \
  --model_path $model_path \
  --input_path $input_path \
  --output_path $output_path
  # --use_gpu

By default, the model uses the last seq_len=128 rows in input_path to predict the future pred_len=128 values of the target metric, which are then saved in output_path as a csv.

Running the forecaster as a long-lived microservice

When performing multiple predictions with the same model, we want to avoid re-loading multiple times. Instead, we can load the model once and keep it in long-lived microservice serving prediction requests.

  • Initialize a microservice for forecasting:
uv run forecaster_service.py \
  --model_path ./checkpoints/simulator1__UNC-1-Noise-Sensor-3_1min_pl128 \
  --port=8000 \ # Use different ports for different model checkpoints (8001, 8002, ...)
  # --use_gpu
  • Send a prediction request:
input_path=./data/simulator1/UNC-1-Noise-Sensor-3_1min_test.csv
output_path=./predictions/simulator1/UNC-1-Noise-Sensor-3_1min_predictions.csv
port=8000

curl -X POST "http://localhost:${port}/predict" \
  -H "Content-Type: application/json" \
  -d "{ \"input_path\": \"${input_path}\", \"output_path\": \"${output_path}\" }"

Acknowledgement

Training and inference in this repository builds upon Time-Series-Library.

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages