RightNow-Mini / train /make_task_states.py
Jr23xd23's picture
Upload 13 files
aa1df78 verified
Raw History Blame Contribute Delete
1.58 kB
"""Write, for every pool task, what its container needs to reach the task's buggy state without the network.
python train/make_task_states.py train/pool/pool_instances.json /data/train/mini/pool_patches
A SWE-smith task is the repository with one bug put in and the tests that catch it taken out. Its official form is a
branch on GitHub, which a container must fetch. While the data center's network was down that fetch failed, so the
state is rebuilt from the dataset itself:
<id>.diff the bug itself (the dataset's `patch` is the change that puts the bug in), applied to the clean repository
<id>.rm the test files that catch the bug (from FAIL_TO_PASS), removed so the agent cannot read them
The grading still uses the official branch (train/grade.sh), so a patch only counts if it fixes the real task.
"""
import ast
import json
import os
import sys
def main():
inst, out = json.load(open(sys.argv[1])), sys.argv[2]
os.makedirs(out, exist_ok=True)
for x in inst:
i = x["instance_id"]
patch = x["patch"]
open(f"{out}/{i}.diff", "w", encoding="utf-8", newline="\n").write(patch if patch.endswith("\n") else patch + "\n")
f2p = x["FAIL_TO_PASS"]
f2p = ast.literal_eval(f2p) if isinstance(f2p, str) else list(f2p)
files = sorted({t.split("::")[0] for t in f2p if t.split("::")[0].endswith(".py")})
open(f"{out}/{i}.rm", "w", encoding="utf-8", newline="\n").write("".join(f + "\n" for f in files))
print(f"{len(inst)} task states written to {out}")
if __name__ == "__main__":
main()