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

Why are dones in MarkovVectorEnv.step() transformed to int? #175

Closed
Sam-Amar opened this issue Aug 30, 2022 · 1 comment
Closed

Why are dones in MarkovVectorEnv.step() transformed to int? #175

Sam-Amar opened this issue Aug 30, 2022 · 1 comment

Comments

@Sam-Amar
Copy link

Sam-Amar commented Aug 30, 2022

In MarkovVectorEnv.step() dones returned by the parallel env are transformed to numpy.uint8 with the following lines:

dns = np.array(
            [dones.get(agent, False) for agent in self.par_env.possible_agents],
            dtype=np.uint8,
        )

Why is this the case?

This behavior might lead to unexpected consequences.
For example, if we want to do parameter sharing with StableBaselines3, we wrap the parallel env into a MarkovVectorEnv with pettingzoo_env_to_vec_env_v1() and then use concat_vec_envs_v1() as seen in the tutorial. However, if we want to use batch normalization with StableBaselines3.VecNormalize, we get a silent bug, as the line

self.returns[dones] = 0

in VecNormalize.step_wait() then always sets the returns of env_0 to 0 if any done is False.

@benblack769
Copy link
Contributor

Oh, wow, did not realize that sb3 did stuff like that. The reason for this is that the memory layout of np.bool type wasn't super obvious, so to make things a bit less ambiguous, and in the meantime, I decided it would be easier to understand the cross-process data transfer if the data type was uint8.

However, you make a good point that before it is returned to the user, it should probably be converted to a bool.

I think just adding a dones.dtype(bool) to here https://github.com/Farama-Foundation/SuperSuit/blob/master/supersuit/vector/multiproc_vec.py#L208 should solve the issue?

@jjshoots jjshoots closed this as completed Sep 2, 2022
jjshoots added a commit that referenced this issue Sep 8, 2022
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

No branches or pull requests

3 participants