hill-a / stable-baselines

A fork of OpenAI Baselines, implementations of reinforcement learning algorithms
http://stable-baselines.readthedocs.io/
MIT License
4.14k stars 723 forks source link

why doesn't env.env_method("reset") reset the environment? #1115

Closed neonine2 closed 3 years ago

neonine2 commented 3 years ago

My environment is wrapped as such:

vec_env = make_vec_env(lambda: env, n_envs=1, seed=0)
env = VecNormalize(vec_env, norm_obs=True, norm_reward=True)

Everytime I reset it using the standard reset() method, the observation changes (as expected since my reset includes a randomization)

env.reset()
obs = env.get_original_obs()
print(obs)

Since I want to pass a parameter to reset(), I tried to test out the following, expecting the same behavior as above

env.env_method('reset')
obs = env.get_original_obs()
print(obs)

However, as I excute this code over and over, obs doesn't change at all, it's clear that env isn't actually being resetted, even though executing env.env_method('reset') does output different value each time.

Does running env.env_method('reset') not reset the environment in the same way as env.reset()?

Miffyli commented 3 years ago

get_original_obs is a function of VecNormalize, so it returns whatever is stored in its buffers. env.reset goes through VecNormalize, where it updates those buffers. env_method, on the other hand, is a function of VecEnv, so calling it does not update VecNormalize's buffers. I recommend you create a new function for your env, e.g. set_reset_params, which you use to set the reset parameters for envs for the next reset call.

PS: I also recommend migrating to stable-baselines3 as it is more actively supported.

neonine2 commented 3 years ago

Great! thank you very much, and I'll look into baselines3.