"""Validate a READ-Bench submission before opening a PR. Checks the submission folder is well-formed and (optionally) re-runs the official harness to verify the reported numbers. Run:: python validate_submission.py --submission submissions/my-method # structure only python validate_submission.py --submission submissions/my-method --run # + recompute scores Exits non-zero on any failure, so it doubles as a CI gate. """ from __future__ import annotations import argparse import json import sys from pathlib import Path REQUIRED_FILES = ["method.py", "metadata.yaml", "requirements.txt"] REQUIRED_META = ["name", "slug", "family", "supervision"] FAMILIES = {"Raw-window distance", "Symbolic", "FM embedder", "Fusion", "Reranker", "Supervised", "Other"} SUPERVISION = {"label-free", "neighbour-labels", "supervised"} def _fail(msg: str) -> None: print(f" ✗ {msg}") def _ok(msg: str) -> None: print(f" ✓ {msg}") def validate(submission: Path, run: bool, token: str = None) -> bool: import yaml print(f"Validating {submission}") ok = True for f in REQUIRED_FILES: if (submission / f).exists(): _ok(f"{f} present") else: _fail(f"missing {f}") ok = False meta = {} if (submission / "metadata.yaml").exists(): meta = yaml.safe_load((submission / "metadata.yaml").read_text()) or {} for key in REQUIRED_META: if meta.get(key): _ok(f"metadata.{key} = {meta[key]!r}") else: _fail(f"metadata.{key} missing/empty") ok = False if meta.get("family") and meta["family"] not in FAMILIES: _fail(f"family must be one of {sorted(FAMILIES)}") ok = False if meta.get("supervision") and meta["supervision"] not in SUPERVISION: _fail(f"supervision must be one of {sorted(SUPERVISION)}") ok = False # method.py must import and expose rank(query, corpus). try: from eval_submission import load_method load_method(submission) _ok("method.py exposes rank(query, corpus)") except Exception as exc: # noqa: BLE001 _fail(f"method.py not loadable: {type(exc).__name__}: {exc}") ok = False if run and ok: print("Running official harness (this downloads the dataset)…") try: from eval_submission import evaluate results = evaluate(submission, token=token) out = submission / "results.json" out.write_text(json.dumps(results, indent=2)) h = results["headline"] _ok(f"scored NDCG@10 rho0/10/20 = " f"{h['rho0']:.4f}/{h['rho10']:.4f}/{h['rho20']:.4f} -> {out.name}") except Exception as exc: # noqa: BLE001 _fail(f"harness failed: {type(exc).__name__}: {exc}") ok = False print("PASS ✅" if ok else "FAIL ❌") return ok def main(argv=None) -> None: p = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) p.add_argument("--submission", required=True, type=Path) p.add_argument("--run", action="store_true", help="also recompute scores via the harness") p.add_argument("--token", default=None) args = p.parse_args(argv) sys.exit(0 if validate(args.submission, args.run, args.token) else 1) if __name__ == "__main__": main()