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

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REPO="$(cd "$SCRIPT_DIR/../.." && pwd)"
IMAGE="${IMAGE:-aha-l2a-qwen3-repro:torch2.9.1-cu128}"
GPU_COUNT="$(nvidia-smi -L | wc -l)"
if [[ "$GPU_COUNT" -lt 1 ]]; then
  echo "At least one NVIDIA GPU is required." >&2
  exit 2
fi
GPU_LIST="$(seq -s, 0 $((GPU_COUNT - 1)))"

docker build -t "$IMAGE" -f "$REPO/recipe/Dockerfile" "$REPO/recipe"
docker run --rm --gpus all --ipc=host \
  --ulimit memlock=-1 --ulimit stack=67108864 \
  -e GPU_LIST="$GPU_LIST" \
  -v "$REPO:/workspace" \
  -w /workspace/recipe \
  "$IMAGE" bash scripts/eval_sweep.sh
