Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into tutorial
Browse files Browse the repository at this point in the history
Merging latest updates.
  • Loading branch information
HardyHasan94 committed Apr 16, 2024
2 parents 3e78de8 + 94a7909 commit d1a7a07
Show file tree
Hide file tree
Showing 35 changed files with 112 additions and 77 deletions.
4 changes: 4 additions & 0 deletions docs/api/vector.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ vector/utils
The ``EnvSpec`` of the environment normally set during :py:meth:`gymnasium.make_vec`
.. autoattribute:: gymnasium.vector.VectorEnv.metadata
The metadata of the environment containing rendering modes, rendering fps, etc
.. autoattribute:: gymnasium.vector.VectorEnv.render_mode
The render mode of the environment which should follow similar specifications to `Env.render_mode`.
Expand Down
2 changes: 1 addition & 1 deletion gymnasium/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class Env(Generic[ObsType, ActType]):
- :attr:`action_space` - The Space object corresponding to valid actions, all valid actions should be contained within the space.
- :attr:`observation_space` - The Space object corresponding to valid observations, all valid observations should be contained within the space.
- :attr:`spec` - An environment spec that contains the information used to initialize the environment from :meth:`gymnasium.make`
- :attr:`metadata` - The metadata of the environment, i.e. render modes, render fps
- :attr:`metadata` - The metadata of the environment, e.g., `{"render_modes": ["rgb_array", "human"], "render_fps": 30}`. For Jax or Torch, this can be indicated to users with `"jax"=True` or `"torch"=True`.
- :attr:`np_random` - The random number generator for the environment. This is automatically assigned during
``super().reset(seed=seed)`` and when assessing :attr:`np_random`.
Expand Down
2 changes: 1 addition & 1 deletion gymnasium/envs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@
# --- For shimmy compatibility
def _raise_shimmy_error(*args: Any, **kwargs: Any):
raise ImportError(
"To use the gym compatibility environments, run `pip install shimmy[gym-v21]` or `pip install shimmy[gym-v26]`"
'To use the gym compatibility environments, run `pip install "shimmy[gym-v21]"` or `pip install "shimmy[gym-v26]"`'
)


Expand Down
4 changes: 2 additions & 2 deletions gymnasium/envs/box2d/bipedal_walker.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
)
except ImportError as e:
raise DependencyNotInstalled(
"Box2D is not installed, run `pip install gymnasium[box2d]`"
'Box2D is not installed, you can install it by run `pip install swig` followed by `pip install "gymnasium[box2d]"`'
) from e


Expand Down Expand Up @@ -628,7 +628,7 @@ def render(self):
from pygame import gfxdraw
except ImportError as e:
raise DependencyNotInstalled(
"pygame is not installed, run `pip install gymnasium[box2d]`"
'pygame is not installed, run `pip install "gymnasium[box2d]"`'
) from e

if self.screen is None and self.render_mode == "human":
Expand Down
2 changes: 1 addition & 1 deletion gymnasium/envs/box2d/car_dynamics.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from Box2D.b2 import fixtureDef, polygonShape, revoluteJointDef
except ImportError as e:
raise DependencyNotInstalled(
"Box2D is not installed, run `pip install gymnasium[box2d]`"
'Box2D is not installed, you can install it by run `pip install swig` followed by `pip install "gymnasium[box2d]"`'
) from e


Expand Down
4 changes: 2 additions & 2 deletions gymnasium/envs/box2d/car_racing.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from Box2D.b2 import contactListener, fixtureDef, polygonShape
except ImportError as e:
raise DependencyNotInstalled(
"Box2D is not installed, run `pip install gymnasium[box2d]`"
'Box2D is not installed, you can install it by run `pip install swig` followed by `pip install "gymnasium[box2d]"`'
) from e

try:
Expand All @@ -27,7 +27,7 @@
from pygame import gfxdraw
except ImportError as e:
raise DependencyNotInstalled(
"pygame is not installed, run `pip install gymnasium[box2d]`"
'pygame is not installed, run `pip install "gymnasium[box2d]"`'
) from e


Expand Down
4 changes: 2 additions & 2 deletions gymnasium/envs/box2d/lunar_lander.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
)
except ImportError as e:
raise DependencyNotInstalled(
"Box2D is not installed, run `pip install gymnasium[box2d]`"
'Box2D is not installed, you can install it by run `pip install swig` followed by `pip install "gymnasium[box2d]"`'
) from e


