Make Tuple and Dicts be seedable with lists and dicts of seeds + make the seed in default initialization controllable (#1774)

* Make the seed in default initialization controllable

Since seed() is being called in default initialization of Space, it should be controllable for reproducibility.

* Updated derived classes of Space to have their seeds controllable at initialization.

* Allow Tuple's spaces to each have their own seed

* Added dict based seeding for Dict space; test cases for Tuple and Dict seeding

* Update discrete.py

* Update test_spaces.py

* Add seed to __init__()

* blacked

* Fix black

* Fix failing tests
This commit is contained in:
RaghuSpaceRajan
2021-09-13 20:08:01 +02:00
committed by GitHub
parent 0eabbaf8a2
commit c571b0d853
8 changed files with 123 additions and 45 deletions

View File

@@ -11,10 +11,10 @@ class Discrete(Space):
"""
def __init__(self, n):
def __init__(self, n, seed=None):
assert n >= 0
self.n = n
super(Discrete, self).__init__((), np.int64)
super(Discrete, self).__init__((), np.int64, seed)
def sample(self):
return self.np_random.randint(self.n)