"""Run the experiment grid: main models, ablation, or a named subset. Usage: python scripts/run_experiments.py --grid main # all 11 main configs python scripts/run_experiments.py --grid ablation # A1-A5 + full python scripts/run_experiments.py --only xgboost resnet50 # named subset python scripts/run_experiments.py --grid main --device cuda Each config runs the full 15-evaluation CV (3 seeds x 5 folds); OOF predictions and per-run metrics land in results//. Idempotent: skips configs whose summary.json already exists unless --force. """ from __future__ import annotations import argparse import sys import traceback from pathlib import Path ROOT = Path(__file__).resolve().parents[1] sys.path.insert(0, str(ROOT / "src")) from trifuse.experiments import main_grid, ablation_grid from trifuse.eval.runner import run_experiment, RESULTS def main() -> None: ap = argparse.ArgumentParser() ap.add_argument("--grid", choices=["main", "ablation"], default=None) ap.add_argument("--only", nargs="+", default=None, help="run only these config names") ap.add_argument("--device", default="cuda") ap.add_argument("--force", action="store_true", help="rerun even if summary.json exists") a = ap.parse_args() configs = [] if a.grid == "main": configs += main_grid() if a.grid == "ablation": configs += ablation_grid() if not a.grid: configs = main_grid() + ablation_grid() if a.only: configs = [c for c in configs if c.name in set(a.only)] if not configs: sys.exit("no configs selected") print(f"running {len(configs)} configs: {[c.name for c in configs]}", flush=True) for cfg in configs: done = (RESULTS / cfg.name / "summary.json").exists() if done and not a.force: print(f"[skip] {cfg.name} (summary.json exists)", flush=True) continue print(f"\n===== {cfg.name} ({cfg.model}, {cfg.modality}) =====", flush=True) try: run_experiment(cfg, device=a.device) except Exception: # noqa: BLE001 - keep the grid going, log the failure print(f"[FAIL] {cfg.name}:\n{traceback.format_exc()}", flush=True) if __name__ == "__main__": main()