-
Notifications
You must be signed in to change notification settings - Fork 373
[Feature] custom info_dict reader methods #234
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm - left some minor comments
""" | ||
|
||
def __init__(self, keys=None): | ||
if keys is None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we want to ensure that keys like 'observation', 'next_observation', 'action', 'reward', 'done' are not passed so that they arent read from info_dict
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see your point but on the other hand some crazy researcher may want to do that no? Like overriding the observation based on the info. Since the default is reading nothing we can assume that those inputting similar keys to read know what they're doing, what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense - good to go from my side!
|
||
@property | ||
def info_dict_reader(self): | ||
if "_info_dict_reader" not in self.__dir__(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume that this is checking if _info_dict_reader
attribute exists or not. I am not sure if checking the self.__dir__()
is the recommended method. I have seen use of hasattr
method lot more. So just flagging this, in case it turns out to be relevant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Problem with hasattr is that it'll look into env.env (ie the gym env) if it can't find it, and I can't promise what env.env has and hasn't.
With dir I'm sure it won't propagate to the wrapped env
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting. I didnt realise hashattr would do that but it makes sense!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah it's not a clever function
It just runs getattr and tells you ok if it did not return an error...
Proposes a
set_info_dict_reader
method for gym-like environments that'll read the info dictionary and write down the values on aTensorDict
in a way defined by the user.This will allow users to use
GymWrapper
andGymEnv
without effort in cases where the info dictionary is weird and unpredictable.cc @BoboBananas