Expand Down Expand Up @@ -683,7 +683,7 @@ def render(self):
from pygame import gfxdraw
except ImportError as e:
raise DependencyNotInstalled(
"pygame is not installed, run `pip install gymnasium[box2d]`"
'pygame is not installed, run `pip install "gymnasium[box2d]"`'
) from e

if self.screen is None and self.render_mode == "human":
Expand Down
2 changes: 1 addition & 1 deletion gymnasium/envs/classic_control/acrobot.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ def render(self):
from pygame import gfxdraw
except ImportError as e:
raise DependencyNotInstalled(
"pygame is not installed, run `pip install gymnasium[classic-control]`"
'pygame is not installed, run `pip install "gymnasium[classic-control]"`'
) from e

if self.screen is None:
Expand Down
4 changes: 2 additions & 2 deletions gymnasium/envs/classic_control/cartpole.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ def render(self):
from pygame import gfxdraw
except ImportError as e:
raise DependencyNotInstalled(
"pygame is not installed, run `pip install gymnasium[classic-control]`"
'pygame is not installed, run `pip install "gymnasium[classic-control]"`'
) from e

if self.screen is None:
Expand Down Expand Up @@ -528,7 +528,7 @@ def render(self):
from pygame import gfxdraw
except ImportError:
raise DependencyNotInstalled(
"pygame is not installed, run `pip install gymnasium[classic_control]`"
'pygame is not installed, run `pip install "gymnasium[classic_control]"`'
)

if self.screens is None:
Expand Down
2 changes: 1 addition & 1 deletion gymnasium/envs/classic_control/continuous_mountain_car.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def render(self):
from pygame import gfxdraw
except ImportError as e:
raise DependencyNotInstalled(
"pygame is not installed, run `pip install gymnasium[classic-control]`"
'pygame is not installed, run `pip install "gymnasium[classic_control]"`'
) from e

if self.screen is None:
Expand Down
2 changes: 1 addition & 1 deletion gymnasium/envs/classic_control/mountain_car.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def render(self):
from pygame import gfxdraw
except ImportError as e:
raise DependencyNotInstalled(
"pygame is not installed, run `pip install gymnasium[classic-control]`"
'pygame is not installed, run `pip install "gymnasium[classic_control]"`'
) from e

if self.screen is None:
Expand Down
2 changes: 1 addition & 1 deletion gymnasium/envs/classic_control/pendulum.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def render(self):
from pygame import gfxdraw
except ImportError as e:
raise DependencyNotInstalled(
"pygame is not installed, run `pip install gymnasium[classic-control]`"
'pygame is not installed, run `pip install "gymnasium[classic_control]"`'
) from e

if self.screen is None:
Expand Down
3 changes: 1 addition & 2 deletions gymnasium/envs/mujoco/mujoco_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
import mujoco
except ImportError as e:
raise error.DependencyNotInstalled(
"Could not import mujoco"
"(HINT: you need to install mujoco, run `pip install gymnasium[mujoco]`.)"
'MuJoCo is not installed, run `pip install "gymnasium[mujoco]"`'
) from e


Expand Down
6 changes: 6 additions & 0 deletions gymnasium/envs/mujoco/pusher_v4.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import mujoco
import numpy as np

from gymnasium import utils
Expand All @@ -22,7 +23,12 @@ class PusherEnv(MujocoEnv, utils.EzPickle):
}

def __init__(self, **kwargs):
if mujoco.__version__ >= "3.0.0":
raise ImportError(
"`Pusher-v4` is only supported on `mujuco<3`, for more information https://github.com/Farama-Foundation/Gymnasium/issues/950"
)
utils.EzPickle.__init__(self, **kwargs)

