Giter VIP home page Giter VIP logo

zombie-einstein / flock_env Goto Github PK

View Code? Open in Web Editor NEW
11.0 3.0 2.0 9.89 MB

Boid flock multi-agent RL training environment implemented in JAX

Home Page: https://zombie-einstein.github.io/2020/09/26/rl_flock.html

Python 2.28% Jupyter Notebook 97.72%
rl-agents multi-agent-environment flock flock-environment multiple-homogenous-agents agen multi-agent-reinforcement-learning reinforcement-learning rl-environment jax

flock_env's Introduction

Flock Multi Agent RL Environment

Multi-agent RL environment based on Boids, implemented with JAX

alt text

The environment is based on popular boids model where agents recreate flocking behaviours based on simple interaction rules. The environment implements boids as a multi-agent reinforcement problem where each boid takes individual actions and have a individual localised view of the environment.

This environment has been built around the gymnax API (a JAX version of the popular RL Gym API):

import flock_env
import jax

key = jax.random.PRNGKey(101)
key_reset, key_act, key_step = jax.random.split(key)

# Initialise a flock environment with 10 agents
env = flock_env.SimpleFlockEnv(
    reward_func=flock_env.rewards.exponential_rewards,
    n_agents=10
)
env_params = env.default_params

# Reset the environment and get state and observation
obs, state = env.reset(key_reset, env_params)
# Sample random action for agents
actions = jax.random.uniform(key_act, (10, 2))
# Step the environment
new_obs, new_state, rewards, dones, _ = env.step_env(
    key_step, state, actions, env_params
)

Usage

See examples/ppo_example.ipynb for an example of training a Proximal-Policy-Optimisation based agent with this environment (using my JAX implementation of PPO).

The package can and requirements can be installed using poetry by running

poetry install

โš ๏ธ Generating observations currently compares all pairs of agents so performance scales as $n^2$ with the number of agents. This means performance may not be great past hundreds of agents.

TODO

  • More complex observation spaces, e.g. ray-casting view model
  • Objects/obstacles in the environment
  • More efficient agent observation generation

Previous Version

The previous version of this project built around Numba can be found in /deprecated

Developers

Pre-Commit Hooks

Pre commit hooks can be installed by running

pre-commit install

Pre-commit checks can then be run using

task lint

Tests

Tests can be run with

task test

flock_env's People

Contributors

zombie-einstein avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

flock_env's Issues

Request

Hi @zombie-einstein,

I have a private question concerning this repository, is it possible to contact you via e-mail?

Kind regards

How long did it take to train?

Really cool project! How long did it take to train the RL agent? Do you know of similar work on multi-agent RL simulations of artificial life?

Request

Hi @zombie-einstein ,

I have a some private questions concerning this repository, is it possible to contact you via e-mail?

Thank you,
Kind regards

Help with similar project

Hello,

I was working on a project about flocking similar to yours and was stuck a bit. I wanted to ask if you could just lend me a couple of pointers if it's no trouble.

Regards,
Hamza

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.