Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

multiple DQN trained agents for a single environment #1

Open
indhra opened this issue Apr 24, 2020 · 7 comments
Open

multiple DQN trained agents for a single environment #1

indhra opened this issue Apr 24, 2020 · 7 comments

Comments

@indhra
Copy link

indhra commented Apr 24, 2020

@blavad
thanks for the huge repo

hi i have a query

i would like to train two agents with DQN of same environment, but independent of them (agents)
is it possible, if so help me out

thanks for the huge repo

@indhra
Copy link
Author

indhra commented Apr 24, 2020

its kind of competitive between agent A vs agent B of same environment

@blavad
Copy link
Owner

blavad commented Apr 24, 2020

Hi @indhra007 .
Indeed it is totally possible to train two independant agents with DQN algorithm. All you have to do is to :

  1. Instantiate your OpenAI Gym like environment and get observation and action space for both agents (if they have different observation and/or action space)
import marl
from marl.agent import DQNAgent

env = my_env()

# This part may depend of the implementation of the environment
obs_space1 = env.observation_space[0]
act_space1 = env.action_space[0]

obs_space2 = env.observation_space[1]
act_space2 = env.action_space[1]
  1. Instantiate two DQNAgent with the best training parameters for each. Easiest way to do (with neither custom parameters nor custom model) is as follow:
agent1 = DQNAgent("MlpNet", obs_space1, act_space1)
print("#> Agent 1 :\n", agent1, "\n")

agent2 = DQNAgent("MlpNet", obs_space2, act_space2)
print("#> Agent 2 :\n", agent2, "\n")
  1. Instantiate your multi-agent system for reinforcement learning. If the agents are independant learners, you don't need to use set_mas() function because it means that they don't need to know local information about other agents (i.e. policies of other agents):
mas = MARL(agents_list=[agent1, agent2])
  1. Train and test your system
# Train the agent for 100 000 timesteps
mas.learn(env, nb_timesteps=100000)

# Test the agent for 10 episodes
mas.test(env, nb_episodes=10)

I hope this will help you. I continue to implement some module for this API and I hope I will have time
to improve the documentation in order to provide more usefull examples.

@indhra
Copy link
Author

indhra commented Apr 24, 2020

@blavad thanks for quick reply

If possible can u share an environment which has multi agents-with some documentation

@blavad
Copy link
Owner

blavad commented Apr 26, 2020

@indhra007 sorry for the late answer. In order to avoid problems of importing packages when using notebook, go to the marl directory before installing it.
If you are using a Notebook or Google Colab, the following lines should fix the problem:

!git clone https://github.com/blavad/marl.git
%cd marl
!pip install -e .

or

!git clone https://github.com/blavad/marl.git
!cd marl
!pip install -e .

If you are using command line, something as follow should work:

git clone https://github.com/blavad/marl.git
cd marl
pip install -e .

@indhra
Copy link
Author

indhra commented Apr 27, 2020

@blavad Any multi agent environment other than soccer,
Because of no soccer documentation it is not possible to understand

@blavad
Copy link
Owner

blavad commented Apr 27, 2020

@indhra007 For the moment I cannot share another well documented environment. I am currently working with another environment (for the game Hanabi) but it is not online yet.
You can check to this section of the documentation (https://blavad.github.io/marl/html/quickstart/environment.html) for a brief review of how to build an adequate environment.

I will let you know as soon as I make a repo with some multi-agent environments.

@indhra
Copy link
Author

indhra commented Apr 27, 2020

Ok
Does the soccer environment works?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants