#!/usr/bin/env bash # Score one agent pass with the official SWE-bench harness, version 4.0.4 (the benchmark's own tests, in its own images). # LABEL=stock-1 bash eval/score.sh # An instance of the subset with no prediction or an empty patch counts as not resolved: the score is always out of N. set -u R=/data/train/mini LABEL=${LABEL:?give LABEL}; OUT=${OUT:-$R/results/agent/$LABEL}; EW=${EW:-24} SUBSET=${SUBSET:-$R/src/eval/subset.json} cd "$OUT" || exit 1 echo "== $LABEL scoring start $(date -u +%FT%TZ)" | tee -a meta.txt rm -f "instances.$LABEL.json" sudo -n env PATH=$R/venv-smith/bin:/usr/bin:/bin HF_HOME=$R/hf $R/venv-smith/bin/python -m swebench.harness.run_evaluation \ --dataset_name princeton-nlp/SWE-bench_Verified --split test --predictions_path "$OUT/preds.json" --run_id "$LABEL" \ --max_workers "$EW" --namespace swebench --report_dir "$OUT" > score.log 2>&1 sudo -n chown -R "$USER":"$USER" "$OUT" $R/hf 2>/dev/null # The harness's last step can fail on a busy machine and leave no run report (see eval/instance_report.py); the # per-instance reports are complete by then and are added up instead. ls ./*."$LABEL".json >/dev/null 2>&1 || $R/venv/bin/python $R/src/eval/instance_report.py "$OUT" "$LABEL" "$OUT/preds.json" "instances.$LABEL.json" >> score.log 2>&1 echo "== $LABEL scoring done $(date -u +%FT%TZ)" | tee -a meta.txt $R/venv/bin/python - "$OUT" "$SUBSET" "$LABEL" <<'EOF' import glob, json, sys out, subset, label = sys.argv[1:4] ids = json.load(open(subset))["instance_ids"] reports = [f for f in glob.glob(out + f"/*.{label}.json")] if not reports: print("NO REPORT FILE; see score.log"); sys.exit(1) r = json.load(open(reports[0])) resolved = sorted(set(r.get("resolved_ids", [])) & set(ids)) summary = {"label": label, "subset_n": len(ids), "resolved": len(resolved), "score_pct": round(100 * len(resolved) / len(ids), 1), "submitted": r.get("submitted_instances"), "completed": r.get("completed_instances"), "empty_patch": r.get("empty_patch_instances"), "error": r.get("error_instances"), "unresolved": r.get("unresolved_instances"), "resolved_ids": resolved, "report_file": reports[0].split("/")[-1]} json.dump(summary, open(out + "/summary.json", "w"), indent=1) print(json.dumps({k: v for k, v in summary.items() if k != "resolved_ids"})) EOF