junaid0600 commited on
Commit
2f13d79
·
verified ·
1 Parent(s): 9f883be

Update env/graders.py

Browse files
Files changed (1) hide show
  1. env/graders.py +14 -17
env/graders.py CHANGED
@@ -122,11 +122,11 @@ def _score_error_location(submitted_location: str, expected_location: str) -> fl
122
  def grade_easy(action: Action, ground_truth: dict) -> tuple[float, dict, str]:
123
  """
124
  Easy task grader — syntax errors.
125
- Max score: 0.999 (strictly less than 1.0)
126
  DETERMINISTIC: same input always returns same score.
127
  """
128
  if action is None or action.payload is None:
129
- return 0.001, {"error": "null_action"}, "No action provided."
130
 
131
  payload = action.payload
132
  score = 0.0
@@ -186,8 +186,7 @@ def grade_easy(action: Action, ground_truth: dict) -> tuple[float, dict, str]:
186
  score += conf_score
187
  breakdown["confidence"] = round(conf_score, 4)
188
 
189
- # Clamp strictly between 0 and 1 exclusive
190
- final_score = round(max(0.001, min(0.999, score)), 4)
191
  feedback = " ".join(feedback_parts) if feedback_parts else "No valid response provided."
192
  return final_score, breakdown, feedback
193
 
@@ -195,11 +194,11 @@ def grade_easy(action: Action, ground_truth: dict) -> tuple[float, dict, str]:
195
  def grade_medium(action: Action, ground_truth: dict) -> tuple[float, dict, str]:
196
  """
197
  Medium task grader — logic errors.
198
- Max score: 0.999 (strictly less than 1.0)
199
  DETERMINISTIC: same input always returns same score.
200
  """
201
  if action is None or action.payload is None:
202
- return 0.001, {"error": "null_action"}, "No action provided."
203
 
204
  payload = action.payload
205
  score = 0.0
@@ -276,8 +275,7 @@ def grade_medium(action: Action, ground_truth: dict) -> tuple[float, dict, str]:
276
  else:
277
  breakdown["impact_analysis"] = 0.0
278
 
279
- # Clamp strictly between 0 and 1 exclusive
280
- final_score = round(max(0.001, min(0.999, score)), 4)
281
  feedback = " ".join(feedback_parts) if feedback_parts else "No valid response provided."
282
  return final_score, breakdown, feedback
283
 
@@ -285,12 +283,12 @@ def grade_medium(action: Action, ground_truth: dict) -> tuple[float, dict, str]:
285
  def grade_hard(action: Action, ground_truth: dict) -> tuple[float, dict, str]:
286
  """
287
  Hard task grader — performance issues.
288
- Max score: 0.999 (strictly less than 1.0)
289
  Frontier models expected ~0.10-0.20.
290
  DETERMINISTIC: same input always returns same score.
291
  """
292
  if action is None or action.payload is None:
293
- return 0.001, {"error": "null_action"}, "No action provided."
294
 
295
  payload = action.payload
296
  score = 0.0
@@ -383,8 +381,7 @@ def grade_hard(action: Action, ground_truth: dict) -> tuple[float, dict, str]:
383
  score += conf_score
384
  breakdown["confidence"] = round(conf_score, 4)
385
 
386
- # Clamp strictly between 0 and 1 exclusive
387
- final_score = round(max(0.001, min(0.999, score)), 4)
388
  feedback = " ".join(feedback_parts) if feedback_parts else "Performance issue not identified."
389
  return final_score, breakdown, feedback
390
 
@@ -398,14 +395,14 @@ def grade(action: Action, task_id: str) -> tuple[float, dict, str]:
398
  Main grader entry point.
399
  Looks up ground truth, dispatches to correct grader by difficulty.
400
  ALWAYS returns (float, dict, str) — never crashes.
