Download source/codedesk/build/validate.py from rca-umb/five-desks-code: direct link, hf CLI and curl.
- Browser
- Download file 1.94 kB
-
https://huggingface.co/datasets/rca-umb/five-desks-code/resolve/main/source/codedesk/build/validate.py
- Command line
-
hf download hf://datasets/rca-umb/five-desks-code/source/codedesk/build/validate.py
-
curl -L -o validate.py https://huggingface.co/datasets/rca-umb/five-desks-code/resolve/main/source/codedesk/build/validate.py
1.94 kB
| """Check every catalog mutant inside the image: the untouched workspace must fail and the original code must pass, | |
| at both levels. Writes the indices that pass to /out/valid.json. | |
| docker run --rm -e PYTHONPATH=/app -v $PWD/codedesk/build/out:/out -v $PWD/codedesk/build/validate.py:/v.py:ro \ | |
| five-desks-code:native python /v.py | |
| """ | |
| import json | |
| import random | |
| import sys | |
| from concurrent.futures import ThreadPoolExecutor | |
| from codedesk.families.bugfix import LIBS, LibBugfix, catalog | |
| def check(i_m): | |
| i, m = i_m | |
| try: | |
| for level in (1, 2): | |
| t = LibBugfix(random.Random(i), level, LIBS[m["lib"]][1], mutant=m) | |
| try: | |
| if t.grade({}) != 0.0: | |
| return i, "untouched passes" | |
| t.oracle() | |
| if t.grade({}) != 1.0: | |
| return i, f"oracle fails (level {level})" | |
| finally: | |
| t.close() | |
| return i, "ok" | |
| except Exception as exc: # generation problems count as failures | |
| return i, f"error {type(exc).__name__}: {exc}"[:200] | |
| def main(): | |
| cat = catalog() | |
| results = {} | |
| with ThreadPoolExecutor(int(sys.argv[1]) if len(sys.argv) > 1 else 4) as pool: | |
| for i, verdict in pool.map(check, list(enumerate(cat))): | |
| results[i] = verdict | |
| ok = [i for i, v in sorted(results.items()) if v == "ok"] | |
| keys = [[cat[i]["lib"], cat[i]["file"], cat[i]["line"], cat[i]["col"], cat[i]["new"]] for i in ok] | |
| bad = {} | |
| for i, v in results.items(): | |
| if v != "ok": | |
| bad.setdefault(cat[i]["lib"], []).append(v) | |
| json.dump({"ok": keys, "failures": {k: v[:5] for k, v in bad.items()}}, open("/out/valid.json", "w"), indent=1) | |
| by = {} | |
| for i in ok: | |
| by[cat[i]["lib"]] = by.get(cat[i]["lib"], 0) + 1 | |
| print(len(ok), "of", len(cat), "valid", by) | |
| print({k: len(v) for k, v in bad.items()}) | |
| if __name__ == "__main__": | |
| main() | |