-
Notifications
You must be signed in to change notification settings - Fork 8.6k
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
Make various 'space' functions easier to extend for custom Spaces #2093
Conversation
b40ba5e
to
40363c6
Compare
So after discussion with @benblack769 this actually seems like a generally good idea. However, this detailed tests need to be added before I can merge this and Pr currently does not have them. |
Reviewer: @benblack769 |
40363c6
to
ad1aaa3
Compare
@lebrice tests are failing and there are merge conflicts. Are you still interested in working on this PR? |
Hey @jkterry1, Yeah I will update this when I find a moment, should be relatively soon. |
aff3e82
to
037adb0
Compare
Alright so turns out that @tristandeleu actually already added part of what this PR was meant for in #2328 (at least for the flatten/unflatten/flatdim utils). This PR also transforms the other utility functions into singledispatch callables, and also fixes a potential bug:
My opinion is that there shouldn't be any other tests needed specifically for this PR, since it's simply a refactoring of the utility functions, each of which already has tests. This PR also adds a test for the positional argument issue I just described. Let me know what you think. |
Apologies for the changes, I should have noted them here. I would also be in favor of eventually changing the order of the arguments in all the functions in |
@tristandeleu This is actually not the case! I've added a "wrapper" function around all the introduced generic functions, which makes this totally backward-compatible! As an example, I didn't need to change anything VectorEnvs for this to work! :) |
Yes sorry I saw the wrapper function. What I was suggesting was to change the order of the arguments everywhere (and remove the wrapper function). The PR in its current form is absolutely fine, but in the future it would be cleaner (and possibly less confusing) to have all these functions have |
@lebrice is this PR currently in a state where you'd like it to be reviewed for being merged? |
@lebrice could you please also fix tests and change argument orders per Tristan's comment? |
PR is in a good state and ready for review, however I guess I could first change the order of arguments as you mentioned. I'll also keep it backward-compatible as well and raise a warning or something in case the old ordering is used with positional args. |
@lebrice did you change the argument order and can you please fix the merge conflicts? |
Not yet, will do. You can close this if you want, or mark it as draft, and I'll mark it as "ready for review" when it's good to go |
Hey, this looks really good in refactoring the code. One thing that pops to me was the use of |
Signed-off-by: Fabrice Normandin <fabrice.normandin@gmail.com>
Signed-off-by: Fabrice Normandin <fabrice.normandin@gmail.com>
Signed-off-by: Fabrice Normandin <fabrice.normandin@gmail.com>
- Fix bug where singledispatch requires at least one positional argument. Added a `pass_space_as_first_positional_argument` wrapper which fixes this issue. - Improve tests for the functions which had the ordering of their arguments changed: Tests now cover both the old ordering as well as the new one (they previously only used the old ordering). Signed-off-by: Fabrice Normandin <fabrice.normandin@gmail.com>
Signed-off-by: Fabrice Normandin <fabrice.normandin@gmail.com>
Signed-off-by: Fabrice Normandin <fabrice.normandin@gmail.com>
Signed-off-by: Fabrice Normandin <fabrice.normandin@gmail.com>
Signed-off-by: Fabrice Normandin <fabrice.normandin@gmail.com>
Signed-off-by: Fabrice Normandin <fabrice.normandin@gmail.com>
Signed-off-by: Fabrice Normandin <fabrice.normandin@gmail.com>
Signed-off-by: Fabrice Normandin <fabrice.normandin@gmail.com>
Signed-off-by: Fabrice Normandin <fabrice.normandin@gmail.com>
6f87995
to
1578ad6
Compare
Closed in favor of #2525 |
Adds better support for "custom" Space subclasses, by making it possible to "extend" the various gym functions that take a
Space
as an argument by registering new handlers that type.This is achieved by converting the given functions into singledispatch functions:
The ordering of the positional arguments for the following functions was changed, since the type of the first argument (in this case
space
) is the one used by singledispatch to choose the appropriate callable to use. There is however code in each of these to re-order the arguments in case they weren't passed in the right order, making this change fully backward-compatible.Signed-off-by: Fabrice Normandin fabrice.normandin@gmail.com