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 lines15161718181920212223222425262728262914 unmodified lines - id: "book_appointment" name: "Task 1: Basic Booking" description: "Successfully book an appointment when slots are available." difficulty: "easy" grader: "tasks:TaskGrader.grade_task_1" grader: "tasks:grade_task_1" - id: "scheduling_conflicts" name: "Task 2: Conflict Management" description: "Handle scheduling conflicts and rescheduling efficiently." difficulty: "medium" grader: "tasks:TaskGrader.grade_task_2" 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:TaskGrader.grade_task_3" grader: "tasks:grade_task_3"123456789101111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576771 unmodified line798081828384858687888990919210111213141593949596192021222324972627282930313233343536379899100404142434445464748495051101102103545556575859606162636465666768697071727374757677787980818283104"""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 List, Dict, Anyfrom 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 check return 0.5 return 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.5 booked_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.5 raw_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.5 booked_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.5 raw_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.5 p1_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.5 p2_score = (p2_booked / p2_total) if p2_total > 0 else 0.5
raw_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 line self.difficulty = difficulty self.description = description
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."),]
# ββ Backward-compatible class wrapper (used by inference.py) βββββββββ
class TaskGrader: """ Grader for Healthcare Scheduling Tasks. IMPORTANT: OpenEnv requirements specify that scores MUST be strictly between 0 and 1 (not 0.0 and not 1.0). We use 0.01 and 0.99 as bounds. """ """Class wrapper for backward compat with inference.py.""" def __init__(self, env): self.env = env
def _clamp(self, score: float) -> float: """Clamp score to strictly (0, 1) range β never exactly 0.0 or 1.0.""" if score != score: # NaN check return 0.5 return 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 score booked_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.5 raw_score = booked_count / (total_patients * 0.5) return self._clamp(raw_score) return grade_task_1(self.env)
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.5 booked_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.5 raw_score = booked_count / (total_patients * 0.7) return self._clamp(raw_score) return grade_task_2(self.env)
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.5 p1_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.5 else: p1_score = p1_booked / p1_total
if p2_total == 0: p2_score = 0.5 else: p2_score = p2_booked / p2_total raw_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.")] return grade_task_3(self.env)openenv.yaml+6-3
tasks.py+88-67