"""Sweep driver for the Retracted Evidence attribution test (paper App. C.3). Usage: python run_evidence.py --out results/evidence.jsonl [--seeds 0 1 2] Sweeps (one factor at a time, P=4, C=2, 4 workers, 3 seeds): L sweep: L in {3,4,6,8} (A=2, F=2) A sweep: A in {1,2,4} (L=4, F=2) F sweep: F in {1,2,4} (L=4, A=2) Treatments: attribution vs no_attribution. """ import argparse import json import os import sys import threading from concurrent.futures import ThreadPoolExecutor, as_completed sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) from agent import make_client, Usage # noqa: E402 from evidence import run_condition # noqa: E402 LOCK = threading.Lock() def main(): ap = argparse.ArgumentParser() ap.add_argument("--out", default="results/evidence.jsonl") ap.add_argument("--seeds", type=int, nargs="+", default=[0, 1, 2]) ap.add_argument("--concurrency", type=int, default=4) ap.add_argument("--root", default="runs") args = ap.parse_args() os.makedirs(os.path.dirname(args.out) or ".", exist_ok=True) client = make_client() usage = Usage() conditions = [] for L in [3, 4, 6, 8]: conditions += [(L, 2, 2, t, s) for t in ("attribution", "no_attribution") for s in args.seeds] for A in [1, 2, 4]: conditions += [(4, A, 2, t, s) for t in ("attribution", "no_attribution") for s in args.seeds] for F in [1, 2, 4]: conditions += [(4, 2, F, t, s) for t in ("attribution", "no_attribution") for s in args.seeds] conditions = sorted(set(conditions)) print(f"{len(conditions)} condition-runs, concurrency {args.concurrency}", flush=True) def one(c): L, A, F, t, s = c try: res = run_condition(client, args.root, s, L, A, F, t, usage=usage) res["status"] = "ok" except Exception as e: res = {"task": "evidence", "L": L, "A": A, "F": F, "treatment": t, "seed": s, "status": "error", "error": repr(e)} with LOCK: with open(args.out, "a") as f: f.write(json.dumps(res) + "\n") print(f"done {c} -> {res.get('status')} " f"frac={res.get('fraction_read')}", flush=True) return res with ThreadPoolExecutor(max_workers=args.concurrency) as ex: futs = [ex.submit(one, c) for c in conditions] for f in as_completed(futs): f.result() print(json.dumps({"prompt_tokens": usage.prompt_tokens, "completion_tokens": usage.completion_tokens, "llm_calls": usage.calls}), flush=True) if __name__ == "__main__": main()