Spaces:
Runtime error
Runtime error
File size: 4,348 Bytes
6083286 |
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 |
"""
Main entry point for the Drone RL project.
Tests imports and basic functionality.
"""
import sys
import numpy as np
print("=" * 50)
print("Drone RL Project - Import Test")
print("=" * 50)
# Test PyTorch
try:
import torch
print(f"β PyTorch {torch.__version__} imported successfully")
print(f" CUDA available: {torch.cuda.is_available()}")
except ImportError as e:
print(f"β PyTorch import failed: {e}")
sys.exit(1)
# Test NumPy
try:
print(f"β NumPy {np.__version__} imported successfully")
except ImportError as e:
print(f"β NumPy import failed: {e}")
sys.exit(1)
# Test Gymnasium
try:
import gymnasium as gym
print(f"β Gymnasium {gym.__version__} imported successfully")
# Test creating a simple environment
try:
env = gym.make("CartPole-v1")
print(f"β Gymnasium environment 'CartPole-v1' created successfully")
env.close()
except Exception as e:
print(f"β Could not create test environment: {e}")
except ImportError as e:
print(f"β Gymnasium import failed: {e}")
sys.exit(1)
# Test Stable-Baselines3
try:
import stable_baselines3
print(f"β Stable-Baselines3 imported successfully")
except ImportError as e:
print(f"β Stable-Baselines3 import failed: {e}")
print(" (This is optional, you can use cleanrl instead)")
# Test Pygame
pygame_works = False
try:
import pygame
print(f"β Pygame {pygame.__version__} imported successfully")
# Try to initialize pygame
try:
pygame.init()
print("β Pygame initialized successfully")
# Create a test window
screen = pygame.display.set_mode((640, 480))
pygame.display.set_caption("Drone RL - Pygame Test")
print("β Pygame window created successfully")
print(" Window should be visible. Close it to continue...")
# Keep window open briefly, then close
import time
clock = pygame.time.Clock()
running = True
start_time = time.time()
while running and (time.time() - start_time) < 2.0: # Show for 2 seconds
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
screen.fill((50, 50, 50)) # Dark gray background
font = pygame.font.Font(None, 36)
text = font.render("Pygame Works!", True, (255, 255, 255))
text_rect = text.get_rect(center=(320, 240))
screen.blit(text, text_rect)
pygame.display.flip()
clock.tick(60)
pygame.quit()
pygame_works = True
print("β Pygame window test completed successfully")
except Exception as e:
print(f"β Pygame initialization failed: {e}")
pygame.quit()
except ImportError as e:
print(f"β Pygame import failed: {e}")
# Fallback to matplotlib if pygame failed
if not pygame_works:
print("\n" + "=" * 50)
print("Falling back to matplotlib animation...")
print("=" * 50)
try:
import matplotlib.pyplot as plt
import matplotlib.animation as animation
print("β Matplotlib imported successfully")
# Create a simple animation
fig, ax = plt.subplots()
ax.set_xlim(0, 10)
ax.set_ylim(0, 10)
ax.set_title("Drone RL - Matplotlib Test")
line, = ax.plot([], [], 'o-', lw=2)
def animate(frame):
x = np.linspace(0, 10, 100)
y = np.sin(x + frame * 0.1) * 5 + 5
line.set_data(x, y)
return line,
anim = animation.FuncAnimation(fig, animate, frames=100, interval=50, blit=True)
print("β Matplotlib animation created")
print(" Animation window should be visible. Close it to continue...")
plt.show(block=False)
# Keep it open briefly
import time
time.sleep(2)
plt.close()
print("β Matplotlib animation test completed successfully")
except ImportError as e:
print(f"β Matplotlib import failed: {e}")
print(" Please install matplotlib: pip install matplotlib")
print("\n" + "=" * 50)
print("All tests completed!")
print("=" * 50)
|