How dt-g7/lunar_lander_ai works
Main Components
• Environment & Simulation Module:
• The core environment is implemented in src/lunar_lander/Lunar_Lander_custom_env.py.
• The physics simulation is defined in src/lunar_lander/physics.py.
• Rendering is handled in src/lunar_lander/rendering.py using Pygame.
• Training Module:
• The training script (src/lunar_lander/custom_run.py) uses Stable-Baselines3 PPO to interact with the custom environment.
• The PPO model receives state observations from the environment (6-dimensional: dx, dy, x_velocity, y_velocity, angle, angular_velocity) and sends actions (continuous thrust and torque) back.
• Model Management:
• Models are saved and stored in directories such as custom_lunar (for “best” model checkpoints) and models/PPO (with many iteration checkpoints).
• Utility scripts (load.py and load_model_not_trained.py) are provided for loading pre-trained or untrained models.
• Logging & Monitoring:
• The logs/ directory captures TensorBoard logs generated during training.
Relationships and Interactions
• The Training Module (custom_run.py) interacts with:
• The Environment Module (Lunar_Lander_custom_env.py, physics.py, rendering.py) to simulate each training episode.
• The PPO agent from Stable-Baselines3 which computes updates from state transitions, rewards, and actions.
• The Model Management layer:
• Saves periodic checkpoints and best models.
• Provides loading pathways (through load.py and load_model_not_trained.py).
• Logging:
• Continuously records training events and metrics; data flows to TensorBoard when executed via tensorboard --logdir logs.
• External Dependencies:
• The system relies on external libraries such as Box2D and Pygame for simulation and rendering, Gymnasium for environment interface, and Stable-Baselines3 for the learning algorithm.
Architectural Patterns and Design Principles
• Modularity: The project is segmented into clearly defined modules (environment, physics, rendering, training, logging, model loading) that can be diagrammed separately.
• Separation of Concerns: Core environment simulation (physics and rendering) is decoupled from the training logic, which in turn is separate from model management.