Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
171 changes: 101 additions & 70 deletions gymnasium/core.py

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions gymnasium/envs/box2d/bipedal_walker.py
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,7 @@ def step(self, action: np.ndarray):

def render(self):
if self.render_mode is None:
assert self.spec is not None
gym.logger.warn(
"You are calling render method without specifying any render mode. "
"You can specify the render_mode at initialization, "
Expand Down
1 change: 1 addition & 0 deletions gymnasium/envs/box2d/car_racing.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,7 @@ def step(self, action: Union[np.ndarray, int]):

def render(self):
if self.render_mode is None:
assert self.spec is not None
gym.logger.warn(
"You are calling render method without specifying any render mode. "
"You can specify the render_mode at initialization, "
Expand Down
1 change: 1 addition & 0 deletions gymnasium/envs/box2d/lunar_lander.py
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,7 @@ def step(self, action):

def render(self):
if self.render_mode is None:
assert self.spec is not None
gym.logger.warn(
"You are calling render method without specifying any render mode. "
"You can specify the render_mode at initialization, "
Expand Down
1 change: 1 addition & 0 deletions gymnasium/envs/classic_control/acrobot.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ def _dsdt(self, s_augmented):

def render(self):
if self.render_mode is None:
assert self.spec is not None
gym.logger.warn(
"You are calling render method without specifying any render mode. "
"You can specify the render_mode at initialization, "
Expand Down
1 change: 1 addition & 0 deletions gymnasium/envs/classic_control/cartpole.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ def reset(

def render(self):
if self.render_mode is None:
assert self.spec is not None
gym.logger.warn(
"You are calling render method without specifying any render mode. "
"You can specify the render_mode at initialization, "
Expand Down
1 change: 1 addition & 0 deletions gymnasium/envs/classic_control/continuous_mountain_car.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ def _height(self, xs):

def render(self):
if self.render_mode is None:
assert self.spec is not None
gym.logger.warn(
"You are calling render method without specifying any render mode. "
"You can specify the render_mode at initialization, "
Expand Down
1 change: 1 addition & 0 deletions gymnasium/envs/classic_control/mountain_car.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ def _height(self, xs):

def render(self):
if self.render_mode is None:
assert self.spec is not None
gym.logger.warn(
"You are calling render method without specifying any render mode. "
"You can specify the render_mode at initialization, "
Expand Down
1 change: 1 addition & 0 deletions gymnasium/envs/classic_control/pendulum.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ def _get_obs(self):

def render(self):
if self.render_mode is None:
assert self.spec is not None
gym.logger.warn(
"You are calling render method without specifying any render mode. "
"You can specify the render_mode at initialization, "
Expand Down
1 change: 1 addition & 0 deletions gymnasium/envs/toy_text/blackjack.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ def reset(

def render(self):
if self.render_mode is None:
assert self.spec is not None
gym.logger.warn(
"You are calling render method without specifying any render mode. "
"You can specify the render_mode at initialization, "
Expand Down
1 change: 1 addition & 0 deletions gymnasium/envs/toy_text/cliffwalking.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ def reset(self, *, seed: Optional[int] = None, options: Optional[dict] = None):

def render(self):
if self.render_mode is None:
assert self.spec is not None
gym.logger.warn(
"You are calling render method without specifying any render mode. "
"You can specify the render_mode at initialization, "
Expand Down
1 change: 1 addition & 0 deletions gymnasium/envs/toy_text/frozen_lake.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ def reset(

def render(self):
if self.render_mode is None:
assert self.spec is not None
gym.logger.warn(
"You are calling render method without specifying any render mode. "
"You can specify the render_mode at initialization, "
Expand Down
1 change: 1 addition & 0 deletions gymnasium/envs/toy_text/taxi.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ def reset(

def render(self):
if self.render_mode is None:
assert self.spec is not None
gym.logger.warn(
"You are calling render method without specifying any render mode. "
"You can specify the render_mode at initialization, "
Expand Down
2 changes: 2 additions & 0 deletions gymnasium/utils/play.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def _get_relevant_keys(
elif hasattr(self.env.unwrapped, "get_keys_to_action"):
keys_to_action = self.env.unwrapped.get_keys_to_action()
else:
assert self.env.spec is not None
raise MissingKeysToAction(
f"{self.env.spec.id} does not have explicit key to action mapping, "
"please specify one manually"
Expand Down Expand Up @@ -230,6 +231,7 @@ def play(
elif hasattr(env.unwrapped, "get_keys_to_action"):
keys_to_action = env.unwrapped.get_keys_to_action()
else:
assert env.spec is not None
raise MissingKeysToAction(
f"{env.spec.id} does not have explicit key to action mapping, "
"please specify one manually"
Expand Down
3 changes: 2 additions & 1 deletion gymnasium/wrappers/atari_preprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ def __init__(
assert noop_max >= 0
if frame_skip > 1:
if (
"NoFrameskip" not in env.spec.id
env.spec is not None
and "NoFrameskip" not in env.spec.id
and getattr(env.unwrapped, "_frameskip", None) != 1
):
raise ValueError(
Expand Down
1 change: 1 addition & 0 deletions gymnasium/wrappers/time_limit.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def __init__(
"""
super().__init__(env)
if max_episode_steps is None and self.env.spec is not None:
assert env.spec is not None
max_episode_steps = env.spec.max_episode_steps
if self.env.spec is not None:
self.env.spec.max_episode_steps = max_episode_steps
Expand Down
9 changes: 7 additions & 2 deletions tests/envs/test_action_dim_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ def test_mujoco_action_dimensions(env_spec: EnvSpec):


@pytest.mark.parametrize(
"env", DISCRETE_ENVS, ids=[env.spec.id for env in DISCRETE_ENVS]
"env",
DISCRETE_ENVS,
ids=[env.spec.id for env in DISCRETE_ENVS if env.spec is not None],
)
def test_discrete_actions_out_of_bound(env: gym.Env):
"""Test out of bound actions in Discrete action_space.
Expand Down Expand Up @@ -87,7 +89,9 @@ def test_discrete_actions_out_of_bound(env: gym.Env):
OOB_VALUE = 100


@pytest.mark.parametrize("env", BOX_ENVS, ids=[env.spec.id for env in BOX_ENVS])
@pytest.mark.parametrize(
"env", BOX_ENVS, ids=[env.spec.id for env in BOX_ENVS if env.spec is not None]
)
def test_box_actions_out_of_bound(env: gym.Env):
"""Test out of bound actions in Box action_space.

Expand All @@ -100,6 +104,7 @@ def test_box_actions_out_of_bound(env: gym.Env):
"""
env.reset(seed=42)

assert env.spec is not None
oob_env = gym.make(env.spec.id, disable_env_checker=True)
oob_env.reset(seed=42)

Expand Down
2 changes: 1 addition & 1 deletion tests/envs/test_envs.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def test_render_modes(spec):
@pytest.mark.parametrize(
"env",
all_testing_initialised_envs,
ids=[env.spec.id for env in all_testing_initialised_envs],
ids=[env.spec.id for env in all_testing_initialised_envs if env.spec is not None],
)
def test_pickle_env(env: gym.Env):
pickled_env = pickle.loads(pickle.dumps(env))
Expand Down
4 changes: 4 additions & 0 deletions tests/envs/test_make.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@

def test_make():
env = gym.make("CartPole-v1", disable_env_checker=True)
assert env.spec is not None
assert env.spec.id == "CartPole-v1"
assert isinstance(env.unwrapped, cartpole.CartPoleEnv)
env.close()
Expand All @@ -73,6 +74,7 @@ def test_make_max_episode_steps():
# Default, uses the spec's
env = gym.make("CartPole-v1", disable_env_checker=True)
assert has_wrapper(env, TimeLimit)
assert env.spec is not None
assert (
env.spec.max_episode_steps == gym.envs.registry["CartPole-v1"].max_episode_steps
)
Expand All @@ -81,6 +83,7 @@ def test_make_max_episode_steps():
# Custom max episode steps
env = gym.make("CartPole-v1", max_episode_steps=100, disable_env_checker=True)
assert has_wrapper(env, TimeLimit)
assert env.spec is not None
assert env.spec.max_episode_steps == 100
env.close()

Expand Down Expand Up @@ -297,6 +300,7 @@ def test_make_kwargs():
arg3="override_arg3",
disable_env_checker=True,
)
assert env.spec is not None
assert env.spec.id == "test.ArgumentEnv-v0"
assert isinstance(env.unwrapped, ArgumentEnv)
assert env.arg1 == "arg1"
Expand Down
1 change: 1 addition & 0 deletions tests/envs/test_register.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ def test_make_latest_versioned_env(register_testing_envs):
env = gym.make(
"MyAwesomeNamespace/MyAwesomeVersionedEnv", disable_env_checker=True
)
assert env.spec is not None
assert env.spec.id == "MyAwesomeNamespace/MyAwesomeVersionedEnv-v5"


Expand Down
1 change: 1 addition & 0 deletions tests/envs/test_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def test_spec():
def test_spec_kwargs():
map_name_value = "8x8"
env = gym.make("FrozenLake-v1", map_name=map_name_value)
assert env.spec is not None
assert env.spec.kwargs["map_name"] == map_name_value


Expand Down
Loading