Fix seed method for spaces.Tuple and spaces.Dict (#2365)

* Fix seed method for Tuple and Dict

* Improve stochasticity

* Update test cases for seed method

* Update test cases for seed method

Update test cases for seed method

Update test cases for seed method
This commit is contained in:
Xuehai Pan
2021-09-02 22:15:34 +08:00
committed by GitHub
parent c00c1babb9
commit bb8e8063e9
3 changed files with 160 additions and 4 deletions

View File

@@ -19,7 +19,24 @@ class Tuple(Space):
super(Tuple, self).__init__(None, None)
def seed(self, seed=None):
[space.seed(seed) for space in self.spaces]
seed = super().seed(seed)
try:
subseeds = self.np_random.choice(
np.iinfo(int).max,
size=len(self.spaces),
replace=False, # unique subseed for each subspace
)
except ValueError:
subseeds = self.np_random.choice(
np.iinfo(int).max,
size=len(self.spaces),
replace=True, # we get more than INT_MAX subspaces
)
for subspace, subseed in zip(self.spaces, subseeds):
seed.append(subspace.seed(int(subseed))[0])
return seed
def sample(self):
return tuple([space.sample() for space in self.spaces])