LEAF-Bench / leaf /code /v1.5 /v1.4 /prepare_verified.py
PeterXie666's picture
Add files using upload-large-folder tool
d0b4aad verified
Raw History Blame Contribute Delete
1.55 kB
"""Select only exact replay candidates, preserving rejected fidelity reports."""
import json
from pathlib import Path
J=Path(__file__).resolve().parent
B=J.parent
selected=json.loads((J/'selected.json').read_text())
accepted=[];rejected=[];missing=[]
for row in selected:
prefix='legacy_raw' if row['cohort']=='legacy' else 'raw'
rel=Path(row['batch'])/row['run']
candidates=[]
for root in [prefix+'_local',prefix]:
p=B/root/rel/'replay.json'
if p.exists():candidates.append((p,json.loads(p.read_text())))
passing=[(p,r) for p,r in candidates if not r.get('error') and r.get('n_mismatch')==0 and not r.get('code_diff') and not r.get('inst_diff')]
if passing:
p,r=passing[0]
target=B/('legacy_verified_raw' if row['cohort']=='legacy' else 'verified_raw')/rel
target.parent.mkdir(parents=True,exist_ok=True)
if not target.exists():target.symlink_to(p.parent,target_is_directory=True)
accepted.append(dict(row,replay_path=str(p),reports_checked=r['n_checked'],frames=sum(e['n_frames'] for e in r['episodes'])))
elif candidates:
rejected.append(dict(row,reason='no exact replay candidate',candidates=[dict(path=str(p),report=r) for p,r in candidates]))
else:missing.append(row)
assert not missing, [r['run'] for r in missing]
report=dict(accepted=accepted,rejected=rejected,missing=missing)
(J/'verified_selection.json').write_text(json.dumps(report,indent=2))
print(json.dumps(dict(accepted=len(accepted),rejected=len(rejected),missing=len(missing))))