Skip to content

Conversation

@younik
Copy link
Member

@younik younik commented Sep 23, 2022

Update to new Render API openai/gym#2671

Todo:

  • make human rendering automatic

# Conflicts:
#	pettingzoo/mpe/_mpe_utils/simple_env.py
# Conflicts:
#	docs/content/basic_usage.md
#	pettingzoo/classic/rlcard_envs/gin_rummy.py
#	pettingzoo/classic/rlcard_envs/leduc_holdem.py
#	pettingzoo/classic/tictactoe/tictactoe.py
@younik younik marked this pull request as ready for review September 27, 2022 17:40
Copy link
Collaborator

@jjshoots jjshoots left a comment

Choose a reason for hiding this comment

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

Almost LGTM so far, other than some of the comments I've left.

I think self.render_mode and possibly the warning can be moved into env.py itself, this would remove a lot of clutter from the many environment files.

Copy link
Collaborator

@jjshoots jjshoots left a comment

Choose a reason for hiding this comment

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

LGTM now, if @WillDudley is happy with this then I think we can merge. (Possibly after the clarification needed from Mark)

Copy link
Contributor

@WillDudley WillDudley 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've pinged Ben on Discord asking for his sanity check on the r_env revision if he has time, but nonetheless I approve the merge. If Ben notices we've misinterpreted it we can easily hotfix it.

@jjshoots
Copy link
Collaborator

Cool, @younik could you fix black? Then I'll merge this PR, thanks a ton for the help!

@benblack769
Copy link
Contributor

benblack769 commented Sep 30, 2022

Looking at the r_env thing, it looks necessary to me:

        env = raw_env(**kwargs)
        env = wrappers.CaptureStdoutWrapper(env)
    else:
        env = raw_env(**kwargs)

    env = wrappers.TerminateIllegalWrapper(
        env, illegal_reward=HanabiScorePenalty(env)
    )

Note the code path:

        env = raw_env(**kwargs)
        env = wrappers.CaptureStdoutWrapper(env)
        HanabiScorePenalty(env)

HanabiScorePenalty looks at the hanabi_env attribute, which is part of the raw env, but not part of the wrapped env. If you add an unwrapped, i.e.

        env = raw_env(**kwargs)
        env = wrappers.CaptureStdoutWrapper(env)
        HanabiScorePenalty(env.unwrapped)

It should work

(note that the code was written before the unwrapped attribute was implemented)

@younik
Copy link
Member Author

younik commented Oct 1, 2022

Thanks, @benblack769, it makes sense! With this PR, I also added a custom implementation of __getattr__ for wrappers. Thus, the following code runs fine:

from pettingzoo.classic.hanabi_v4 import raw_env
from pettingzoo.classic.hanabi.hanabi import HanabiScorePenalty
from pettingzoo.utils import wrappers

env = raw_env(render_mode="human")
env = wrappers.CaptureStdoutWrapper(env)
env = HanabiScorePenalty(env)
float(env)

@jjshoots I fixed pre-commit.

Comment on lines +42 to +47
def __getattr__(self, name):
"""Returns an attribute with ``name``, unless ``name`` starts with an underscore."""
if name.startswith("_"):
raise AttributeError(f"accessing private attribute '{name}' is prohibited")
return getattr(self.env, name)

Copy link
Member Author

Choose a reason for hiding this comment

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

@benblack769 for reference

Copy link
Contributor

Choose a reason for hiding this comment

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

I wouldn't add it casually in the middle of a big PR like this, its worth thinking over whether this plays nicely with the conversion wrappers, with the parallel wrappers, with the OrderEnforcing wrapper which has its own __getattr__ overload, etc.

PZ has somewhat more complex wrapper system than gym.

That being said, I think people have converted me over to the concept that this is a good idea.

@WillDudley
Copy link
Contributor

Personally I don't quite follow this. Why does adding an attribute error for hidden attributes negate the need for env.unwrapped?

@jjshoots
Copy link
Collaborator

jjshoots commented Oct 1, 2022

It's not the error that negates the need for unwrapped, it's the getattr(self.env, name), that's basically unwrapped.

@WillDudley
Copy link
Contributor

Ah, I see, lgtm then. Merge?

@jjshoots
Copy link
Collaborator

jjshoots commented Oct 1, 2022

I'm waiting to see if @benblack769 has anything to say about that new getattr.

@jjshoots
Copy link
Collaborator

jjshoots commented Oct 1, 2022

@benblack769 Could you have a look at that getattr thing and see if it's reasonable?

@jjshoots
Copy link
Collaborator

jjshoots commented Oct 1, 2022

Thanks for the help everyone! Merging since I think everything's sound.

@Trinkle23897
Copy link

Hi there, a lot of people complain about the API changes you have made. Is there a decent solution to address those issues?

@younik
Copy link
Member Author

younik commented Nov 2, 2022

Hi there, a lot of people complain about the API changes you have made. Is there a decent solution to address those issues?

Hello,
We changed the API of rendering in openai/gym#2671
This became a breaking change in gym 0.26, then we migrate also PettingZoo.

I explained the changes and how to update environments here: https://younis.dev/blog/render-api/
I am happy to help more with it if needed.

@WillDudley
Copy link
Contributor

We also have a tutorial but it needs some minor bugfixes which I don't have capacity to do.

The tutorials can be found here: https://github.com/Farama-Foundation/PettingZoo/tree/master/tutorials/Tianshou

@Trinkle23897 It would help if you could take a look at them, otherwise I'll find someone to delegate the task to. I'll also bump up the task priority, I wasn't aware of the complaints.

@Trinkle23897
Copy link

It would be nice if someone can address this issue!

@WillDudley
Copy link
Contributor

We've upped the priority on the tutorial

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.

6 participants