Spaces:
Runtime error
Runtime error
File size: 10,784 Bytes
331f4b7 | 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 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 | """
Validation script for OpenEnv compatibility.
Run this before submitting: python validate.py
"""
import sys
import traceback
from pathlib import Path
from reproagent.environment import ReproAgentEnv
def validate_environment():
"""Validate environment meets OpenEnv requirements."""
print("="*70)
print("π VALIDATING REPROAGENT ENVIRONMENT")
print("="*70)
print()
all_passed = True
# Test 1: Import environment
print("Test 1: Environment Import")
try:
from reproagent.environment import ReproAgentEnv
print(" β
Environment imported successfully")
except Exception as e:
print(f" β Failed to import environment: {e}")
traceback.print_exc()
all_passed = False
return False
# Test 2: Create environment
print("\nTest 2: Environment Creation")
try:
env = ReproAgentEnv(difficulty="easy", max_steps=20, use_llm=False)
print(" β
Environment created")
except Exception as e:
print(f" β Failed to create environment: {e}")
traceback.print_exc()
all_passed = False
return False
# Test 3: Check spaces
print("\nTest 3: Action/Observation Spaces")
try:
assert hasattr(env, 'action_space'), "Missing action_space"
assert hasattr(env, 'observation_space'), "Missing observation_space"
print(f" β
Action space: {env.action_space}")
print(f" β
Observation space: {type(env.observation_space).__name__}")
except Exception as e:
print(f" β Space validation failed: {e}")
all_passed = False
# Test 4: Reset
print("\nTest 4: Reset")
try:
obs, info = env.reset()
assert obs is not None, "Observation is None"
assert isinstance(info, dict), "Info is not dict"
print(" β
Reset successful")
print(f" β
Observation keys: {list(obs.keys())}")
print(f" β
Info keys: {list(info.keys())}")
except Exception as e:
print(f" β Reset failed: {e}")
traceback.print_exc()
all_passed = False
return False
# Test 5: Observation space validation
print("\nTest 5: Observation Space Validation")
try:
assert env.observation_space.contains(obs), "Observation not in space"
print(" β
Observation matches observation_space")
except Exception as e:
print(f" β Observation space mismatch: {e}")
all_passed = False
# Test 6: Action space validation
print("\nTest 6: Action Space Validation")
try:
action = env.action_space.sample()
assert env.action_space.contains(action), "Action not in space"
print(f" β
Sampled action: {action}")
print(f" β
Action is valid")
except Exception as e:
print(f" β Action space validation failed: {e}")
all_passed = False
# Test 7: Step
print("\nTest 7: Step")
try:
obs, reward, terminated, truncated, info = env.step(action)
assert obs is not None, "Observation is None"
assert isinstance(reward, (int, float)), "Reward is not numeric"
assert isinstance(terminated, bool), "Terminated is not bool"
assert isinstance(truncated, bool), "Truncated is not bool"
assert isinstance(info, dict), "Info is not dict"
print(" β
Step successful")
print(f" β
Reward: {reward:.2f}")
print(f" β
Terminated: {terminated}")
print(f" β
Truncated: {truncated}")
except Exception as e:
print(f" β Step failed: {e}")
traceback.print_exc()
all_passed = False
return False
# Test 8: Full episode
print("\nTest 8: Full Episode")
try:
env.reset()
total_reward = 0
steps = 0
for i in range(10):
action = env.action_space.sample()
obs, reward, terminated, truncated, info = env.step(action)
total_reward += reward
steps += 1
if terminated or truncated:
break
print(f" β
Episode completed")
print(f" β
Steps: {steps}")
print(f" β
Total reward: {total_reward:.2f}")
except Exception as e:
print(f" β Episode failed: {e}")
traceback.print_exc()
all_passed = False
# Test 9: Multiple episodes
print("\nTest 9: Multiple Episodes")
try:
for episode in range(3):
env.reset()
for _ in range(5):
action = env.action_space.sample()
obs, reward, terminated, truncated, info = env.step(action)
if terminated or truncated:
break
print(f" β
3 episodes completed successfully")
except Exception as e:
print(f" β Multiple episodes failed: {e}")
traceback.print_exc()
all_passed = False
# Test 10: Render
print("\nTest 10: Render")
try:
env.reset()
output = env.render()
print(" β
Render successful")
except Exception as e:
print(f" β οΈ Render failed (non-critical): {e}")
# Test 11: Close
print("\nTest 11: Close")
try:
env.close()
print(" β
Close successful")
except Exception as e:
print(f" β οΈ Close failed (non-critical): {e}")
# Summary
print("\n" + "="*70)
if all_passed:
print("β
ALL VALIDATION TESTS PASSED!")
print("="*70)
print("\nπ Environment is OpenEnv compatible!")
print("β
Ready for submission")
return True
else:
print("β SOME TESTS FAILED")
print("="*70)
print("\nβ οΈ Please fix errors before submission")
return False
def validate_agents():
"""Validate agents can interact with environment."""
print("\n" + "="*70)
print("π€ VALIDATING AGENTS")
print("="*70)
print()
try:
from reproagent.environment import ReproAgentEnv
from agents.reasoning_agent import create_agent
env = ReproAgentEnv(difficulty="easy", max_steps=10, use_llm=False)
# Test reasoning agent
print("Test: Reasoning Agent")
agent = create_agent(env, "reasoning", use_llm=False)
obs, info = env.reset()
agent.reset()
for i in range(5):
action = agent.select_action(obs, info)
obs, reward, terminated, truncated, info = env.step(action)
if terminated or truncated:
break
print(" β
Reasoning agent works")
# Test random agent
print("\nTest: Random Agent")
random_agent = create_agent(env, "random")
obs, info = env.reset()
random_agent.reset()
for i in range(5):
action = random_agent.select_action(obs, info)
obs, reward, terminated, truncated, info = env.step(action)
if terminated or truncated:
break
print(" β
Random agent works")
print("\nβ
All agents validated successfully")
return True
except Exception as e:
print(f"\nβ Agent validation failed: {e}")
traceback.print_exc()
return False
def validate_demo():
"""Validate Gradio demo can be imported."""
print("\n" + "="*70)
print("π¨ VALIDATING DEMO")
print("="*70)
print()
try:
from server.app import create_demo
print(" β
Demo imported successfully")
print(" βΉοΈ To test demo fully, run: python server/app.py")
return True
except Exception as e:
print(f" β Demo import failed: {e}")
traceback.print_exc()
return False
def validate_graders():
"""Validate grading system."""
print("\n" + "="*70)
print("π VALIDATING GRADERS")
print("="*70)
print()
try:
from graders.graders import ReproductionGrader
print(" β
Grader imported successfully")
return True
except Exception as e:
print(f" β Grader import failed: {e}")
traceback.print_exc()
return False
def validate_openenv_yaml():
"""Validate openenv.yaml exists."""
print("\n" + "="*70)
print("π VALIDATING openenv.yaml")
print("="*70)
print()
yaml_path = Path("openenv.yaml")
if yaml_path.exists():
print(" β
openenv.yaml exists")
try:
import yaml
with open(yaml_path) as f:
config = yaml.safe_load(f)
required_keys = ['name', 'environment', 'observation_space', 'action_space']
for key in required_keys:
if key in config:
print(f" β
Has '{key}'")
else:
print(f" β οΈ Missing '{key}'")
return True
except Exception as e:
print(f" β οΈ Could not parse YAML: {e}")
return True # Non-critical
else:
print(" β οΈ openenv.yaml not found (will need to create)")
return True # Non-critical for now
def main():
"""Run all validation tests."""
print("\n" + "π"*35)
print("REPROAGENT VALIDATION SUITE")
print("π"*35 + "\n")
results = {
'environment': validate_environment(),
'agents': validate_agents(),
'demo': validate_demo(),
'graders': validate_graders(),
'openenv_yaml': validate_openenv_yaml()
}
# Final summary
print("\n" + "="*70)
print("π VALIDATION SUMMARY")
print("="*70)
for component, passed in results.items():
status = "β
PASSED" if passed else "β FAILED"
print(f"{component.upper():<20} {status}")
print("="*70)
if all(results.values()):
print("\nπ ALL VALIDATIONS PASSED!")
print("β
System is ready for deployment")
return 0
else:
print("\nβ οΈ SOME VALIDATIONS FAILED")
print("Please fix errors before proceeding")
return 1
if __name__ == "__main__":
sys.exit(main())
|