"""Rebuild this partial v2 release from pinned v1 tasks and metadata/selection.json. Finished terminal errors score zero; raw verifier rewards are preserved in the combined traces. """ import argparse,copy,hashlib,json from pathlib import Path import pyarrow as pa,pyarrow.parquet as pq p=argparse.ArgumentParser();p.add_argument('--out',type=Path,required=True);p.add_argument('--source',type=Path);a=p.parse_args() s=json.loads((Path(__file__).parent/'metadata/selection.json').read_text()) if a.source:f=a.source else: from huggingface_hub import hf_hub_download f=Path(hf_hub_download(s['repo_id'],s['source_folder']+'/tasks.parquet',repo_type='dataset',revision=s['source_revision'])) assert hashlib.sha256(f.read_bytes()).hexdigest()==s['source_sha256'] t=pq.read_table(f);schema=t.schema.remove_metadata() for name in s['result_columns']:schema=schema.append(pa.field(name,pa.int64())) rows=[] for r in t.to_pylist(): e=s['tasks'][r['path']];assert r['content_sha256']==e['content_sha256'] if e['kept']: r.update({name:e[name] for name in s['result_columns']});rows.append(r) assert len(rows)==s['partial_refresh']['summary']['kept'] meta=dict(t.schema.metadata or {});names={r['path'] for r in rows} if b'ot.images.v1' in meta: im=json.loads(meta[b'ot.images.v1']);im['tasks']={k:v for k,v in im['tasks'].items() if k in names};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} if 'missing' in im:im['missing']=[x for x in im['missing'] if x.get('task') in names] if 'uncached_task_ids' in im:im['uncached_task_ids']=sorted(names-set(im['tasks'])) if 'coverage' in im:im['coverage']={'cached_tasks':len(im['tasks']),'total_tasks':len(names)} meta[b'ot.images.v1']=json.dumps(im).encode() meta[b'ot.release.v2']=json.dumps({k:v for k,v in s.items() if k!='tasks'}).encode() a.out.mkdir(parents=True,exist_ok=True);assert not (a.out/'tasks.parquet').exists() pq.write_table(pa.Table.from_pylist(rows,schema=schema).replace_schema_metadata(meta),a.out/'tasks.parquet',compression='zstd') print(len(rows),'retained tasks')