Skip to content

Commit

Permalink
Made readout of seed possible in env
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Panchenko committed Jan 23, 2024
1 parent 81151ab commit c3cd661
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions gymnasium/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class Env(Generic[ObsType, ActType]):

# Created
_np_random: np.random.Generator | None = None
_seed: int | None = None

def step(
self, action: ActType
Expand Down Expand Up @@ -148,7 +149,7 @@ def reset(
"""
# Initialize the RNG if the seed is manually passed
if seed is not None:
self._np_random, seed = seeding.np_random(seed)
self._np_random, self._seed = seeding.np_random(seed)

def render(self) -> RenderFrame | list[RenderFrame] | None:
"""Compute the render frames as specified by :attr:`render_mode` during the initialization of the environment.
Expand Down Expand Up @@ -201,6 +202,11 @@ def unwrapped(self) -> Env[ObsType, ActType]:
"""
return self

@property
def seed(self) -> int | None:
"""Returns the environment's internal :attr:`_seed` that if not set will initialise with a random seed."""
return self._seed

@property
def np_random(self) -> np.random.Generator:
"""Returns the environment's internal :attr:`_np_random` that if not set will initialise with a random seed.
Expand All @@ -209,7 +215,7 @@ def np_random(self) -> np.random.Generator:
Instances of `np.random.Generator`
"""
if self._np_random is None:
self._np_random, _ = seeding.np_random()
self._np_random, self._seed = seeding.np_random()
return self._np_random

@np_random.setter
Expand Down

0 comments on commit c3cd661

Please # to comment.