File size: 1,578 Bytes
aa1df78 | 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 | """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()
|