File size: 3,118 Bytes
af5b4af
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
"""Assemble the public Hugging Face dataset folder.

Writes OUT/tasks.jsonl (one task per line: id, family, domain, level, an example instruction, the calibration screen stats and whether the task is in the submission), and
OUT/source/ (the environment, tools, tests, Dockerfile). The README card is kept by hand.

Usage: python tools/make_dataset.py --screen runs/a.jsonl runs/b.jsonl --selected runs/selected.txt --out dataset
"""

import argparse
import json
import os
import random
import shutil
import sys
from collections import defaultdict

sys.path.insert(0, ".")
from terminal_desk.families import FAMILIES, all_task_ids, instance_seed, parse_task_id  # noqa: E402

SOURCE = ["terminal_desk", "tools", "tests", "Dockerfile", "openenv.yaml", "README.md", "LICENSE", "NOTICE",
          ".dockerignore", "vendor"]


def main() -> None:
    p = argparse.ArgumentParser()
    p.add_argument("--screen", required=True, nargs="+")
    p.add_argument("--selected", required=True)
    p.add_argument("--out", required=True)
    a = p.parse_args()
    stats = defaultdict(list)
    for path in a.screen:
        for line in open(path):
            r = json.loads(line)
            if "error" not in r:
                stats[r["task_id"]].append(r)
    selected = {ln.strip() for ln in open(a.selected) if ln.strip() and not ln.startswith("#")}
    with open(os.path.join(a.out, "tasks.jsonl"), "w") as fh:
        for tid in all_task_ids():
            fid, level, _ = parse_task_id(tid)
            fam = FAMILIES[fid]
            built = fam.build(level, random.Random(instance_seed(tid)))  # the fixed instance reset serves
            rs = stats.get(tid, [])
            rewards = [r["reward"] for r in rs]
            fh.write(json.dumps({
                "task_id": tid,
                "family": fid,
                "domain": fam.domain,
                "level": level,
                "title": fam.title,
                "in_submission": tid in selected,
                "screen_episodes": len(rs),
                "screen_mean_reward": round(sum(rewards) / len(rewards), 3) if rewards else None,
                "screen_full_solves": sum(1 for x in rewards if x == 1.0),
                "screen_non_json_endings": sum(1 for r in rs if r["ended"] in ("invalid_reply", "truncated", "invalid_action")),
                "screen_budget_endings": sum(1 for r in rs if r["ended"] in ("budget", "context")),
                "screen_mean_steps": round(sum(r["steps"] for r in rs) / len(rs), 2) if rs else None,
                "artifact_path": "/app/" + built.artifact.path,
                "artifact_kind": built.artifact.kind,
                "example_instruction": built.instruction,
            }) + "\n")
    src = os.path.join(a.out, "source")
    shutil.rmtree(src, ignore_errors=True)
    for name in SOURCE:
        if os.path.isdir(name):
            shutil.copytree(name, os.path.join(src, name), ignore=shutil.ignore_patterns("__pycache__", "qwen_tok"))
        else:
            shutil.copy(name, os.path.join(src, name))
    print("dataset folder ready:", a.out)


if __name__ == "__main__":
    main()