Update rubrics.py
Browse files123456789101112131418 unmodified lines3334353637383940414243446 unmodified lines5152535455565758596 unmodified lines666768697071727374757677786 unmodified lines858687888990919293949596979811 unmodified lines1101111121131141151161171181191201211221231241252 unmodified lines128129130131132133134135136137138139140141142143144145146# rubrics.py – OpenEnv Rubrics for Code Review Environmentfrom openenv.core import Rubric# --------------------------------------------------------------------------------# 1. TOOL‑USAGE BONUS (encourages first‑time use of diagnostic tools)# --------------------------------------------------------------------------------class ToolUsageRubric(Rubric):"""Small fixed reward the first time each of the major diagnostic tools is used.Also gives a tiny reward for every invocation to prevent the agent from ignoring them."""def __init__(self, bonus: float = 0.05):self.bonus = bonus18 unmodified lines# --------------------------------------------------------------------------------# 2. DELTA‑BASED REWARDS (primary learning signal)# --------------------------------------------------------------------------------class TestDeltaRubric(Rubric):"""Rewards improvement in the pass ratio of the test suite."""def __init__(self, weight: float = 0.3):self.weight = weight6 unmodified linesclass LintDeltaRubric(Rubric):"""Rewards improvement in lint score (normalised 0‑1)."""def __init__(self, weight: float = 0.3):self.weight = weight6 unmodified lines# --------------------------------------------------------------------------------# 3. TERMINAL SUCCESS BONUS (propose_fix only)# --------------------------------------------------------------------------------class TerminalSuccessRubric(Rubric):"""Bonus awarded when a proposed fix achieves high test and lint scores.Graded: >0.85 → 0.2, >0.95 → 0.4."""def __call__(self, env, action, obs, reward, done, info):if info.get("action_type") != "propose_fix":return 0.06 unmodified lines# --------------------------------------------------------------------------------# 4. EXPLORATION & DIVERSITY (discourages repetition, encourages varied actions)# --------------------------------------------------------------------------------class ExplorationRubric(Rubric):"""Encourages diverse action sequences.- Penalty if last 3 actions are all the same.- Bonus if they are all different."""def __init__(self, penalty: float = -0.05, bonus: float = 0.021):self.penalty = penaltyself.bonus = bonus11 unmodified lines# --------------------------------------------------------------------------------# 5. ANTI‑HACKING & CONSISTENCY (prevents reward without real work)# --------------------------------------------------------------------------------class AntiHackingRubric(Rubric):"""Penalises suspicious behaviour:- proposing a fix without ever running tests.- proposing a fix too early (step < 2).Additional cross‑signal penalties are applied in the environment (not as a rubric)because they require modifying the base reward, not adding to it."""def __call__(self, env, action, obs, reward, done, info):if info.get("action_type") != "propose_fix":return 0.02 unmodified linesscore -= 0.25if env._step_count < 2:score -= 0.1# tiny boost if the agent did the “right” preparationif env._tests_run and env._linter_run:score += 0.02return score# --------------------------------------------------------------------------------# 6. STEP PENALTY (time pressure)# --------------------------------------------------------------------------------class StepPenaltyRubric(Rubric):"""Simple per‑step penalty to encourage efficient resolution."""def __init__(self, penalty: float = -0.01):self.penalty = penalty12345678910111213141518 unmodified lines3435363738394041426 unmodified lines4950515253546 unmodified lines6162636465666768696 unmodified lines76777879808182838411 unmodified lines969798991001011021031042 unmodified lines107108109110111112113114115116117118119120121# rubrics.py – Self-contained Rubrics (no external OpenEnv dependency)class Rubric:"""Minimal Rubric base – compatible with OpenEnv but self‑contained."""def __call__(self, env, action, obs, reward, done, info):return 0.0# --------------------------------------------------------------------------------# 1. TOOL‑USAGE BONUS# --------------------------------------------------------------------------------class ToolUsageRubric(Rubric):def __init__(self, bonus: float = 0.05):self.bonus = bonus18 unmodified lines# --------------------------------------------------------------------------------# 2. DELTA‑BASED REWARDS# --------------------------------------------------------------------------------class TestDeltaRubric(Rubric):def __init__(self, weight: float = 0.3):self.weight = weight6 unmodified linesclass LintDeltaRubric(Rubric):def __init__(self, weight: float = 0.3):self.weight = weight6 unmodified lines# --------------------------------------------------------------------------------# 3. TERMINAL SUCCESS BONUS# --------------------------------------------------------------------------------class TerminalSuccessRubric(Rubric):def __call__(self, env, action, obs, reward, done, info):if info.get("action_type") != "propose_fix":return 0.06 unmodified lines# --------------------------------------------------------------------------------# 4. EXPLORATION & DIVERSITY# --------------------------------------------------------------------------------class ExplorationRubric(Rubric):def __init__(self, penalty: float = -0.05, bonus: float = 0.021):self.penalty = penaltyself.bonus = bonus11 unmodified lines# --------------------------------------------------------------------------------# 5. ANTI‑HACKING & CONSISTENCY# --------------------------------------------------------------------------------class AntiHackingRubric(Rubric):def __call__(self, env, action, obs, reward, done, info):if info.get("action_type") != "propose_fix":return 0.02 unmodified linesscore -= 0.25if env._step_count < 2:score -= 0.1if env._tests_run and env._linter_run:score += 0.02return score# --------------------------------------------------------------------------------# 6. STEP PENALTY# --------------------------------------------------------------------------------class StepPenaltyRubric(Rubric):def __init__(self, penalty: float = -0.01):self.penalty = penalty
rubrics.py+13-38