I would like to seed my gymnasium environment. From the official documentation, the way I'd do it is -
import gymnasium as gym
env = gym.make("LunarLander-v2", render_mode="human")
observation, info = env.reset(seed=42)
However, stable_baselines3 doesn't seem to require resets from the user side as shown in the program below -
import gymnasium as gym
from stable_baselines3 import PPO
from stable_baselines3.common.env_util import make_vec_env
# Parallel environments
vec_env = make_vec_env("CartPole-v1", n_envs=4)
model = PPO("MlpPolicy", vec_env, verbose=1)
model.learn(total_timesteps=25000)
model.save("ppo_cartpole")
del model # remove to demonstrate saving and loading
model = PPO.load("ppo_cartpole")
How do I place a seed with stable_baselines3
? I tried placing np.random.seed(24)
but that didn't work.
make_vec_env
has a parameter named seed
. You can find more examples from official tutorial. Search for "seed".