Skip to content

Commit 9fa7ede

Browse files
Forwards all np_random assignments to the actual environment and prevent access to the _np_random in wrappers (#2857)
1 parent fa01fda commit 9fa7ede

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

gym/core.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,21 @@ def metadata(self) -> dict:
315315
def metadata(self, value):
316316
self._metadata = value
317317

318+
@property
319+
def np_random(self) -> RandomNumberGenerator:
320+
"""Returns the environment np_random."""
321+
return self.env.np_random
322+
323+
@np_random.setter
324+
def np_random(self, value):
325+
self.env.np_random = value
326+
327+
@property
328+
def _np_random(self):
329+
raise AttributeError(
330+
"Can't access `_np_random` of a wrapper, use `.unwrapped._np_random` or `.np_random`."
331+
)
332+
318333
def step(self, action: ActType) -> Tuple[ObsType, float, bool, dict]:
319334
"""Steps through the environment with action."""
320335
return self.env.step(action)

0 commit comments

Comments
 (0)