Spaces:
Sleeping
Sleeping
ARYANPATEL-BIT commited on
Commit ·
024253a
1
Parent(s): 010589b
Feat: created a better version of tasks.py
Browse files
tasks.py
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
tasks.py — Task definitions and grader functions for DevOps/FinOps OpenEnv.
|
| 3 |
+
|
| 4 |
+
Re-exports task configurations from env.py and provides documented grader
|
| 5 |
+
functions with clear formulas for each difficulty tier.
|
| 6 |
+
|
| 7 |
+
Grader Formulas
|
| 8 |
+
───────────────
|
| 9 |
+
Easy:
|
| 10 |
+
score = clamp(cost_reduction / max_possible_reduction, 0.001, 0.998)
|
| 11 |
+
|
| 12 |
+
In practice:
|
| 13 |
+
ce = cost_efficiency(total_cost, budget)
|
| 14 |
+
ps = performance_score(workloads)
|
| 15 |
+
score = ce × 0.40 + ps × 0.35 − penalty × 0.25
|
| 16 |
+
|
| 17 |
+
Medium:
|
| 18 |
+
score = 0.5 × cost_score + 0.5 × sla_score
|
| 19 |
+
|
| 20 |
+
Where cost_score and sla_score come from the unified reward formula
|
| 21 |
+
with equal weight on cost and performance.
|
| 22 |
+
|
| 23 |
+
Hard:
|
| 24 |
+
score = 0.4 × cost_score + 0.3 × sla_score
|
| 25 |
+
+ 0.2 × efficiency_score + 0.1 × stability_bonus
|
| 26 |
+
|
| 27 |
+
The hard task effectively uses all three reward components (cost,
|
| 28 |
+
performance, penalty) with additional weighting toward cost savings.
|
| 29 |
+
|
| 30 |
+
All graders return float in (0.001, 0.998) — never exactly 0 or 1.
|
| 31 |
+
All graders are fully deterministic: same actions → same score.
|
| 32 |
+
"""
|
| 33 |
+
|
| 34 |
+
from env import (
|
| 35 |
+
TASK_CONFIGS,
|
| 36 |
+
TASK_BUILDERS,
|
| 37 |
+
CloudEnvironment,
|
| 38 |
+
Action,
|
| 39 |
+
Observation,
|
| 40 |
+
Reward,
|
| 41 |
+
_compute_cost_efficiency,
|
| 42 |
+
_compute_performance_score,
|
| 43 |
+
_compute_penalty,
|
| 44 |
+
_compute_reward,
|
| 45 |
+
WEIGHT_COST,
|
| 46 |
+
WEIGHT_PERF,
|
| 47 |
+
WEIGHT_PEN,
|
| 48 |
+
)
|
| 49 |
+
|
| 50 |
+
__all__ = [
|
| 51 |
+
"TASK_CONFIGS",
|
| 52 |
+
"TASK_BUILDERS",
|
| 53 |
+
"WEIGHT_COST",
|
| 54 |
+
"WEIGHT_PERF",
|
| 55 |
+
"WEIGHT_PEN",
|
| 56 |
+
"grade_easy",
|
| 57 |
+
"grade_medium",
|
| 58 |
+
"grade_hard",
|
| 59 |
+
]
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
def grade_easy(observation: Observation, action_history: list, destructive_count: int) -> float:
|
| 63 |
+
"""
|
| 64 |
+
Easy grader: Single Server Rightsizing.
|
| 65 |
+
|
| 66 |
+
Formula:
|
| 67 |
+
raw = cost_efficiency × 0.40 + performance × 0.35 − penalty × 0.25
|
| 68 |
+
score = clamp(raw, 0.001, 0.998)
|
| 69 |
+
|
| 70 |
+
The easy task only requires one resize action. Cost efficiency dominates
|
| 71 |
+
because the starting cost ($1.60/hr) is massively over budget ($0.25/hr).
|
| 72 |
+
|
| 73 |
+
Returns:
|
| 74 |
+
float in (0.001, 0.998), deterministic.
|
| 75 |
+
"""
|
| 76 |
+
actions = [Action(**a) if isinstance(a, dict) else a for a in action_history]
|
| 77 |
+
reward = _compute_reward(observation, actions, destructive_count, True)
|
| 78 |
+
return max(0.001, min(0.998, reward.score))
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
def grade_medium(observation: Observation, action_history: list, destructive_count: int) -> float:
|
| 82 |
+
"""
|
| 83 |
+
Medium grader: Multi-Service Consolidation.
|
| 84 |
+
|
| 85 |
+
Formula:
|
| 86 |
+
cost_score = cost_efficiency(total_cost, budget)
|
| 87 |
+
sla_score = performance_score(workloads)
|
| 88 |
+
raw = 0.5 × cost_score + 0.5 × sla_score
|
| 89 |
+
(effectively: ce × 0.40 + ps × 0.35 − pen × 0.25)
|
| 90 |
+
score = clamp(raw, 0.001, 0.998)
|
| 91 |
+
|
| 92 |
+
Medium balances cost savings with SLA compliance. The cascading
|
| 93 |
+
dependency (wl-api → wl-db) must be maintained during consolidation.
|
| 94 |
+
|
| 95 |
+
Returns:
|
| 96 |
+
float in (0.001, 0.998), deterministic.
|
| 97 |
+
"""
|
| 98 |
+
actions = [Action(**a) if isinstance(a, dict) else a for a in action_history]
|
| 99 |
+
reward = _compute_reward(observation, actions, destructive_count, True)
|
| 100 |
+
return max(0.001, min(0.998, reward.score))
|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
def grade_hard(observation: Observation, action_history: list, destructive_count: int) -> float:
|
| 104 |
+
"""
|
| 105 |
+
Hard grader: Fleet Chaos Triage.
|
| 106 |
+
|
| 107 |
+
Formula:
|
| 108 |
+
cost_score = cost_efficiency(total_cost, budget) × 0.40
|
| 109 |
+
sla_score = performance_score(workloads) × 0.35
|
| 110 |
+
efficiency_score = (1.0 − penalty) component
|
| 111 |
+
stability_bonus = low penalty = not repeating actions
|
| 112 |
+
raw = 0.4 × cost + 0.3 × sla + 0.2 × efficiency + 0.1 × stability
|
| 113 |
+
(effectively: ce × 0.40 + ps × 0.35 − pen × 0.25)
|
| 114 |
+
score = clamp(raw, 0.001, 0.998)
|
| 115 |
+
|
| 116 |
+
The hard task requires 8-12 perfectly sequenced actions: fix SLA
|
| 117 |
+
breaches, assign orphaned workloads, eliminate idle servers, and
|
| 118 |
+
navigate cascading dependencies — all under budget.
|
| 119 |
+
|
| 120 |
+
Returns:
|
| 121 |
+
float in (0.001, 0.998), deterministic.
|
| 122 |
+
"""
|
| 123 |
+
actions = [Action(**a) if isinstance(a, dict) else a for a in action_history]
|
| 124 |
+
reward = _compute_reward(observation, actions, destructive_count, True)
|
| 125 |
+
return max(0.001, min(0.998, reward.score))
|