#!/usr/bin/env bash
set -euo pipefail

ROOT="${ROOT:-/root/disk_3tb/earlywarning/30072026}"
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
OUT="${OUT:-$ROOT/results/suite21_guarded_temporal_residual}"
LOG="${LOG:-$ROOT/log/suite21_guarded_temporal_residual.log}"
CACHE="${CACHE:-$ROOT/results/cross_faculty_residual_moe/cache}"
STRUCTURED="${STRUCTURED:-$ROOT/results/suite12_structured_cache}"

mkdir -p "$OUT" "$(dirname "$LOG")"
cd "$HERE"

echo "[suite21] compiling Python sources..."
python3 -m py_compile suite21_*.py train_suite21_guarded_temporal_residual.py check_suite21_environment.py

echo "[suite21] checking environment..."
python3 check_suite21_environment.py \
  --cache_dir "$CACHE" \
  --structured_cache_dir "$STRUCTURED"

echo "[suite21] starting full F1-F7 run"
echo "[suite21] results: $OUT"
echo "[suite21] log: $LOG"

python3 -u train_suite21_guarded_temporal_residual.py \
  --cache_dir "$CACHE" \
  --structured_cache_dir "$STRUCTURED" \
  --out_dir "$OUT" \
  "$@" 2>&1 | tee "$LOG"
