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

Improve 'set_wrapper_attr'. #1294

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

duburcqa
Copy link
Contributor

@duburcqa duburcqa commented Jan 18, 2025

Description

I propose to further improve 'set_wrapper_attr' (as a follow-up of PR #1293).

I added the optional keyword argument 'force'. Its role is to make sure that the attribute exists before setting it, so that no attribute while be create on the top-level wrapper. While this could already be done using 'has_wrapper_attr', but specifying the new optional argument is not only more convenient but also faster. Moreover, adding this extra argument enables to refactor the implementation of 'set_wrapper_attr' as a recursive function calling itself on the lower-level environment (in case of wrappers). This is not only more than twice faster (because isinstance is very slow...), but also more robust, as it allows anybody to derive its own wrapper from gym.Env and provides its own implementation of 'set_wrapper_attr'. Finally, the implementation is easier to understand and closely align with get_wrapper_attr.

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

Checklist:

  • I have run the pre-commit checks with pre-commit run --all-files (see CONTRIBUTING.md instructions to set it up)
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

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.

1 participant