ποΈββοΈ 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.6 |
πFeatures
- Set of APIs to implement OpenAI Gym interface
- REST API to control an agent
- Rendering to RAM membuffer
π Changelog
- 0.8.4
- Added object representation of observation space
- 0.9.1
- Bevy v.0.9 support
- Minor changes in
Derefergonomics
- 0.9.3
- Fixed a bug when
AIGymStatecould not be initialized outside of the crate
- Fixed a bug when
- 0.9.4
- Option to use crate without camera rendering to buffer
- 0.9.5, 0.9.6
- Fixed a regression introduces in 0.8.4
π©βπ» Usage
1. Define App States
Environment needs to have multiple states, where different system are executed. Typically you will need to implement InGame, Control and Reset states.
2. Define Action Space and Observation Space
Observation space needs to be Serializable because it's exported via REST API.
// Action space
// Observation space
3. Enable AI Gym Plugin
Width and height should exceed 256, otherwise wgpu will panic.
let gym_settings = AIGymSettings ;
app
.insert_resource
.insert_resource
.add_plugin
3.1 (Optional) Enable Rendering to Buffer
pub
4. Implement Environment Logic
DelayedControlTimer should pause environment execution to allow agents to take actions.
;
Define systems that implement environment logic.
app.add_startup_system;
app.add_system_set;
app.insert_resource; // 10 Hz
app.add_system_set;
app.add_system_set;
control_switch should pause game world and poll bevy_rl for agent actions.
pub
process_reset_request handles environment reset request.
pub
turnbased_text_control_system parses agent actions and issues commands to agents in environment.
pub
π» AIGymState API
| Method | Description |
|---|---|
send_step_result(results: Vec<bool>) |
Send upon agents interactions are complete |
send_reset_result(result: bool) |
Send when reset request is complete |
receive_action_strings(Vec<Option<String>>) |
Recieve environment for agent actions |
receive_reset_request() |
Recieve environment for reset request |
is_next_action() -> bool |
Whether agent actions are supplied |
is_reset_request() -> bool |
Whether reset request was sent |
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