gym icon indicating copy to clipboard operation
gym copied to clipboard

[Proposal] Allows custom seed for automatic reset in VectorEnv

Open xiaobanni opened this issue 3 years ago • 1 comments

Proposal

Allows custom seed for automatic reset in VectorEnv. (Suitable for gym version 0.26.1.) When we make vertorized env like,

envs = gym.vector.make("CartPole-v1", num_envs=3)

We know that "The environment copies inside a vectorized environment automatically call gym.Env.reset at the end of an episode". But i don't find a way to send custom seed to this process. I find the function to reset the done env in VectorEnv is in file sync_vector_env.py line 154:

if self._terminateds[i] or self._truncateds[i]:
    old_observation = observation
    observation, info = env.reset()
    info["final_observation"] = old_observation

So current version may not support my proposal.

Motivation

In many environments (e.g. in a maze) we need to ensure that the environment is determined after each reset.

xiaobanni avatar Oct 08 '22 05:10 xiaobanni

If on the first reset you pass a seed, reset(seed=123) and use the same actions, the environment observations should be deterministic. This is for all internal Gym environments and most external environments should share this property. Importantly, when the autoreset happens at the end of an episode, the environment continues using the same random number generator so is still deterministic in the next episode.

I believe this should solve your issue.

If this doesn't solve your issue, could you post an example of this failing

pseudo-rnd-thoughts avatar Oct 08 '22 23:10 pseudo-rnd-thoughts