File size: 3,132 Bytes
6184311
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Rebuild BugsInPy v3 tasks.parquet from pinned v1/v2 payloads and metadata/selection.json.

pip install pyarrow huggingface_hub
python patch.py --out rebuilt
Optional --source-dir holds v1.parquet and v2.parquet for offline reproduction.
"""
import argparse,hashlib,json
from pathlib import Path
import pyarrow as pa
import pyarrow.parquet as pq

def build(out, source_dir=None):
    root=Path(__file__).parent
    m=json.loads((root/'metadata/selection.json').read_text())
    def source(version,revision):
        if source_dir:return source_dir/f'{version}.parquet'
        from huggingface_hub import hf_hub_download
        return Path(hf_hub_download(m['repo_id'],f'bugsinpy_{version}/tasks.parquet',repo_type='dataset',revision=revision,cache_dir=out/'.source-cache'))
    out.mkdir(parents=True,exist_ok=True)
    target=out/'tasks.parquet'
    if target.exists():raise ValueError(f'{target} already exists')
    v1=source('v1',m['evaluation_source_revision']);v2=source('v2',m['v2_revision'])
    with v1.open('rb') as f:assert hashlib.file_digest(f,'sha256').hexdigest()==m['evaluation_source_sha256']
    old=pq.ParquetFile(v2);oldrows={r['path']:r for b in old.iter_batches(batch_size=1) for r in b.to_pylist()}
    pf=pq.ParquetFile(v1);kept={t for t,e in m['tasks'].items() if e['kept']}
    schema=pa.schema([*old.schema_arrow,pa.field('qwen38_successes',pa.int64()),pa.field('qwen38_attempts',pa.int64()),pa.field('kept_from_v2',pa.bool_())])
    md=dict(old.schema_arrow.metadata or {});im=json.loads(pf.schema_arrow.metadata[b'ot.images.v1'])
    im['tasks']={t:e for t,e in im['tasks'].items() if t in kept};used={e['bundle'] for v in im['tasks'].values() for e in v['environments']};im['bundles']={k:v for k,v in im['bundles'].items() if k in used};im['missing']=[x for x in im.get('missing',[]) if x.get('task') in kept]
    md[b'ot.images.v1']=json.dumps(im).encode();md[b'ot.release.v3']=json.dumps({k:v for k,v in m.items() if k!='tasks'}).encode();schema=schema.with_metadata(md)
    count=0
    with pq.ParquetWriter(target,schema,compression='zstd') as writer:
        for b in pf.iter_batches(batch_size=1):
            row=b.to_pylist()[0];t=row['path']
            if t not in kept:continue
            e=m['tasks'][t]
            if t in oldrows:row=oldrows[t]
            else:
                assert row['content_sha256']==e['models']['qwen3.8-27b']['evaluated_content_sha256']
                row.update(instruct_successes=e['models']['qwen3-30b-instruct-2507']['solved_attempts'],thinking_successes=e['models']['qwen3-30b-thinking']['solved_attempts'],attempts_per_model=16)
            row.update(qwen38_successes=e['qwen38_successes'],qwen38_attempts=e['qwen38_attempts'],kept_from_v2=e['kept_v2'])
            writer.write_table(pa.Table.from_pylist([row],schema=schema));count+=1
    assert count==m['kept']==471 and set(oldrows)<=kept
    print(f'Wrote {count} tasks to {target}')

if __name__=='__main__':
    p=argparse.ArgumentParser(description=__doc__);p.add_argument('--out',type=Path,required=True);p.add_argument('--source-dir',type=Path);a=p.parse_args();build(a.out,a.source_dir)