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] MultiAgentEnv API enhancements (related to defining obs-/action spaces for agents). #47830

Merged

Conversation

sven1977
Copy link
Contributor

@sven1977 sven1977 commented Sep 26, 2024

MultiAgentEnv API enhancements (related to defining obs-/action spaces for agents).

The MultiAgentEnv API gets the following face-lift:

  • The MultiAgentEnv will have a new get_observation_space(agent_id=...) method, which is the only path that RLlib will use to get an agent's space.
  • We remove/deprecate other methods to simplify the MultiAgentEnv class a bit. E.g. observation_space_sample() .
  • If users want (b/c they have a lot of agents, some of which share the same spaces), users can now override this method in MultiAgentEnv and always return the correct (single-agent) space for the given agent_id. This relieves one from having to include all agent IDs in the agent-to-space dict. In fact, you don't even have to define such a dict anymore at all.
  • Alternatively to overriding get_observation_space(), one can define self.observation_spaces (plural!) to be a dict mapping AgentIDs to individual spaces (<- currently the only supported mechanism).
  • Alternatively to overriding get_observation_space(), one can define self.observation_space (singular!) to be a single observation space that applies to all agents in the env (<- "lazy" mechanism for when all agents have the same space anyways).

^ Exact same for action spaces.

On top of that, to make things more explicit and more similar to PettingZoo, we should also require users to provide the two attributes in their MultiAgentEnv

self.agents = [list of agents currently in the episode]
self.possible_agents = [list of all possible agent that can ever appear in any episode]

The method self.get_agent_ids() will be deprecated soon (replaced by self.agents or self.possible_agents).
The private attribute self._agent_ids will be deprecated soon (replaced by self.agents or self.possible_agents).

Why are these changes needed?

Related issue number

Checks

  • I've signed off every commit(by using the -s flag, i.e., git commit -s) in this PR.
  • I've run scripts/format.sh to lint the changes in this PR.
  • I've included any doc changes needed for https://docs.ray.io/en/master/.
    • I've added any new APIs to the API Reference. For example, if I added a
      method in Tune, I've added it in doc/source/tune/api/ under the
      corresponding .rst file.
  • I've made sure the tests are passing. Note that there might be a few flaky tests, see the recent failures at https://flakey-tests.ray.io/
  • Testing Strategy
    • Unit tests
    • Release tests
    • This PR is not tested :(

Signed-off-by: sven1977 <svenmika1977@gmail.com>
Signed-off-by: sven1977 <svenmika1977@gmail.com>
Signed-off-by: sven1977 <svenmika1977@gmail.com>
Copy link
Collaborator

@simonsays1980 simonsays1980 left a comment

Choose a reason for hiding this comment

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

LGTM. We should test, if checkpointing runs error-free with these changes. I don't see an obvious problem, but let's quickly check this.

def render(self) -> None:
"""Tries to render the environment."""
@property
def num_agents(self) -> int:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice!!

# By default, do nothing.
pass
@property
def max_num_agents(self) -> int:
Copy link
Collaborator

Choose a reason for hiding this comment

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

This might also help in the sampling from MultiAgentEpisodeBuffers

Signed-off-by: sven1977 <svenmika1977@gmail.com>
@sven1977 sven1977 enabled auto-merge (squash) September 27, 2024 10:41
@github-actions github-actions bot added the go add ONLY when ready to merge, run all tests label Sep 27, 2024
Signed-off-by: sven1977 <svenmika1977@gmail.com>
Signed-off-by: sven1977 <svenmika1977@gmail.com>
Signed-off-by: sven1977 <svenmika1977@gmail.com>
@sven1977 sven1977 enabled auto-merge (squash) September 27, 2024 16:07
Signed-off-by: sven1977 <svenmika1977@gmail.com>
Signed-off-by: sven1977 <svenmika1977@gmail.com>
@sven1977 sven1977 enabled auto-merge (squash) September 28, 2024 13:22
Signed-off-by: sven1977 <svenmika1977@gmail.com>
Signed-off-by: sven1977 <svenmika1977@gmail.com>
@sven1977 sven1977 enabled auto-merge (squash) September 28, 2024 18:48
@sven1977 sven1977 merged commit e07594e into ray-project:master Sep 28, 2024
6 checks passed
@sven1977 sven1977 added rllib RLlib related issues rllib-multi-agent An RLlib multi-agent related problem. labels Sep 29, 2024
@sven1977 sven1977 added rllib-env rllib env related issues rllib-newstack labels Sep 29, 2024
@sven1977 sven1977 deleted the multi_agent_env_space_enhancements branch September 29, 2024 09:41
ujjawal-khare pushed a commit to ujjawal-khare-27/ray that referenced this pull request Oct 15, 2024
…on spaces for agents). (ray-project#47830)

Signed-off-by: ujjawal-khare <ujjawal.khare@dream11.com>
ujjawal-khare pushed a commit to ujjawal-khare-27/ray that referenced this pull request Oct 15, 2024
…on spaces for agents). (ray-project#47830)

Signed-off-by: ujjawal-khare <ujjawal.khare@dream11.com>
ujjawal-khare pushed a commit to ujjawal-khare-27/ray that referenced this pull request Oct 15, 2024
…on spaces for agents). (ray-project#47830)

Signed-off-by: ujjawal-khare <ujjawal.khare@dream11.com>
ujjawal-khare pushed a commit to ujjawal-khare-27/ray that referenced this pull request Oct 15, 2024
…on spaces for agents). (ray-project#47830)

Signed-off-by: ujjawal-khare <ujjawal.khare@dream11.com>
ujjawal-khare pushed a commit to ujjawal-khare-27/ray that referenced this pull request Oct 15, 2024
…on spaces for agents). (ray-project#47830)

Signed-off-by: ujjawal-khare <ujjawal.khare@dream11.com>
ujjawal-khare pushed a commit to ujjawal-khare-27/ray that referenced this pull request Oct 15, 2024
…on spaces for agents). (ray-project#47830)

Signed-off-by: ujjawal-khare <ujjawal.khare@dream11.com>
ujjawal-khare pushed a commit to ujjawal-khare-27/ray that referenced this pull request Oct 15, 2024
…on spaces for agents). (ray-project#47830)

Signed-off-by: ujjawal-khare <ujjawal.khare@dream11.com>
ujjawal-khare pushed a commit to ujjawal-khare-27/ray that referenced this pull request Oct 15, 2024
…on spaces for agents). (ray-project#47830)

Signed-off-by: ujjawal-khare <ujjawal.khare@dream11.com>
ujjawal-khare pushed a commit to ujjawal-khare-27/ray that referenced this pull request Oct 15, 2024
…on spaces for agents). (ray-project#47830)

Signed-off-by: ujjawal-khare <ujjawal.khare@dream11.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
go add ONLY when ready to merge, run all tests rllib RLlib related issues rllib-env rllib env related issues rllib-multi-agent An RLlib multi-agent related problem. rllib-newstack
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants