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:
Ariel Kwiatkowski
2021-12-08 22:14:15 +01:00
committed by GitHub
parent b84b69c872
commit c364506710
59 changed files with 386 additions and 294 deletions

View File

@@ -1,5 +1,6 @@
import sys
import math
from typing import Optional
import numpy as np
import Box2D
@@ -122,7 +123,6 @@ class BipedalWalker(gym.Env, EzPickle):
def __init__(self):
EzPickle.__init__(self)
self.seed()
self.viewer = None
self.world = Box2D.b2World()
@@ -149,10 +149,6 @@ class BipedalWalker(gym.Env, EzPickle):
)
self.observation_space = spaces.Box(-high, high)
def seed(self, seed=None):
self.np_random, seed = seeding.np_random(seed)
return [seed]
def _destroy(self):
if not self.terrain:
return
@@ -188,7 +184,7 @@ class BipedalWalker(gym.Env, EzPickle):
y += velocity
elif state == PIT and oneshot:
counter = self.np_random.randint(3, 5)
counter = self.np_random.integers(3, 5)
poly = [
(x, y),
(x + TERRAIN_STEP, y),
@@ -215,7 +211,7 @@ class BipedalWalker(gym.Env, EzPickle):
y -= 4 * TERRAIN_STEP
elif state == STUMP and oneshot:
counter = self.np_random.randint(1, 3)
counter = self.np_random.integers(1, 3)
poly = [
(x, y),
(x + counter * TERRAIN_STEP, y),
@@ -228,9 +224,9 @@ class BipedalWalker(gym.Env, EzPickle):
self.terrain.append(t)
elif state == STAIRS and oneshot:
stair_height = +1 if self.np_random.rand() > 0.5 else -1
stair_width = self.np_random.randint(4, 5)
stair_steps = self.np_random.randint(3, 5)
stair_height = +1 if self.np_random.random() > 0.5 else -1
stair_width = self.np_random.integers(4, 5)
stair_steps = self.np_random.integers(3, 5)
original_y = y
for s in range(stair_steps):
poly = [
@@ -266,9 +262,9 @@ class BipedalWalker(gym.Env, EzPickle):
self.terrain_y.append(y)
counter -= 1
if counter == 0:
counter = self.np_random.randint(TERRAIN_GRASS / 2, TERRAIN_GRASS)
counter = self.np_random.integers(TERRAIN_GRASS / 2, TERRAIN_GRASS)
if state == GRASS and hardcore:
state = self.np_random.randint(1, _STATES_)
state = self.np_random.integers(1, _STATES_)
oneshot = True
else:
state = GRASS
@@ -312,7 +308,8 @@ class BipedalWalker(gym.Env, EzPickle):
x2 = max(p[0] for p in poly)
self.cloud_poly.append((poly, x1, x2))
def reset(self):
def reset(self, seed: Optional[int] = None):
super().reset(seed=seed)
self._destroy()
self.world.contactListener_bug_workaround = ContactDetector(self)
self.world.contactListener = self.world.contactListener_bug_workaround