Farama-Foundation / Minigrid

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

Wrappers and default seeds #108

Closed tudor-berariu closed 2 years ago

tudor-berariu commented 4 years ago

Method gym.core.Env.seed has the following signature def seed(self, seed=None). The seed method in gym.core.Wrapper also has a default value of None for parameter seed (which is the actual issue, as it should have passed *args, **kwargs to self.env.seed).

gym_minigrid.MiniGridEnv.seed has a default value of 1337 for parameter seed, but when some environment is wrapped, the effective default value becomes None (because of gym.core.Wrapper.seed).

Maybe it would be a good idea to preserve the signature from gym and treat None as a special case:

def seed(self, seed=None):
    if seed is None:
        seed = 1337

but this might be problematic too, as one cannot explicitly send None now.

maximecb commented 4 years ago

Hi @tudor-berariu. I think you are correct.

It seems to me it should be safe to just change the default signature to def seed(self, seed=None) and not check if seed is None in the method. For serious ML experiments, users will already have supplied their own seed value.

SamNPowers commented 4 years ago

Relatedly I think it's a bit confusing that some environments default to a seed (e.g. the multi room envs) and some do not (e.g. unlock).

maximecb commented 4 years ago

I would accept a PR if you'd like to fix that :)

pseudo-rnd-thoughts commented 2 years ago

Addressed by https://github.com/Farama-Foundation/gym-minigrid/pull/194

shreyanmitra commented 2 months ago

@pseudo-rnd-thoughts What happened to the seed() function in the current version? I am updating old code that uses gym-minigrid.

pseudo-rnd-thoughts commented 2 months ago

@shreyanmitra gym-minigrid was updated gymnasium backend, see this guide for more info https://gymnasium.farama.org/content/migration-guide/

shreyanmitra commented 2 months ago

@pseudo-rnd-thoughts Thanks so much for the resource. However, I get the following error:

TypeError: reset() got an unexpected keyword argument 'seed'

Although the recommendation in the migration guide was to replace env.seed(seed=seed) with env.reset(seed=seed)