File size: 3,108 Bytes
ed507c1
 
 
 
 
 
 
 
 
 
 
 
76acce0
ed507c1
 
 
 
 
 
76acce0
ed507c1
 
 
 
 
76acce0
 
42b6583
ed507c1
42b6583
 
ed507c1
 
 
 
 
76acce0
42b6583
 
 
 
ed507c1
 
 
 
 
 
 
 
 
 
 
42b6583
ed507c1
 
 
 
 
 
 
42b6583
ed507c1
 
 
 
 
 
 
42b6583
ed507c1
9ef5507
 
 
 
 
 
 
 
ed507c1
 
 
42b6583
ed507c1
 
 
 
42b6583
ed507c1
 
 
 
 
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
"""
Task definitions for FarmRL OpenEnv submission.

Defines three progressive difficulty levels for farm management optimization.
Each task is associated with a grading function that evaluates performance.
"""

from typing import Dict, List, Any


class TaskDefinition:
    """Represents a task with metadata and grader association."""

    def __init__(
        self,
        task_id: str,
        name: str,
        description: str,
        difficulty: str,
        grader: str,
    ):
        self.task_id = task_id
        self.name = name
        self.description = description
        self.difficulty = difficulty
        self.grader = grader

    def to_dict(self) -> Dict[str, Any]:
        """Convert to OpenEnv task definition format."""
        grader_name = self.grader.split(
            ":")[-1] if ":" in self.grader else self.grader
        return {
            "id": self.task_id,
            "name": self.name,
            "description": self.description,
            "difficulty": self.difficulty,
            "grader": self.grader,
            "grader_fn": self.grader,
            "grader_name": grader_name,
            "grader_endpoint": "/grader",
            "grader_enabled": True,
        }


# Define the three required tasks matching the graders
TASKS: List[TaskDefinition] = [
    TaskDefinition(
        task_id="task_easy_yield",
        name="Yield Performance",
        description="Maximize crop yield through optimal irrigation and environmental management. "
                    "Graded on average reward per step.",
        difficulty="easy",
        grader="tasks.graders:grade_yield_performance",
    ),
    TaskDefinition(
        task_id="task_medium_chemical_efficiency",
        name="Chemical Efficiency",
        description="Minimize fertilizer and pesticide usage while maintaining acceptable yields. "
                    "Graded on chemical use efficiency.",
        difficulty="medium",
        grader="tasks.graders:grade_chemical_efficiency",
    ),
    TaskDefinition(
        task_id="task_hard_sustainability_balance",
        name="Sustainability Balance",
        description="Achieve top-tier sustainability by maximizing yield-to-chemical-input ratio. "
                    "Graded on sustainability metrics.",
        difficulty="hard",
        grader="tasks.graders:grade_sustainability_balance",
    ),
    TaskDefinition(
        task_id="task_expert_soil_health",
        name="Soil Health Monitoring",
        description="Maintain optimal soil conditions by managing moisture and pH levels. "
                    "Graded on soil pH stability and moisture retention within ideal ranges.",
        difficulty="expert",
        grader="tasks.graders:grade_soil_health",
    ),
]


def get_all_tasks() -> List[Dict[str, Any]]:
    """Return all task definitions in OpenEnv format."""
    return [task.to_dict() for task in TASKS]


def get_task_by_id(task_id: str) -> Dict[str, Any] | None:
    """Look up a task definition by ID."""
    for task in TASKS:
        if task.task_id == task_id:
            return task.to_dict()
    return None