Buckets:
| """cwm3/eval/pc_joint_locked.py — eval/paired_compare_joint.py with a race-free append to the shared results/paired_compare.csv (2026-09-16, WP3 R2 controls). | |
| Same arguments as paired_compare_joint.py. The comparison runs unchanged but writes its rows to a PRIVATE file (results/tmp_pc/<tag>_<regime>_<pid>.csv); | |
| the rows are then appended to results/paired_compare.csv under an exclusive flock on results/paired_compare.csv.lock (header written only when the shared | |
| file is new). Several pairings may run in parallel (eval/run_joint_evals_r2_controls.sh, xargs -P) without interleaving partial rows in the shared CSV. | |
| Nothing about the statistics changes: the cells, bootstrap, tags and columns are paired_compare_joint's. CPU only; no openpilot DMS field. | |
| """ | |
| from __future__ import annotations | |
| import csv | |
| import fcntl | |
| import os | |
| import sys | |
| import time | |
| from pathlib import Path | |
| CWM3 = Path(__file__).resolve().parents[1] | |
| sys.path.insert(0, str(CWM3 / "eval")) | |
| import paired_compare_joint as PCJ # noqa: E402 | |
| SHARED = CWM3 / "results" / "paired_compare.csv" | |
| LOCK = CWM3 / "results" / "paired_compare.csv.lock" | |
| TMP = CWM3 / "results" / "tmp_pc" | |
| def main(): | |
| args = sys.argv[1:] | |
| tag = args[args.index("--tag") + 1] if "--tag" in args else "untagged" | |
| reg = args[args.index("--regime") + 1] if "--regime" in args else "x" | |
| TMP.mkdir(parents=True, exist_ok=True) | |
| private = TMP / f"{tag}_{reg}_{os.getpid()}.csv" | |
| if private.exists(): | |
| private.unlink() | |
| PCJ.OUT = private # the module-level path paired_compare_joint.main() appends to | |
| sys.argv = [str(CWM3 / "eval" / "paired_compare_joint.py")] + args | |
| PCJ.main() | |
| if not private.exists(): | |
| print(f"no rows written for {tag} {reg}") | |
| return | |
| with open(private, newline="") as f: | |
| rows = list(csv.DictReader(f)) | |
| t0 = time.time() | |
| with open(LOCK, "a") as lk: | |
| fcntl.flock(lk, fcntl.LOCK_EX) | |
| new = not SHARED.exists() or SHARED.stat().st_size == 0 | |
| with open(SHARED, "a", newline="") as f: | |
| w = csv.DictWriter(f, fieldnames=PCJ.COLS) | |
| if new: | |
| w.writeheader() | |
| for r in rows: | |
| w.writerow(r) | |
| f.flush() | |
| os.fsync(f.fileno()) | |
| fcntl.flock(lk, fcntl.LOCK_UN) | |
| private.unlink() | |
| print(f"locked-append {len(rows)} rows ({tag} {reg}) to {SHARED} ({time.time() - t0:.1f}s)") | |
| if __name__ == "__main__": | |
| main() | |
Xet Storage Details
- Size:
- 2.53 kB
- Xet hash:
- 91389b49458a26737065b36195fbf4f0ca6a9fd778c23a1dc646b43609a27ce3
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.