#!/bin/bash
# Run phase1 eval on all route_comparison models.
# Output: <model_dir>/phase1_summary.json + phase1_scores.npz
#
# Usage:
#   bash artifacts/route_comparison/run_phase1_all.sh [GPU_ID]
#
# Default GPU_ID = 0. Each eval takes ~3-5 min with the caps below.

set -e
GPU_ID="${1:-0}"
ROOT=/home/chy/mambafortrafficmodeling
EVAL=${ROOT}/artifacts/verify_2026_04_24/eval_phase1_unified.py

models=(
  baseline_ciciot2023_seed42
  baseline_ciciot2023_seed43
  baseline_ciciot2023_seed44
  route_a_causal_ciciot2023_seed42
  route_a_causal_ciciot2023_seed43
  route_a_causal_ciciot2023_seed44
)

cd ${ROOT}/Unified_CFM
for name in "${models[@]}"; do
  model_dir=${ROOT}/artifacts/route_comparison/${name}
  if [ ! -f "${model_dir}/model.pt" ]; then
    echo "[skip] ${name}: model.pt missing"
    continue
  fi
  out_dir=${model_dir}
  if [ -f "${out_dir}/phase1_summary.json" ]; then
    echo "[skip] ${name}: phase1_summary.json exists"
    continue
  fi
  echo "[eval] ${name}"
  CUDA_VISIBLE_DEVICES=${GPU_ID} stdbuf -oL uv run --no-sync python -u ${EVAL} \
    --model-dir ${model_dir} --out-dir ${out_dir} \
    --batch-size 256 --n-steps 16 \
    --jacobian-n-eps 4 \
    --n-val-cap 5000 --n-atk-cap 10000 \
    2>&1 | tee ${model_dir}/phase1.log | tail -5
  echo "[done] ${name}"
done
echo "[all done]"
