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; docs] Docs do-over (new API stack): Env pages vol 01. #49165

Merged

Conversation

sven1977
Copy link
Contributor

@sven1977 sven1977 commented Dec 9, 2024

[RLlib] Docs do-over (new API stack): Env pages vol 01

  • new sigils/logos for upcoming split-structure (single-, multi-agent, external & hierarchical)
  • more example scripts for simultaneous and turn-based multi-agent acting patterns (added to CI)
  • remove old API stack env APIs no longer needed
  • Move example multi-agent env classes into their own subfolder in examples/envs/classes/multi_agent/..

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 <[email protected]>
@@ -0,0 +1,20 @@
from ray.rllib.env.multi_agent_env import make_multi_agent
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Simply moved some example classes in here for order.

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. Awesome PR!

Copy link
Collaborator

Choose a reason for hiding this comment

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

In the long run we should ask for a professional designer to make these diagrams.

Copy link
Collaborator

Choose a reason for hiding this comment

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

So, does this wants to say that the top agent is acting whenever the lower ones are not or could this happen simultaneously?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Both is possible. Our example script has always only one level acting at a time.

"""Two-player environment for the famous rock paper scissors game.

# __sphinx_doc_1_end__
Optionally, the "Sheldon Cooper extension" can be activated by passing
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hilarious! :D


# The observations are always the last taken actions. Hence observation- and
# action spaces are identical.
self.observation_spaces = self.action_spaces = {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe simplify to:

self.sheldon_cooper_mode = self.config.get("sheldon_cooper_mode", False)
if self.sheldon_cooper_mode:
       num_actions = 5
else:
       num_actions = 3

self.action_spaces = self.observation_spaces = {
            "player1": gym.spaces.Discrete(num_actions),
            "player2": gym.spaces.Discrete(num_actions),
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, but I wanted to leave the Sheldon Cooper mode out of the docs entirely (to keep docs as simple as possible). Therefore I had to spacially separate these two logics entirely in the file.

| 6| 7| 8|
----------

The action space is Discrete(9) and actions landing on an alredy occupied field
Copy link
Collaborator

Choose a reason for hiding this comment

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

"alredy" -> "already"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

win_val = [-1, -1, -1]
if (
# Horizontal win.
self.board[:3] == win_val
Copy link
Collaborator

Choose a reason for hiding this comment

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

Very cool!

):
# Final reward is +5 for victory and -5 for a loss.
rewards[self.current_player] += 5.0
rewards[opponent] = -5.0
Copy link
Collaborator

Choose a reason for hiding this comment

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

I wonder if it works better if win and loss are rewarded in a different amount than a wrong placement?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They are rewarded separately, with +1.0 and -1.0.
The misplacement penalty should be learnt pretty quickly by the agents (b/c it hurts a lot) and after that, they should be able to "focus" on the actual game, not misplacing any pieces anymore. 🤞


return (
{self.current_player: np.array(self.board, np.float32)},
rewards,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe add a comment here that tells users how these rewards are handled in the MultiAgentEpisode - that it is treated in there as the reward for the last current player (the one that sent the action); this is counter-intuitive at first for new users.

Signed-off-by: sven1977 <[email protected]>
Signed-off-by: sven1977 <[email protected]>
@sven1977 sven1977 enabled auto-merge (squash) December 11, 2024 10:50
@github-actions github-actions bot added the go add ONLY when ready to merge, run all tests label Dec 11, 2024
@github-actions github-actions bot disabled auto-merge December 11, 2024 10:50
@sven1977 sven1977 added rllib RLlib related issues rllib-env rllib env related issues rllib-docs-or-examples Issues related to RLlib documentation or rllib/examples rllib-newstack rllib-oldstack-cleanup Issues related to cleaning up classes, utilities on the old API stack labels Dec 11, 2024
@sven1977 sven1977 enabled auto-merge (squash) December 11, 2024 10:51
@sven1977 sven1977 changed the title [RLlib] Docs do-over (new API stack): Env pages vol 01. [RLlib; docs] Docs do-over (new API stack): Env pages vol 01. Dec 11, 2024
Signed-off-by: sven1977 <[email protected]>
@github-actions github-actions bot disabled auto-merge December 11, 2024 11:46
Signed-off-by: sven1977 <[email protected]>
@sven1977 sven1977 enabled auto-merge (squash) December 11, 2024 13:46
Signed-off-by: sven1977 <[email protected]>
@github-actions github-actions bot disabled auto-merge December 11, 2024 13:48
Signed-off-by: sven1977 <[email protected]>
@sven1977 sven1977 enabled auto-merge (squash) December 11, 2024 15:30
@sven1977 sven1977 merged commit 3f429c6 into ray-project:master Dec 11, 2024
6 checks passed
@sven1977 sven1977 deleted the docs_redo_cleanup_old_api_stack_01_00 branch December 11, 2024 16:32
ujjawal-khare pushed a commit to ujjawal-khare-27/ray that referenced this pull request Dec 17, 2024
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-docs-or-examples Issues related to RLlib documentation or rllib/examples rllib-env rllib env related issues rllib-newstack rllib-oldstack-cleanup Issues related to cleaning up classes, utilities on the old API stack
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants