File size: 1,788 Bytes
c3cd245
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Score one LegalReasonBench matter from a finished Harbor trial.

The matter reward is points-weighted across its assignments: the sum of signed
points earned (penalties subtract) over the sum of available positive points,
clamped to [0, 1]. Harbor's own multi_step_reward_strategy = "mean" averages the
per-assignment rewards instead and is diagnostic only.

Usage: python score_matter.py <harbor trial dir>
"""
import json
import sys
from pathlib import Path


def score(trial_dir: Path) -> dict:
    earned = positive = 0.0
    steps = []
    # Each assignment's verifier writes reward-details.json; the raw RewardKit copy
    # under raw/ has no aggregation block and is skipped.
    for details in sorted(trial_dir.rglob("reward-details.json")):
        correctness = json.loads(details.read_text()).get("correctness")
        aggregation = correctness.get("aggregation") if isinstance(correctness, dict) else None
        if not isinstance(aggregation, dict) or "earned" not in aggregation or "positive_total" not in aggregation:
            continue
        earned += float(aggregation["earned"])
        positive += float(aggregation["positive_total"])
        steps.append({
            "file": str(details.relative_to(trial_dir)),
            "assignment_reward": correctness.get("score"),
            "earned": aggregation["earned"],
            "positive_total": aggregation["positive_total"],
        })
    if not steps:
        raise SystemExit(f"no assignment reward-details.json under {trial_dir}")
    overall = max(0.0, min(1.0, earned / positive)) if positive > 0 else 0.0
    return {"matter_reward": overall, "earned": earned, "positive_total": positive, "assignments": steps}


if __name__ == "__main__":
    print(json.dumps(score(Path(sys.argv[1])), indent=2))