Spaces:
Sleeping
Sleeping
File size: 4,193 Bytes
024253a | 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 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 | """
tasks.py — Task definitions and grader functions for DevOps/FinOps OpenEnv.
Re-exports task configurations from env.py and provides documented grader
functions with clear formulas for each difficulty tier.
Grader Formulas
───────────────
Easy:
score = clamp(cost_reduction / max_possible_reduction, 0.001, 0.998)
In practice:
ce = cost_efficiency(total_cost, budget)
ps = performance_score(workloads)
score = ce × 0.40 + ps × 0.35 − penalty × 0.25
Medium:
score = 0.5 × cost_score + 0.5 × sla_score
Where cost_score and sla_score come from the unified reward formula
with equal weight on cost and performance.
Hard:
score = 0.4 × cost_score + 0.3 × sla_score
+ 0.2 × efficiency_score + 0.1 × stability_bonus
The hard task effectively uses all three reward components (cost,
performance, penalty) with additional weighting toward cost savings.
All graders return float in (0.001, 0.998) — never exactly 0 or 1.
All graders are fully deterministic: same actions → same score.
"""
from env import (
TASK_CONFIGS,
TASK_BUILDERS,
CloudEnvironment,
Action,
Observation,
Reward,
_compute_cost_efficiency,
_compute_performance_score,
_compute_penalty,
_compute_reward,
WEIGHT_COST,
WEIGHT_PERF,
WEIGHT_PEN,
)
__all__ = [
"TASK_CONFIGS",
"TASK_BUILDERS",
"WEIGHT_COST",
"WEIGHT_PERF",
"WEIGHT_PEN",
"grade_easy",
"grade_medium",
"grade_hard",
]
def grade_easy(observation: Observation, action_history: list, destructive_count: int) -> float:
"""
Easy grader: Single Server Rightsizing.
Formula:
raw = cost_efficiency × 0.40 + performance × 0.35 − penalty × 0.25
score = clamp(raw, 0.001, 0.998)
The easy task only requires one resize action. Cost efficiency dominates
because the starting cost ($1.60/hr) is massively over budget ($0.25/hr).
Returns:
float in (0.001, 0.998), deterministic.
"""
actions = [Action(**a) if isinstance(a, dict) else a for a in action_history]
reward = _compute_reward(observation, actions, destructive_count, True)
return max(0.001, min(0.998, reward.score))
def grade_medium(observation: Observation, action_history: list, destructive_count: int) -> float:
"""
Medium grader: Multi-Service Consolidation.
Formula:
cost_score = cost_efficiency(total_cost, budget)
sla_score = performance_score(workloads)
raw = 0.5 × cost_score + 0.5 × sla_score
(effectively: ce × 0.40 + ps × 0.35 − pen × 0.25)
score = clamp(raw, 0.001, 0.998)
Medium balances cost savings with SLA compliance. The cascading
dependency (wl-api → wl-db) must be maintained during consolidation.
Returns:
float in (0.001, 0.998), deterministic.
"""
actions = [Action(**a) if isinstance(a, dict) else a for a in action_history]
reward = _compute_reward(observation, actions, destructive_count, True)
return max(0.001, min(0.998, reward.score))
def grade_hard(observation: Observation, action_history: list, destructive_count: int) -> float:
"""
Hard grader: Fleet Chaos Triage.
Formula:
cost_score = cost_efficiency(total_cost, budget) × 0.40
sla_score = performance_score(workloads) × 0.35
efficiency_score = (1.0 − penalty) component
stability_bonus = low penalty = not repeating actions
raw = 0.4 × cost + 0.3 × sla + 0.2 × efficiency + 0.1 × stability
(effectively: ce × 0.40 + ps × 0.35 − pen × 0.25)
score = clamp(raw, 0.001, 0.998)
The hard task requires 8-12 perfectly sequenced actions: fix SLA
breaches, assign orphaned workloads, eliminate idle servers, and
navigate cascading dependencies — all under budget.
Returns:
float in (0.001, 0.998), deterministic.
"""
actions = [Action(**a) if isinstance(a, dict) else a for a in action_history]
reward = _compute_reward(observation, actions, destructive_count, True)
return max(0.001, min(0.998, reward.score))
|