openenv-null-control / source /server /environment.py
naklitechie's picture
Upload folder using huggingface_hub
9de6be7 verified
Raw History Blame Contribute Delete
1.63 kB
"""Null-control environment: every episode ends after one action with the same reward.
Every rollout in a GRPO group gets REWARD, so within-group variance and the
advantage are zero on every step. Purpose: measure the arena's evaluation with
no learning signal (plan/research/design.md, Batch B).
"""
from uuid import uuid4
from openenv.core.env_server.interfaces import Environment
from openenv.core.env_server.types import State
try:
from ..models import NullAction, NullObservation
except ImportError:
from models import NullAction, NullObservation
REWARD = 0.5
TASK_IDS = ("null",)
PROMPT = 'Reply with one JSON object: {"answer": "done"}. Any reply ends the episode.'
class NullEnvironment(Environment):
SUPPORTS_CONCURRENT_SESSIONS: bool = True
def __init__(self):
self._state = State(episode_id=str(uuid4()), step_count=0)
self._done = False
def reset(self, seed=None, episode_id=None, task_id=None, **kwargs) -> NullObservation:
if task_id is not None and task_id not in TASK_IDS:
raise ValueError(f"unknown task_id {task_id!r}; known: {list(TASK_IDS)}")
self._state = State(episode_id=episode_id or str(uuid4()), step_count=0)
self._done = False
return NullObservation(prompt=PROMPT, done=False, reward=0.0)
def step(self, action: NullAction, timeout_s=None, **kwargs) -> NullObservation: # type: ignore[override]
self._state.step_count += 1
self._done = True
return NullObservation(prompt="Episode over.", done=True, reward=REWARD)
@property
def state(self) -> State:
return self._state