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

[rllib] ExternalMultiAgentEnv #4200

Merged

Conversation

ctombumila37
Copy link
Contributor

@ctombumila37 ctombumila37 commented Feb 28, 2019

What do these changes do?

Create a combination of ExternalEnv and MultiAgentEnv, called ExternalMutliAgentEnv

Related issue number

#4051

Please note that this PR is by far not finished.

For things that do not work (yet), see the commit messages.

I am a novice in ray / rllib, thus I would appreciate any help with this :)

To Do

  • move the functionality of _ExternalMultiAgentEnvEpisode into _ExternalEnvEpisode
  • add a unit test in test_external_env that exercises multi-agent external envs

ctombumila37 and others added 4 commits February 26, 2019 15:41
- self.cur_reward  in _ExternalEnvEpisode
  for some reason has to know
  the ids of all possible agents
  (serving multiagent example)
- the thread of ExternalMultiAgentEnv
  gets started multiple times, thus
  ppo.train() deadlocks in the example
@AmplabJenkins
Copy link

Test FAILed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/12391/
Test FAILed.

@ericl
Copy link
Contributor

ericl commented Mar 1, 2019

Hey, thanks for getting started on this. One idea: is it possible to add multi-agent to the existing external env adapter in a backwards compatible way? For example, adding option arguments to specify an agent id. That way, there could be less code duplication between the two envs.

introduce a flag 'multiagent' in _ExternalEnvToBaseEnv
to reduce code duplication.
@AmplabJenkins
Copy link

Test FAILed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/12417/
Test FAILed.

@AmplabJenkins
Copy link

Test FAILed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/12425/
Test FAILed.

@ctombumila37 ctombumila37 changed the title [rllib] ExternalMutliAgentEnv [rllib] [WIP] ExternalMutliAgentEnv Mar 2, 2019
return episode_id

@PublicAPI
def get_action(self, episode_id, observation):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One design decision here is whether you should be getting the action of multiple agents at once (as opposed to one at a time).

I think it may be easier to enforce all the observations of all agents acting for the "episode step" must be provided at once in this call. Otherwise, it becomes unclear which agent actions go in which episode timestep.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While I think it would be easier to enforce an observation of all agents in one call to get_action(...), this would not allow the same "level" of asynchronism as offered with MultiAgentEnv, right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm I was thinking you could allow a subset to be passed in. Similar to how step() in MultiAgentEnv returns a subset of the agents in the env, get_action() could take a subset of the agents as well. So the level of asynchrony would be matching.

Copy link
Contributor Author

@ctombumila37 ctombumila37 Mar 27, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense, thanks for clarification.

As the logic of ExternalMultiAgentEnv would then be analogous to MultiAgentEnv, I'd opt for that.
Currently, this is working as expected: one can pass in a subset of agent observations and get that subset of agent actions back.



@PublicAPI
class ExternalMultiAgentEnv(threading.Thread):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this extend ExternalEnv?

Copy link
Contributor Author

@ctombumila37 ctombumila37 Mar 27, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only differences I see between ExternalEnv and ExternalMultiAgentEnv are argument types in the method signatures (e.g. action vs. action_dict), so this should be ok?

@richardliaw richardliaw changed the title [rllib] [WIP] ExternalMutliAgentEnv [rllib] [WIP] ExternalMultiAgentEnv Mar 10, 2019
@AmplabJenkins
Copy link

Can one of the admins verify this patch?

1 similar comment
@AmplabJenkins
Copy link

Can one of the admins verify this patch?

@ericl
Copy link
Contributor

ericl commented Mar 18, 2019

@ctombumila37 any update? I can try to help out here unless you've got changes not yet pushed.

@AmplabJenkins
Copy link

Test PASSed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/12980/
Test PASSed.

@AmplabJenkins
Copy link

Test PASSed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/13039/
Test PASSed.

@AmplabJenkins
Copy link

Test FAILed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/13045/
Test FAILed.

@ctombumila37 ctombumila37 force-pushed the feature/external_multi_agent_env branch from 5a704bf to d0431ac Compare March 27, 2019 10:48
@AmplabJenkins
Copy link

Test FAILed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/13322/
Test FAILed.

@ericl
Copy link
Contributor

ericl commented Mar 28, 2019

@ctombumila37 I saw the new updates, is this ready to review? Any other issues you've found?

@ctombumila37
Copy link
Contributor Author

Yes, I hit no other issues.

Should I remove my copy-pasta MultiCartpole-Serving example?

@ctombumila37 ctombumila37 marked this pull request as ready for review March 29, 2019 15:46
Copy link
Contributor

@ericl ericl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking pretty good.

  1. Let's remove the examples as noted (instead, a unit test in test_external_env will suffice).
  2. I have some comments on further removing some duplication for the _ExternalEnvEpisode helper class.

python/ray/rllib/env/base_env.py Outdated Show resolved Hide resolved
python/ray/rllib/evaluation/policy_evaluator.py Outdated Show resolved Hide resolved
self, action_space, observation_space, max_concurrent)

# we require to know all agents' spaces
if isinstance(self.action_space, dict) or isinstance(self.observation_space, dict):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed sometimes you pass in None for the spaces here -- should that be allowed?

python/ray/rllib/env/external_multi_agent_env.py Outdated Show resolved Hide resolved
python/ray/rllib/env/external_multi_agent_env.py Outdated Show resolved Hide resolved
@AmplabJenkins
Copy link

Test FAILed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/13365/
Test FAILed.

@AmplabJenkins
Copy link

Test FAILed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/13367/
Test FAILed.

Remove multiagent cartpole examples.
@AmplabJenkins
Copy link

Test FAILed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/13412/
Test FAILed.

@AmplabJenkins
Copy link

Test FAILed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/13435/
Test FAILed.

@AmplabJenkins
Copy link

Test FAILed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/13436/
Test FAILed.

@AmplabJenkins
Copy link

Test PASSed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/13441/
Test PASSed.

@ericl ericl self-assigned this Apr 3, 2019
Copy link
Contributor

@ericl ericl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great! I think we can merge once the unit test is added.

@AmplabJenkins
Copy link

Test FAILed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/13552/
Test FAILed.

Copy link
Contributor

@ericl ericl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I pushed some lint fixes

@ericl ericl changed the title [rllib] [WIP] ExternalMultiAgentEnv [rllib] ExternalMultiAgentEnv Apr 7, 2019
@AmplabJenkins
Copy link

Test FAILed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/13608/
Test FAILed.

@ericl ericl merged commit 7746d20 into ray-project:master Apr 7, 2019
@ericl
Copy link
Contributor

ericl commented Apr 7, 2019

Tests look good, thanks for contributing this!

@ctombumila37 ctombumila37 deleted the feature/external_multi_agent_env branch April 13, 2019 20:15
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

Successfully merging this pull request may close these issues.

3 participants