RightNow-Mini / eval /instance_report.py
Jr23xd23's picture
Upload 8 files
8507a20 verified
Raw History Blame Contribute Delete
2.57 kB
"""Build a run report from the harness's per-instance reports, for a run whose own final report was not written.
python eval/instance_report.py <folder the harness ran in> <run id> <preds.json> <out.json> [--ids id1 id2 ...]
The SWE-bench harness scores each instance into logs/run_evaluation/<run id>/<model>/<instance>/report.json and then,
as its last step, lists every container on the machine to write one summary file. On a machine where hundreds of
short-lived containers of other runs come and go, that listing can fail (a container disappears between being listed
and being read) and the summary is never written. The per-instance reports are complete by then; this adds them up
the same way. An instance with a patch and no report counts as an error, to be scored again (eval/rescore.sh).
"""
import glob
import json
import sys
def main():
folder, run_id, preds_path, out = sys.argv[1:5]
only = set(sys.argv[sys.argv.index("--ids") + 1:]) if "--ids" in sys.argv else None
preds = json.load(open(preds_path))
resolved, completed, errors, empty = [], [], [], []
for iid, p in sorted(preds.items()):
if only is not None and iid not in only:
continue
if not (p.get("model_patch") or "").strip():
empty.append(iid)
continue
found = glob.glob(f"{folder}/logs/run_evaluation/{run_id}/*/{iid}/report.json")
if not found:
errors.append(iid)
continue
completed.append(iid)
try:
if json.load(open(found[0])).get(iid, {}).get("resolved"):
resolved.append(iid)
except ValueError:
completed.pop()
errors.append(iid)
n = len(resolved) + (len(completed) - len(resolved)) + len(errors) + len(empty)
report = {"built_from": "the per-instance reports (the harness's own run report was not written)",
"total_instances": n, "submitted_instances": n, "completed_instances": len(completed), "resolved_instances": len(resolved),
"unresolved_instances": len(completed) - len(resolved), "empty_patch_instances": len(empty), "error_instances": len(errors),
"completed_ids": completed, "resolved_ids": resolved, "unresolved_ids": sorted(set(completed) - set(resolved)),
"empty_patch_ids": empty, "error_ids": errors}
json.dump(report, open(out, "w"), indent=1)
print(f"built {out}: resolved {len(resolved)}, completed {len(completed)}, errors {len(errors)}, empty {len(empty)}")
if __name__ == "__main__":
main()