401
- Score is always strictly between 0.001 and 0.999.
402
  """
403
  if action is None:
404
- return 0.001, {"error": "null_action"}, "No action provided."
405
 
406
  ground_truth = task_manager.get_ground_truth(task_id)
407
  if ground_truth is None:
408
- return 0.001, {"error": "unknown_task"}, f"Task '{task_id}' not found."
409
 
410
  difficulty = ground_truth.get("id", "").split("_")[0]
411
 
@@ -417,6 +414,6 @@ def grade(action: Action, task_id: str) -> tuple[float, dict, str]:
417
  elif difficulty == "hard":
418
  return grade_hard(action, ground_truth)
419
  else:
420
- return 0.001, {"error": "unknown_difficulty"}, f"Unknown difficulty: {difficulty}"
421
  except Exception as e:
422
- return 0.001, {"error": str(e)}, f"Grader error: {str(e)}"
 
122
  def grade_easy(action: Action, ground_truth: dict) -> tuple[float, dict, str]:
123
  """
124
  Easy task grader — syntax errors.
125
+ Max score: 1.0
126
  DETERMINISTIC: same input always returns same score.
127
  """
128
  if action is None or action.payload is None:
129
+ return 0.0, {"error": "null_action"}, "No action provided."
130
 
131
  payload = action.payload
132
  score = 0.0
 
186
  score += conf_score
187
  breakdown["confidence"] = round(conf_score, 4)
188
 
189
+ final_score = round(max(0.0, min(1.0, score)), 4)
 
190
  feedback = " ".join(feedback_parts) if feedback_parts else "No valid response provided."
191
  return final_score, breakdown, feedback
192
 
 
194
  def grade_medium(action: Action, ground_truth: dict) -> tuple[float, dict, str]:
195
  """
196
  Medium task grader — logic errors.
197
+ Max score: 1.0
198
  DETERMINISTIC: same input always returns same score.
199
  """
200
  if action is None or action.payload is None:
201
+ return 0.0, {"error": "null_action"}, "No action provided."
202
 
203
  payload = action.payload
204
  score = 0.0
 
275
  else:
276
  breakdown["impact_analysis"] = 0.0
277
 
278
+ final_score = round(max(0.0, min(1.0, score)), 4)
 
279
  feedback = " ".join(feedback_parts) if feedback_parts else "No valid response provided."
280
  return final_score, breakdown, feedback
281
 
 
283
  def grade_hard(action: Action, ground_truth: dict) -> tuple[float, dict, str]:
284
  """
285
  Hard task grader — performance issues.
286
+ Max score: 1.0
287
  Frontier models expected ~0.10-0.20.
288
  DETERMINISTIC: same input always returns same score.
289
  """
290
  if action is None or action.payload is None:
291
+ return 0.0, {"error": "null_action"}, "No action provided."
292
 
293
  payload = action.payload
294
  score = 0.0
 
381
  score += conf_score
382
  breakdown["confidence"] = round(conf_score, 4)
383
 
384
+ final_score = round(max(0.0, min(1.0, score)), 4)
 
385
  feedback = " ".join(feedback_parts) if feedback_parts else "Performance issue not identified."
386
  return final_score, breakdown, feedback
387
 
 
395
  Main grader entry point.
396
  Looks up ground truth, dispatches to correct grader by difficulty.
397
  ALWAYS returns (float, dict, str) — never crashes.
398
+ Score is always between 0.0 and 1.0.
399
  """
400
  if action is None:
401
+ return 0.0, {"error": "null_action"}, "No action provided."
402
 
403
  ground_truth = task_manager.get_ground_truth(task_id)
404
  if ground_truth is None:
405
+ return 0.0, {"error": "unknown_task"}, f"Task '{task_id}' not found."
406
 
407
  difficulty = ground_truth.get("id", "").split("_")[0]
408
 
 
414
  elif difficulty == "hard":
415
  return grade_hard(action, ground_truth)
416
  else:
417
+ return 0.0, {"error": "unknown_difficulty"}, f"Unknown difficulty: {difficulty}"
418
  except Exception as e:
419
+ return 0.0, {"error": str(e)}, f"Grader error: {str(e)}"