mirror of
https://github.com/Farama-Foundation/Gymnasium.git
synced 2025-08-21 06:20:15 +00:00
Seeding update (#2422)
* Ditch most of the seeding.py and replace np_random with the numpy default_rng. Let's see if tests pass * Updated a bunch of RNG calls from the RandomState API to Generator API * black; didn't expect that, did ya? * Undo a typo * blaaack * More typo fixes * Fixed setting/getting state in multidiscrete spaces * Fix typo, fix a test to work with the new sampling * Correctly (?) pass the randomly generated seed if np_random is called with None as seed * Convert the Discrete sample to a python int (as opposed to np.int64) * Remove some redundant imports * First version of the compatibility layer for old-style RNG. Mainly to trigger tests. * Removed redundant f-strings * Style fixes, removing unused imports * Try to make tests pass by removing atari from the dockerfile * Try to make tests pass by removing atari from the setup * Try to make tests pass by removing atari from the setup * Try to make tests pass by removing atari from the setup * First attempt at deprecating `env.seed` and supporting `env.reset(seed=seed)` instead. Tests should hopefully pass but throw up a million warnings. * black; didn't expect that, didya? * Rename the reset parameter in VecEnvs back to `seed` * Updated tests to use the new seeding method * Removed a bunch of old `seed` calls. Fixed a bug in AsyncVectorEnv * Stop Discrete envs from doing part of the setup (and using the randomness) in init (as opposed to reset) * Add explicit seed to wrappers reset * Remove an accidental return * Re-add some legacy functions with a warning. * Use deprecation instead of regular warnings for the newly deprecated methods/functions
This commit is contained in:
committed by
GitHub
parent
b84b69c872
commit
c364506710
@@ -1,7 +1,10 @@
|
||||
from typing import List, Union, Optional
|
||||
|
||||
import numpy as np
|
||||
from copy import deepcopy
|
||||
|
||||
from gym import logger
|
||||
from gym.logger import warn
|
||||
from gym.vector.vector_env import VectorEnv
|
||||
from gym.vector.utils import concatenate, create_empty_array
|
||||
|
||||
@@ -72,21 +75,28 @@ class SyncVectorEnv(VectorEnv):
|
||||
self._dones = np.zeros((self.num_envs,), dtype=np.bool_)
|
||||
self._actions = None
|
||||
|
||||
def seed(self, seeds=None):
|
||||
if seeds is None:
|
||||
seeds = [None for _ in range(self.num_envs)]
|
||||
if isinstance(seeds, int):
|
||||
seeds = [seeds + i for i in range(self.num_envs)]
|
||||
assert len(seeds) == self.num_envs
|
||||
def seed(self, seed=None):
|
||||
super().seed(seed=seed)
|
||||
if seed is None:
|
||||
seed = [None for _ in range(self.num_envs)]
|
||||
if isinstance(seed, int):
|
||||
seed = [seed + i for i in range(self.num_envs)]
|
||||
assert len(seed) == self.num_envs
|
||||
|
||||
for env, seed in zip(self.envs, seeds):
|
||||
env.seed(seed)
|
||||
for env, single_seed in zip(self.envs, seed):
|
||||
env.seed(single_seed)
|
||||
|
||||
def reset_wait(self, seed: Optional[Union[int, List[int]]] = None, **kwargs):
|
||||
if seed is None:
|
||||
seed = [None for _ in range(self.num_envs)]
|
||||
if isinstance(seed, int):
|
||||
seed = [seed + i for i in range(self.num_envs)]
|
||||
assert len(seed) == self.num_envs
|
||||
|
||||
def reset_wait(self):
|
||||
self._dones[:] = False
|
||||
observations = []
|
||||
for env in self.envs:
|
||||
observation = env.reset()
|
||||
for env, single_seed in zip(self.envs, seed):
|
||||
observation = env.reset(seed=single_seed)
|
||||
observations.append(observation)
|
||||
self.observations = concatenate(
|
||||
observations, self.observations, self.single_observation_space
|
||||
|
Reference in New Issue
Block a user