observation_space = Box(low=-np.inf, high=np.inf, shape=(23,), dtype=np.float64)
MujocoEnv.__init__(
self,
Expand Down
6 changes: 3 additions & 3 deletions gymnasium/envs/phys2d/cartpole.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def render_image(
from pygame import gfxdraw
except ImportError as e:
raise DependencyNotInstalled(
"pygame is not installed, run `pip install gymnasium[classic-control]`"
'pygame is not installed, run `pip install "gymnasium[classic_control]"`'
) from e
screen, clock = render_state

Expand Down Expand Up @@ -217,7 +217,7 @@ def render_init(
import pygame
except ImportError as e:
raise DependencyNotInstalled(
"pygame is not installed, run `pip install gymnasium[classic-control]`"
'pygame is not installed, run `pip install "gymnasium[classic_control]"`'
) from e

pygame.init()
Expand All @@ -232,7 +232,7 @@ def render_close(self, render_state: RenderStateType) -> None:
import pygame
except ImportError as e:
raise DependencyNotInstalled(
"pygame is not installed, run `pip install gymnasium[classic-control]`"
'pygame is not installed, run `pip install "gymnasium[classic_control]"`'
) from e
pygame.display.quit()
pygame.quit()
Expand Down
6 changes: 3 additions & 3 deletions gymnasium/envs/phys2d/pendulum.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def render_image(
from pygame import gfxdraw
except ImportError as e:
raise DependencyNotInstalled(
"pygame is not installed, run `pip install gymnasium[classic-control]`"
'pygame is not installed, run `pip install "gymnasium[classic_control]"`'
) from e
screen, clock, last_u = render_state

Expand Down Expand Up @@ -191,7 +191,7 @@ def render_init(
import pygame
except ImportError as e:
raise DependencyNotInstalled(
"pygame is not installed, run `pip install gymnasium[classic-control]`"
'pygame is not installed, run `pip install "gymnasium[classic_control]"`'
) from e

pygame.init()
Expand All @@ -210,7 +210,7 @@ def render_close(
import pygame
except ImportError as e:
raise DependencyNotInstalled(
"pygame is not installed, run `pip install gymnasium[classic-control]`"
'pygame is not installed, run `pip install "gymnasium[classic_control]"`'
) from e
pygame.display.quit()
pygame.quit()
Expand Down
6 changes: 3 additions & 3 deletions gymnasium/envs/tabular/blackjack.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ def render_init(
import pygame
except ImportError:
raise DependencyNotInstalled(
"pygame is not installed, run `pip install gymnasium[classic_control]`"
'pygame is not installed, run `pip install "gymnasium[classic_control]"`'
)

rng = seeding.np_random(0)[0]
Expand All @@ -377,7 +377,7 @@ def render_image(
import pygame
except ImportError:
raise DependencyNotInstalled(
"pygame is not installed, run `pip install gymnasium[toy_text]`"
'pygame is not installed, run `pip install "gymnasium[toy_text]"`'
)
screen, dealer_top_card_value_str, dealer_top_card_suit = render_state

Expand Down Expand Up @@ -483,7 +483,7 @@ def render_close(self, render_state: RenderStateType) -> None:
import pygame
except ImportError as e:
raise DependencyNotInstalled(
"pygame is not installed, run `pip install gymnasium[classic_control]`"
'pygame is not installed, run `pip install "gymnasium[classic_control]"`'
) from e
pygame.display.quit()
pygame.quit()
Expand Down
6 changes: 3 additions & 3 deletions gymnasium/envs/tabular/cliffwalking.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ def render_init(
import pygame
except ImportError:
raise DependencyNotInstalled(
"pygame is not installed, run `pip install gymnasium[classic_control]`"
'pygame is not installed, run `pip install "gymnasium[classic_control]"`'
)

cell_size = (60, 60)
Expand Down Expand Up @@ -302,7 +302,7 @@ def render_image(
import pygame
except ImportError:
raise DependencyNotInstalled(
"pygame is not installed, run `pip install gymnasium[toy_text]`"
'pygame is not installed, run `pip install "gymnasium[toy_text]"`'
)
(
window_surface,
Expand Down Expand Up @@ -349,7 +349,7 @@ def render_close(self, render_state: RenderStateType) -> None:
import pygame
except ImportError as e:
raise DependencyNotInstalled(
"pygame is not installed, run `pip install gymnasium[toy-text]`"
'pygame is not installed, run `pip install "gymnasium[toy-text]"`'
) from e
pygame.display.quit()
pygame.quit()
Expand Down
2 changes: 1 addition & 1 deletion gymnasium/envs/toy_text/blackjack.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ def render(self):
import pygame
except ImportError as e:
raise DependencyNotInstalled(
"pygame is not installed, run `pip install gymnasium[toy-text]`"
'pygame is not installed, run `pip install "gymnasium[toy-text]"`'
) from e

player_sum, dealer_card_value, usable_ace = self._get_obs()
Expand Down
2 changes: 1 addition & 1 deletion gymnasium/envs/toy_text/cliffwalking.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ def _render_gui(self, mode):
import pygame
except ImportError as e:
raise DependencyNotInstalled(
"pygame is not installed, run `pip install gymnasium[toy-text]`"
'pygame is not installed, run `pip install "gymnasium[toy-text]"`'
) from e
if self.window_surface is None:
pygame.init()
Expand Down
2 changes: 1 addition & 1 deletion gymnasium/envs/toy_text/frozen_lake.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ def _render_gui(self, mode):
import pygame
except ImportError as e:
raise DependencyNotInstalled(
"pygame is not installed, run `pip install gymnasium[toy-text]`"
'pygame is not installed, run `pip install "gymnasium[toy-text]"`'
) from e

if self.window_surface is None:
Expand Down
2 changes: 1 addition & 1 deletion gymnasium/envs/toy_text/taxi.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ def _render_gui(self, mode):
import pygame # dependency to pygame only if rendering with human
except ImportError as e:
raise DependencyNotInstalled(
"pygame is not installed, run `pip install gymnasium[toy-text]`"
'pygame is not installed, run `pip install "gymnasium[toy-text]"`'
) from e

if self.window is None:
Expand Down
8 changes: 4 additions & 4 deletions gymnasium/utils/play.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from pygame.event import Event
except ImportError as e:
raise gym.error.DependencyNotInstalled(
"pygame is not installed, run `pip install gymnasium[classic-control]`"
'pygame is not installed, run `pip install "gymnasium[classic_control]"`'
) from e

try:
Expand All @@ -27,7 +27,7 @@
matplotlib.use("TkAgg")
import matplotlib.pyplot as plt
except ImportError:
logger.warn("matplotlib is not installed, run `pip install gymnasium[other]`")
logger.warn('matplotlib is not installed, run `pip install "gymnasium[other]"`')
matplotlib, plt = None, None


Expand Down Expand Up @@ -358,7 +358,7 @@ def __init__(

if plt is None:
raise DependencyNotInstalled(
"matplotlib is not installed, run `pip install gymnasium[other]`"
'matplotlib is not installed, run `pip install "gymnasium[other]"`'
)

num_plots = len(self.plot_names)
Expand Down Expand Up @@ -411,6 +411,6 @@ def callback(

if plt is None:
raise DependencyNotInstalled(
"matplotlib is not installed, run `pip install gymnasium[other]`"
'matplotlib is not installed, run `pip install "gymnasium[other]"`'
)
plt.pause(0.000001)
2 changes: 1 addition & 1 deletion gymnasium/utils/save_video.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from moviepy.video.io.ImageSequenceClip import ImageSequenceClip
except ImportError as e:
raise gym.error.DependencyNotInstalled(
"moviepy is not installed, run `pip install moviepy`"
'moviepy is not installed, run `pip install "gymnasium[other]"`'
) from e


Expand Down
8 changes: 8 additions & 0 deletions gymnasium/vector/vector_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ class VectorEnv(Generic[ObsType, ActType, ArrayType]):
:func:`make_vec` is the equivalent function to :func:`make` for vector environments.
"""

# Set this in SOME subclasses
metadata: dict[str, Any] = {"render_modes": []}

spec: EnvSpec | None = None
render_mode: str | None = None
closed: bool = False
Expand Down Expand Up @@ -446,6 +449,11 @@ def render_mode(self) -> tuple[RenderFrame, ...] | None:
"""Returns the `render_mode` from the base environment."""
return self.env.render_mode

@property
def metadata(self) -> dict[str, Any]:
"""Returns the `metadata` from the base environment."""
return self.env.metadata

@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 Down
2 changes: 1 addition & 1 deletion gymnasium/wrappers/atari_preprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def __init__(
import cv2 # noqa: F401
except ImportError:
raise gym.error.DependencyNotInstalled(
"opencv-python package not installed, run `pip install gymnasium[other]` to get dependencies for atari"
'opencv-python package not installed, run `pip install "gymnasium[other]"` to get dependencies for atari'
)

assert frame_skip > 0
Expand Down
Loading

0 comments on commit d1a7a07

Please sign in to comment.