Skip to content

[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

Merged
merged 1 commit into from
Jun 30, 2022
Merged

[Feature] custom info_dict reader methods #234

merged 1 commit into from
Jun 30, 2022

Conversation

vmoens
Copy link
Collaborator

@vmoens vmoens commented Jun 29, 2022

Proposes a set_info_dict_reader method for gym-like environments that'll read the info dictionary and write down the values on a TensorDict in a way defined by the user.
This will allow users to use GymWrapper and GymEnv without effort in cases where the info dictionary is weird and unpredictable.

cc @BoboBananas

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jun 29, 2022
@vmoens vmoens changed the title custom info_dict reader methods [Feature] custom info_dict reader methods Jun 29, 2022
@vmoens vmoens added the enhancement New feature or request label Jun 29, 2022
@vmoens vmoens requested a review from shagunsodhani June 29, 2022 16:51
Copy link
Contributor

@shagunsodhani shagunsodhani left a 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:
Copy link
Contributor

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

Copy link
Collaborator Author

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?

Copy link
Contributor

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__():
Copy link
Contributor

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.

Copy link
Collaborator Author

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

Copy link
Contributor

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!

Copy link
Collaborator Author

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...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants