| import requests |
| import json |
| import time |
| import numpy as np |
|
|
| BASE_URL = "http://localhost:5002" |
|
|
| def debug_server(): |
| print(f"Testing Server at {BASE_URL}...") |
|
|
| |
| try: |
| resp = requests.get(f"{BASE_URL}/health") |
| print("Health Check:", resp.json()) |
| except Exception as e: |
| print(f"Cannot connect to server: {e}") |
| return |
|
|
| |
| |
| |
| |
| |
| env_ids = [f"debug_env_{i}" for i in range(4)] |
| ids2configs = { |
| eid: { |
| "env_name": "sokoban", |
| |
| } |
| for eid in env_ids |
| } |
|
|
| print(f"\nCreating {len(env_ids)} environments...") |
| resp = requests.post(f"{BASE_URL}/environments", json={"ids2configs": ids2configs}) |
| if resp.status_code != 200: |
| print("Create failed:", resp.text) |
| return |
| print("Success.") |
|
|
| |
| print("\nResetting environments (This usually triggers Vulkan errors)...") |
| ids2seeds = {eid: 42 + i for i, eid in enumerate(env_ids)} |
| |
| start_time = time.time() |
| resp = requests.post(f"{BASE_URL}/batch/reset", json={"ids2seeds": ids2seeds}) |
| |
| if resp.status_code != 200: |
| print("Reset failed:", resp.text) |
| else: |
| results = resp.json().get("results", {}) |
| print(f"Reset success! Took {time.time() - start_time:.2f}s") |
| |
| first_obs = list(results.values())[0][0] |
| |
| if isinstance(first_obs, dict) and 'image' in first_obs: |
| print(f"Obs Image Shape: {np.array(first_obs['image']).shape}") |
| else: |
| print("Obs structure keys:", first_obs.keys() if isinstance(first_obs, dict) else "Not a dict") |
|
|
| |
| print("\nStepping environments...") |
| |
| |
| ids2actions = {eid: "move up" for eid in env_ids} |
| |
| resp = requests.post(f"{BASE_URL}/batch/step", json={"ids2actions": ids2actions}) |
| if resp.status_code == 200: |
| print("Step success.") |
| else: |
| print("Step failed:", resp.text) |
|
|
| |
| print("\nClosing environments...") |
| requests.post(f"{BASE_URL}/batch/close", json={"env_ids": env_ids}) |
| print("Done.") |
|
|
| if __name__ == "__main__": |
| debug_server() |