File size: 1,546 Bytes
d0b4aad
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
"""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))))