Spaces:
Paused
Paused
File size: 2,576 Bytes
02ff91f | 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 | """
OpenEnv wrapper — registers SpindleFlowEnv as an OpenEnv-compatible environment.
HACKATHON REQUIREMENT: OpenEnv (latest release) must be used.
This module makes SpindleFlowEnv discoverable and instantiable via the
OpenEnv registry, satisfying the minimum submission requirement.
Usage:
import env.openenv_wrapper # triggers registration
import openenv
env = openenv.make("SpindleFlow-v0")
"""
from __future__ import annotations
try:
import openenv
_OPENENV_AVAILABLE = True
except ImportError:
_OPENENV_AVAILABLE = False
print(
"[OpenEnvWrapper] WARNING: openenv package not found. "
"Run: pip install openenv\n"
"This is a REQUIRED hackathon dependency."
)
from env.spindleflow_env import SpindleFlowEnv
def make_spindleflow_env(**kwargs):
"""Factory function for OpenEnv registry."""
return SpindleFlowEnv(**kwargs)
if _OPENENV_AVAILABLE:
# Register with OpenEnv so `openenv.make("SpindleFlow-v0")` works
try:
openenv.register(
id="SpindleFlow-v0",
entry_point=make_spindleflow_env,
kwargs={
"config_path": "configs/training_config.yaml",
"catalog_path": "configs/specialist_catalog.yaml",
"use_real_spindleflow": False,
"phase": 1,
},
)
print("[OpenEnvWrapper] >> SpindleFlow-v0 registered with OpenEnv")
except Exception as e:
# openenv API may differ across versions — fall back gracefully
print(f"[OpenEnvWrapper] Registration warning: {e}")
print("[OpenEnvWrapper] Verify openenv version: pip show openenv")
def verify_openenv_compliance() -> bool:
"""
Verify that the environment meets OpenEnv compliance.
Called during Step 1 checklist verification.
"""
if not _OPENENV_AVAILABLE:
print("[FAIL] openenv not installed -- REQUIRED for hackathon submission")
return False
try:
env = SpindleFlowEnv(
config_path="configs/training_config.yaml",
catalog_path="configs/specialist_catalog.yaml",
use_real_spindleflow=False,
phase=1,
)
obs, info = env.reset()
action = env.action_space.sample()
obs2, reward, terminated, truncated, info2 = env.step(action)
env.close()
print("[PASS] OpenEnv compliance check passed (reset/step/close cycle OK)")
return True
except Exception as e:
print(f"[FAIL] OpenEnv compliance check failed: {e}")
return False
|