Environment Tools

Environment Tools provides a comprehensive set of utilities for developing, testing, and debugging AI environments within the synth-ai framework.

Overview

The tools suite includes:
  • Environment Testing: Automated testing utilities
  • Visualization: Rendering and debugging tools
  • Performance Profiling: Environment performance analysis
  • State Inspection: Tools for examining environment state
  • Reproducibility: Utilities for deterministic testing

Testing Utilities

Environment Validator

Test environment compliance with synth-ai standards:
from synth_ai.environments.tools import EnvironmentValidator

validator = EnvironmentValidator()

# Test a single environment
results = validator.validate(MyEnvironment())
if results.is_valid:
    print("Environment is valid!")
else:
    print("Validation errors:", results.errors)

Automated Testing

Run comprehensive test suites:
from synth_ai.environments.tools import EnvironmentTester

tester = EnvironmentTester()

# Basic functionality tests
test_results = tester.run_basic_tests(MyEnvironment())

# Custom test suite
@tester.test_case("custom_behavior")
def test_custom_behavior(env):
    """Test custom environment behavior."""
    obs = env.reset()
    action = env.action_space.sample()
    next_obs, reward, done = env.step(action)
    
    assert obs is not None
    assert isinstance(reward, (int, float))
    assert isinstance(done, bool)

results = tester.run_all_tests(MyEnvironment())

Visualization Tools

Environment Renderer

Visualize environment state and agent actions:
from synth_ai.environments.tools import EnvironmentRenderer

renderer = EnvironmentRenderer(MyEnvironment())

# Render current state
image = renderer.render(mode="rgb_array")

# Record episode as video
renderer.start_recording("episode.mp4")
for step in range(100):
    action = agent.act(observation)
    observation, reward, done = env.step(action)
    renderer.record_frame()
    if done:
        break
renderer.stop_recording()

Performance Profiling

Environment Profiler

Analyze environment performance:
from synth_ai.environments.tools import EnvironmentProfiler

profiler = EnvironmentProfiler()

# Profile environment performance
with profiler.profile(MyEnvironment()) as env:
    for _ in range(1000):
        action = env.action_space.sample()
        env.step(action)

# Get performance report
report = profiler.get_report()
print(f"Average step time: {report.avg_step_time:.4f}s")
print(f"Memory usage: {report.memory_usage:.2f}MB")