Datasets:
File size: 2,778 Bytes
b67437c f722940 b67437c | 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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | #!/usr/bin/env python3
"""Summarize a Harbor job (or trials directory) run on the MissionReport tasks.
usage: python scripts/summarize_job.py <job or trials directory> [--criteria]
Prints one line per trial: task, model, reward, positive points earned, penalty points triggered.
With --criteria, also lists each criterion the report missed and each penalty it triggered, with
the judge's one-line reason. Reads result.json and steps/answer/verifier/reward-details.json from
each trial directory. Standard library only.
"""
import json
import sys
from pathlib import Path
def criteria_of(trial: Path) -> list[dict]:
details = trial / "steps" / "answer" / "verifier" / "reward-details.json"
if not details.is_file():
return []
rubric = json.loads(details.read_text()).get("reward", {}).get("rubric") or {}
return rubric.get("criteria") or []
def main() -> None:
root = Path(sys.argv[1])
show = "--criteria" in sys.argv
rewards = []
for result in sorted(root.rglob("result.json")):
trial = result.parent
data = json.loads(result.read_text())
if "trial_name" not in data:
continue # the job-level result.json
task = data.get("task_name", trial.name).split("/")[-1]
model = ((data.get("agent_info") or {}).get("model_info") or {}).get("name") or data["agent_info"]["name"]
reward = ((data.get("verifier_result") or {}).get("rewards") or {}).get("reward")
error = (data.get("exception_info") or {}).get("exception_type")
criteria = criteria_of(trial)
earned = sum(c["signed_score"] for c in criteria if c["signed_score"] > 0 and c.get("raw"))
possible = sum(c["signed_score"] for c in criteria if c["signed_score"] > 0)
penalties = -sum(c["signed_score"] for c in criteria if c["signed_score"] < 0 and c.get("raw"))
shown = "error: " + error if error else ("no reward" if reward is None else f"{reward:.3f}")
print(f"{task:8} {model:32} {shown:>12} earned {earned:g}/{possible:g} penalties {penalties:g}")
if reward is not None:
rewards.append(reward)
if show:
for c in criteria:
missed = c["signed_score"] > 0 and not c.get("raw")
triggered = c["signed_score"] < 0 and c.get("raw")
if missed or triggered:
tag = "MISSED " if missed else "PENALTY"
print(f" {tag} {c['signed_score']:+g} {c['description']}")
if c.get("judge_reasoning"):
print(f" judge: {c['judge_reasoning']}")
if rewards:
print(f"\n{len(rewards)} graded trials, mean reward {sum(rewards) / len(rewards):.3f}")
if __name__ == "__main__":
main()
|