ποΈββοΈ bevy_rl

ποΈ Build π€ Reinforcement Learning ππΏββοΈ Gym environments with π Bevy engine to train πΎ AI agents that π‘ can learn from πΊ screen pixels or defined obeservation state.
Compatibility
| bevy version | bevy_rl version |
|---|---|
| 0.7 | 0.0.5 |
| 0.8 | 0.8.4 |
| 0.9 | 0.9.8-beta |
πFeatures
- Set of APIs to implement OpenAI Gym interface
- REST API to control an agent
- Rendering to RAM membuffer
π©βπ» Usage
1. Define Action and Obeservation Space
Observation space needs to be Serializable for REST API to work.
// Action space
// Observation space
2. Enable AI Gym Plugin
Width and height should exceed 256, otherwise wgpu will panic.
// Setup bevy_rl
let ai_gym_state = new;
app.insert_resource
.add_plugin;
2.1 (Optional) Enable Rendering to Buffer
If your environment exports raw pixels, you will need to attach a render target to each camera of your agents.
pub
4. Handle bevy_rl events
| Event | Description |
|---|---|
EventReset |
Reset environment to initial state |
EventControl |
Switch to control state |
EventPauseResume |
Pause or resume environment execution |
// EventPauseResume
// EventControl
Register systems to handle bevy_rl events.
// bevy_rl events
app.add_system;
app.add_system;
π» AIGymState API
| Method | Description |
|---|---|
set_reward(agent_index: usize, score: f32) |
Set reward for an agent |
set_terminated(agent_index: usize, result: bool) |
Set termination status for an agent |
reset() |
Reset bevy_rl state |
set_env_state(state: State) |
Set current environment state |
π REST API
| Method | Verb | bevy_rl version |
|---|---|---|
| Camera Pixels | GET | http://localhost:7878/visual_observations |
| State | GET | http://localhost:7878/state |
| Reset Environment | POST | http://localhost:7878/reset |
| Step | GET | http://localhost:7878/step payload=ACTION |
βοΈ Examples
- bevy_rl_shooter β example FPS project
- bevy_quadruped_neural_control β quadruped locomotion with bevy_mujoco and bevy_rl