File size: 3,323 Bytes
299b461
 
 
 
ba83b51
 
299b461
ba83b51
299b461
 
 
 
 
 
 
 
ba83b51
299b461
 
 
 
 
 
 
ba83b51
914310a
299b461
 
ba83b51
 
299b461
 
 
 
ba83b51
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
299b461
ba83b51
299b461
 
 
 
 
ba83b51
299b461
 
914310a
 
ba83b51
299b461
 
 
 
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
# SPDX-License-Identifier: BSD-3-Clause

"""Build the public Hugging Face dataset folder for the environment.

Writes dataset/: tasks.jsonl (one row per pinned task id, with a seed-0 example
prompt and oracle), a source snapshot, the calibration summary and the card.

Usage: python scripts/make_dataset.py --tasks a-d1,b-d2 --calibration calibration/summary_v2.json
"""

import argparse
import json
import os
import shutil

from compute_lab.server.compute_lab_environment import render_prompt
from compute_lab.server.workbench import DIFFICULTIES, FAMILIES, make_episode

ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
SOURCE_FILES = ["__init__.py", "models.py", "client.py", "openenv.yaml", "pyproject.toml", "requirements.lock.txt", "server", "scripts", "tests"]


def main():
    ap = argparse.ArgumentParser()
    ap.add_argument("--tasks", required=True, help="task ids in the submission (split=train)")
    ap.add_argument("--calibration", default=os.path.join(ROOT, "calibration", "summary_v3.json"))
    ap.add_argument("--out", default=os.path.join(ROOT, "dataset"))
    args = ap.parse_args()
    submitted = set(args.tasks.split(","))
    calibration = json.load(open(args.calibration)).get("tasks", {}) if os.path.exists(args.calibration) else {}

    shutil.rmtree(args.out, ignore_errors=True)
    os.makedirs(args.out)
    with open(os.path.join(args.out, "tasks.jsonl"), "w") as f:
        for name, family in FAMILIES.items():
            for difficulty in DIFFICULTIES:
                task_id = f"{name}-d{difficulty}"
                episode, _ = make_episode(task_id, 0)
                row = {
                    "task_id": task_id,
                    "family": name,
                    "difficulty": difficulty,
                    "domain": family.domain,
                    "summary": family.summary,
                    "tools": [t.name for t in episode.tools] + ["submit"],
                    "in_submission": task_id in submitted,
                    "split": "train" if task_id in submitted else "unused",
                    "calibration": calibration.get(task_id),
                    "example_seed": 0,
                    "example_prompt": render_prompt(episode),
                    "example_oracle": json.dumps(episode.oracle),
                }
                episode.close()
                f.write(json.dumps(row) + "\n")
    for name in SOURCE_FILES:
        src, dst = os.path.join(ROOT, name), os.path.join(args.out, "source", name)
        if os.path.isdir(src):
            shutil.copytree(src, dst, ignore=shutil.ignore_patterns("__pycache__", "raw", "*.pyc"))
        elif os.path.exists(src):
            os.makedirs(os.path.dirname(dst), exist_ok=True)
            shutil.copy(src, dst)
    if os.path.exists(args.calibration):
        shutil.copy(args.calibration, os.path.join(args.out, "calibration_summary.json"))
    shutil.copy(os.path.join(ROOT, "README.md"), os.path.join(args.out, "README.md"))
    if os.path.exists(os.path.join(ROOT, "calibration", "format_ab.json")):
        shutil.copy(os.path.join(ROOT, "calibration", "format_ab.json"), os.path.join(args.out, "format_ab.json"))
    print(f"wrote {args.out}: {len(FAMILIES) * len(DIFFICULTIES)} pinned tasks ({len(submitted)} in submission)")


if __name__ == "__main__":
    main()