File size: 3,214 Bytes
a8a6794
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import hashlib
import json
from pathlib import Path
import sys

J=Path(__file__).resolve().parent
B=J.parent
group=sys.argv[1]
root=B/('legacy_dataset' if group=='legacy' else 'dataset')
old=Path('/mnt/cpfs/shared/datasets/lffbench_agent_replays/v1.3')
def rows(p,n):return [json.loads(s) for s in (p/'lff'/n).read_text().splitlines()]
def digest(p):return hashlib.sha256(p.read_bytes()).hexdigest()
eps=rows(root,'episodes.jsonl');runs=rows(root,'runs.jsonl')
accepted=[r for r in json.loads((J/'verified_selection.json').read_text())['accepted'] if r['cohort']==group]
paths={r['run']:Path(r['path']) for r in accepted}
new_eps=[e for e in eps if e['run'] in paths]
assert {r['run'] for r in runs if r['run'] in paths}==set(paths)
old_eps=rows(old,'episodes.jsonl') if group=='current' else []
assert len(runs)==len(accepted)+(len(rows(old,'runs.jsonl')) if group=='current' else 0)
for e,n in zip(old_eps,eps):
    for field in ['episode_index','dataset_from_index','dataset_to_index','length','attempts','success','task','seed','run']:
        assert e[field]==n[field],(e['episode_index'],field)
    f=Path('lff/sim_state')/f"episode_{e['episode_index']:06d}.npy"
    assert digest(old/f)==digest(root/f)
snapshot=json.loads((J/'snapshot.json').read_text())
for p,h in snapshot['inputs'].items():assert digest(Path(p))==h,p
for p,h in snapshot['source_files'].items():assert digest(J/p)==h,p
for p,h in snapshot['export_pipeline_sha256'].items():assert digest(J/p)==h,p
expected={}
for run,p in paths.items():
    for line in (p/'events.jsonl').read_text().splitlines():
        e=json.loads(line)
        if e.get('ev')=='done':expected[(run,int(e['attempt']))]=e['success']
actual={}
for e in new_eps:
    ann=json.loads((root/'lff/annotations'/f"episode_{e['episode_index']:06d}.json").read_text())
    h=json.loads((paths[e['run']]/'harness.json').read_text())
    assert ann['agent']['harness']==h['harness']
    assert ann['agent']['model']==h['model']
    assert ann['agent']['framework_config']==h.get('config')
    assert ann['source']['simulator_cohort']==('legacy_uncapped_elbow' if group=='legacy' else 'current_capped_elbow')
    for attempt,success in zip(e['attempts'],e['success']):
        k=e['run'],attempt
        assert k not in actual
        actual[k]=success
assert actual==expected
info=json.loads((root/'meta/info.json').read_text())
assert info['total_episodes']==len(eps)
assert info['total_frames']==sum(e['length'] for e in eps)
report=dict(status='pass',cohort=group,preserved_parent_episodes=len(old_eps),added_runs=len(paths),
            added_episodes=len(new_eps),added_frames=sum(e['length'] for e in new_eps),added_attempts=len(actual),
            added_success=sum(s is True for s in actual.values()),added_failure=sum(s is False for s in actual.values()),
            total_runs=len(runs),total_episodes=len(eps),total_frames=info['total_frames'],
            total_attempts=sum(len(e['attempts']) for e in eps),
            total_success=sum(s is True for e in eps for s in e['success']),
            total_failure=sum(s is False for e in eps for s in e['success']))
(J/f'{group}_release_audit.json').write_text(json.dumps(report,indent=2))
print(json.dumps(report))