Spaces:
Sleeping
Sleeping
Subhash Vadaparthi commited on
Commit Β·
c525e8b
1
Parent(s): 1a0dc50
fix: use standalone grader functions and add difficulty to openenv.yaml
Browse filesFiles changed (2)
- openenv.yaml+6-3
- tasks.py+88-67
14 unmodified lines15161718192021222324252614 unmodified lines- id: "book_appointment"name: "Task 1: Basic Booking"description: "Successfully book an appointment when slots are available."grader: "tasks:TaskGrader.grade_task_1"- id: "scheduling_conflicts"name: "Task 2: Conflict Management"description: "Handle scheduling conflicts and rescheduling efficiently."grader: "tasks:TaskGrader.grade_task_2"- id: "priority_scheduling"name: "Task 3: Priority Optimization"description: "Optimize scheduling for patients with different priorities."grader: "tasks:TaskGrader.grade_task_3"14 unmodified lines15161718192021222324252627282914 unmodified lines- id: "book_appointment"name: "Task 1: Basic Booking"description: "Successfully book an appointment when slots are available."difficulty: "easy"grader: "tasks:grade_task_1"- id: "scheduling_conflicts"name: "Task 2: Conflict Management"description: "Handle scheduling conflicts and rescheduling efficiently."difficulty: "medium"grader: "tasks:grade_task_2"- id: "priority_scheduling"name: "Task 3: Priority Optimization"description: "Optimize scheduling for patients with different priorities."difficulty: "hard"grader: "tasks:grade_task_3"
12341 unmodified line67891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283from typing import List, Dict, Anyclass Task:def __init__(self, name: str, difficulty: str, description: str):1 unmodified lineself.difficulty = difficultyself.description = descriptionclass TaskGrader:"""Grader for Healthcare Scheduling Tasks.IMPORTANT: OpenEnv requirements specify that scores MUST be strictlybetween 0 and 1 (not 0.0 and not 1.0). We use 0.01 and 0.99 as bounds."""def __init__(self, env):self.env = envdef _clamp(self, score: float) -> float:"""Clamp score to strictly (0, 1) range β never exactly 0.0 or 1.0."""if score != score: # NaN checkreturn 0.5return min(max(float(score), 0.01), 0.99)def grade_task_1(self) -> float:"""Task 1 (Easy): successfully book an appointment when slots are available.Score based on number of waiting patients booked."""if not self.env.patients:return 0.5 # No patients = default mid-range scorebooked_count = sum(1 for p in self.env.patients.values() if p.get("status") == "booked")total_patients = len(self.env.patients)if total_patients == 0:return 0.5raw_score = booked_count / (total_patients * 0.5)return self._clamp(raw_score)def grade_task_2(self) -> float:"""Task 2 (Medium): Handle scheduling conflicts and rescheduling.Score based on rescheduling success and slot utilization."""if not self.env.patients:return 0.5booked_count = sum(1 for p in self.env.patients.values() if p.get("status") == "booked")total_patients = len(self.env.patients)if total_patients == 0:return 0.5raw_score = booked_count / (total_patients * 0.7)return self._clamp(raw_score)def grade_task_3(self) -> float:"""Task 3 (Hard): Optimize scheduling for multiple patients with different priorities.Score based on priority completion. Priority 1 should be booked FIRST."""if not self.env.patients:return 0.5p1_total = sum(1 for p in self.env.patients.values() if p.get("priority") == 1)p1_booked = sum(1 for p in self.env.patients.values() if p.get("priority") == 1 and p.get("status") == "booked")p2_total = sum(1 for p in self.env.patients.values() if p.get("priority") == 2)p2_booked = sum(1 for p in self.env.patients.values() if p.get("priority") == 2 and p.get("status") == "booked")if p1_total == 0:p1_score = 0.5else:p1_score = p1_booked / p1_totalif p2_total == 0:p2_score = 0.5else:p2_score = p2_booked / p2_totalraw_score = (p1_score * 0.7) + (p2_score * 0.3)return self._clamp(raw_score)TASKS = [Task("Task 1", "Easy", "Successfully book an appointment when slots are available."),Task("Task 2", "Medium", "Handle scheduling conflicts and rescheduling."),Task("Task 3", "Hard", "Optimize scheduling for multiple patients with different priorities.")]12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576771 unmodified line798081828384858687888990919293949596979899100101102103104"""Task graders for Healthcare Scheduling Environment.OpenEnv expects graders to be standalone callable functions that can beimported via the `module:function` path format. Each grader:- Creates / receives an environment instance- Evaluates the task- Returns a float score strictly in (0, 1) β never 0.0 or 1.0"""from typing import Any, Dict, List# ββ Helper βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββdef _clamp(score: float) -> float:"""Clamp score to strictly (0, 1) β never exactly 0.0 or 1.0."""if score != score: # NaN checkreturn 0.5return min(max(float(score), 0.01), 0.99)# ββ Standalone grader functions (referenced by openenv.yaml) βββββββββdef grade_task_1(env) -> float:"""Task 1 (Easy): Successfully book appointments when slots are available.Score based on fraction of patients booked."""if not env.patients:return 0.5booked_count = sum(1 for p in env.patients.values() if p.get("status") == "booked")total_patients = len(env.patients)if total_patients == 0:return 0.5raw_score = booked_count / (total_patients * 0.5)return _clamp(raw_score)def grade_task_2(env) -> float:"""Task 2 (Medium): Handle scheduling conflicts and rescheduling.Score based on rescheduling success and slot utilization."""if not env.patients:return 0.5booked_count = sum(1 for p in env.patients.values() if p.get("status") == "booked")total_patients = len(env.patients)if total_patients == 0:return 0.5raw_score = booked_count / (total_patients * 0.7)return _clamp(raw_score)def grade_task_3(env) -> float:"""Task 3 (Hard): Optimize scheduling for multiple patients with priorities.Score weighted toward priority-1 patients being booked first."""if not env.patients:return 0.5p1_total = sum(1 for p in env.patients.values() if p.get("priority") == 1)p1_booked = sum(1 for p in env.patients.values() if p.get("priority") == 1 and p.get("status") == "booked")p2_total = sum(1 for p in env.patients.values() if p.get("priority") == 2)p2_booked = sum(1 for p in env.patients.values() if p.get("priority") == 2 and p.get("status") == "booked")p1_score = (p1_booked / p1_total) if p1_total > 0 else 0.5p2_score = (p2_booked / p2_total) if p2_total > 0 else 0.5raw_score = (p1_score * 0.7) + (p2_score * 0.3)return _clamp(raw_score)# ββ Task metadata ββββββββββββββββββββββββββββββββββββββββββββββββββββclass Task:def __init__(self, name: str, difficulty: str, description: str):1 unmodified lineself.difficulty = difficultyself.description = descriptionTASKS = [Task("Task 1", "easy", "Successfully book an appointment when slots are available."),Task("Task 2", "medium", "Handle scheduling conflicts and rescheduling."),Task("Task 3", "hard", "Optimize scheduling for multiple patients with different priorities."),]# ββ Backward-compatible class wrapper (used by inference.py) βββββββββclass TaskGrader:"""Class wrapper for backward compat with inference.py."""def __init__(self, env):self.env = envdef grade_task_1(self) -> float:return grade_task_1(self.env)def grade_task_2(self) -> float:return grade_task_2(self.env)def grade_task_3(self) -> float:return grade_task_3(self.env)
openenv.yaml+6-3
tasks.py+88-67