Farama-Foundation / Minigrid

Simple and easily configurable grid world environments for reinforcement learning
https://minigrid.farama.org/
Other
2.13k stars 611 forks source link

Vectorize environments #173

Closed raymondchua closed 2 years ago

raymondchua commented 2 years ago

Hi, I would like to vectorise the mini grid environment if possible. Currently, I am doing

 env_fn = lambda: ImgObsWrapper(RGBImgObsWrapper(gym.make(args.env)))
 env = gym.vector.AsyncVectorEnv([env_fn for _ in range(args.num_envs)])
 obs = env.reset()

But when I view the images of the environment, it seems that for all the environments, the agents have the same starting location. I am hoping that the agents are starting at different random positions. When initialising the environment, I set agent_start_pos = None but I suspect it needs something else to fix this issue. Is there a way to set use the random seed to generate different random seeds for the environments?

maximecb commented 2 years ago

Yes, you would need to supply a different seed to each environment.

You could call env.seed() in your lambda with a different seed for each environment after creating it.

There's also a seed method for AsyncVectorEnv that takes. a list of seeds: https://tristandeleu.github.io/gym/vector/api_reference.html#gym.vector.AsyncVectorEnv.seed

raymondchua commented 2 years ago

Thanks! That works!