ποΈββοΈ bevy_rl
ποΈ Build π€ Reinforcement Learning ππΏββοΈ Gym environments with π Bevy engine to train πΎ AI agents that π‘ learn from πΊ screen pixels.
Compatibility
| bevy version | bevy_rl version |
|---|---|
| 0.7 | 0.0.5 |
| 0.8 | 0.8.4 |
| 0.9 | 0.9.4 |
π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
π©βπ» Usage
1. Define App States
2. Define Action Space and Observation Space
A action space is a set of actions that an agent can take. An observation space is a set of observations that an agent can see. Action space can be discrete or continuous. Observations should be serializable to JSON with serde_json crate.
// Action space
// Observation space
3. Enable AI Gym Plugin
Width and hight should exceed 256, otherwise wgpu will panic.
let gym_settings = AIGymSettings ;
app
.insert_resource
.insert_resource
.add_plugin
4. Implement Environment Logic
DelayedControlTimer should pause environment execution to allow agents to take actions.
;
Define systems that implement environment logic.
app.add_system_set;
app.insert_resource; // 10 Hz
app.add_system_set;
turnbased_control_system_switchshould pause game world and pollbevy_rlfor agent actions.execute_reset_requesthandles environment reset request.turnbased_text_control_systemparses agent actions and issues commands to agents in environment.
π» 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: B) |
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