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

Fix VectorizeActionTransform for changing spaces #1170

Merged

Conversation

pseudo-rnd-thoughts
Copy link
Member

@pseudo-rnd-thoughts pseudo-rnd-thoughts commented Sep 20, 2024

Description

Fixes #1169

gymnasium.wrappers.vector.VectorizeActionTransform was incorrectly implemented for changing spaces, i.e., self.same_out is False as the direction of data is the opposite of VectorizeObservationTransform from which it was copied.

tuple(
self.wrapper.func(action)
for action in iterate(self.env.action_space, actions)
for action in iterate(self.action_space, actions)
Copy link

@pkrack pkrack Sep 20, 2024

Choose a reason for hiding this comment

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

Question: why not self.single_action_space?
Docstring of iterate: "space: Observation space of a single environment in the vectorized environment."

Same docstring in concatenate which also takes as input a single_action_space. (also both docstrings are completely identical, the one for iterate is wrong).

This seems to suggest that iterate takes as argument the action space of a single action, not a batched one. Does it even matter since there is no out arg?

asking because I use it in my code, just want to make sure :)

Copy link
Member Author

Choose a reason for hiding this comment

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

I had just looked at the example docstring which shows a batched space rather than a single space so I'm using the batched space version.
I think the docstring is just incorrect, will update and check the rest.

Copy link
Member Author

Choose a reason for hiding this comment

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

Looks like someone, possibly me, copied the concatenate docstring for some reason, fixing now

Copy link

@pkrack pkrack Sep 20, 2024

Choose a reason for hiding this comment

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

Thanks for the quick answers and fixes :)

I think in the end it does not matter whether the first arg is the batched space or not right? Both batched and unbatched versions of a same structured space should be identical up until the base spaces, which are iterated over just with iter regardless of which space is given as argument. The only difference it makes is with respect to typing, and that is only if someone uses literal shape annotations in the base spaces.

One more little comment before I stop bothering you:
The signature of iterate is:
def iterate(space: Space[T_cov], items: Iterable[T_cov])
but items is supposed to be a single batched sample from space ->
def iterate(space: Space[T_cov], items: T_cov)

Copy link
Member Author

Choose a reason for hiding this comment

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

For the second point, your correct, I'll update

@pseudo-rnd-thoughts pseudo-rnd-thoughts merged commit a6976e4 into Farama-Foundation:main Sep 20, 2024
13 checks passed
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.

[Bug Report] VectorizeAction not working
2 participants