gym_gridverse package#
Subpackages#
- gym_gridverse.envs package
- Subpackages
- Submodules
- gym_gridverse.envs.gridworld module
- gym_gridverse.envs.inner_env module
- gym_gridverse.envs.observation_functions module
- gym_gridverse.envs.reset_functions module
- gym_gridverse.envs.reward_functions module
- gym_gridverse.envs.terminating_functions module
- gym_gridverse.envs.transition_functions module
- gym_gridverse.envs.utils module
- gym_gridverse.envs.visibility_functions module
- Module contents
- gym_gridverse.representations package
- gym_gridverse.utils package
- Submodules
- gym_gridverse.utils.custom module
- gym_gridverse.utils.fast_copy module
- gym_gridverse.utils.functions module
- gym_gridverse.utils.protocols module
- gym_gridverse.utils.raytracing module
- gym_gridverse.utils.registry module
- gym_gridverse.utils.rl module
- gym_gridverse.utils.space_builders module
- Module contents
Submodules#
gym_gridverse.action module#
Defines the Action class
- class Action(value)[source]#
Bases:
Enum
Actions available to the agent.
There are (up to) 8 actions:
4
movement
actions (forward, backwards, left & right)2
turn
actions (left & right)1
actuate
action, which can actuate objects (e.g., the one in front)1
pick and drop
action, to pick up objects (e.g., the one in front)
- MOVE_FORWARD = 0#
- MOVE_BACKWARD = 1#
- MOVE_LEFT = 2#
- MOVE_RIGHT = 3#
- TURN_LEFT = 4#
- TURN_RIGHT = 5#
- ACTUATE = 6#
- PICK_N_DROP = 7#
gym_gridverse.agent module#
- class Agent(position, orientation, grid_object=None)[source]#
Bases:
object
Information relative to the agent.
NOTE: This does not necessarily represent the true full state of the agent; e.g., the agent field of an observation objects, would only contain the observable versions of the agent’s state.
Creates the agent at position with orientation and holding grid_object.
- Parameters
position (Position) – position of the agent relative to some area.
orientation (Orientation) – orientation of the agent relative to some area.
grid_object (Optional[GridObject]) – object held by the agent.
- __init__(position, orientation, grid_object=None)[source]#
Creates the agent at position with orientation and holding grid_object.
- Parameters
position (Position) – position of the agent relative to some area.
orientation (Orientation) – orientation of the agent relative to some area.
grid_object (Optional[GridObject]) – object held by the agent.
- property position: gym_gridverse.geometry.Position#
- Return type
- property orientation: gym_gridverse.geometry.Orientation#
- Return type
gym_gridverse.debugging module#
- gv_debug()[source]#
Gets the library-wide debugging boolean.
Used to bypass expensive type and value checks at runtime. By default (if
reset_gv_debug()
was not called), the value of __debug__ is used.- Return type
gym_gridverse.design module#
- draw_room(grid, area, factory)[source]#
use factory-created grid-objects to draw room boundary on grid
- draw_room_grid(grid, ys, xs, factory)[source]#
use factory-created grid-objects to draw a grid of rooms on grid
- draw_area(grid, area, factory, *, fill)[source]#
use factory-created grid-objects to draw area on grid
- draw_line_horizontal(grid, y, xs, factory)[source]#
use factory-created grid-objects to draw horizontal line on grid
gym_gridverse.geometry module#
- class Shape(height, width)[source]#
Bases:
object
2D shape, with integer height and width.
Follows matrix notation: first index is number of rows, and second index is number of columns.
- class Area(ys, xs)[source]#
Bases:
object
2D area, which extends vertically and horizontally
- class Position(y, x)[source]#
Bases:
object
2D position (y, x), with y extending downward and x extending rightward
- class Orientation(value)[source]#
Bases:
Enum
An enumeration.
- FORWARD = 0#
- BACKWARD = 1#
- LEFT = 2#
- RIGHT = 3#
- F = 0#
- B = 1#
- L = 2#
- R = 3#
- class Transform(position, orientation)[source]#
Bases:
object
A grid-based rigid body transformation, also a
pose
(position and orientation)- position: gym_gridverse.geometry.Position#
- orientation: gym_gridverse.geometry.Orientation#
- get_manhattan_boundary(position, distance)[source]#
Returns the cells (excluding pos) with Manhattan distance of pos
For distance = 1, will return the left, upper, right and lower cell of position. For longer distances, the extended boundary is returned:
E.g. for distance = 2 the cells denoted by ‘x’ are returned:
x x x x . x x x x
gym_gridverse.grid module#
- class Grid(objects)[source]#
Bases:
object
A two-dimensional grid of objects.
A container of
GridObject
. This is typically used to represent either the global state of the environment, or a partial agent view. This is basically a two-dimensional array, with some additional methods which help in querying and manipulating its objects.Constructs a grid from the given grid-objects
- Parameters
objects (List[List[GridObject]]) – grid of GridObjects
- __init__(objects)[source]#
Constructs a grid from the given grid-objects
- Parameters
objects (List[List[GridObject]]) – grid of GridObjects
- static from_shape(shape, *, factory=<class 'gym_gridverse.grid_object.Floor'>)[source]#
Constructs a grid with the given shape, with objects generated from the factory.
- object_types()[source]#
Returns the set of object types in the grid
- Return type
Set[Type[GridObject]]
- get(position, *, factory)[source]#
Gets the grid object in the position, or generates one from the factory.
- Parameters
- Return type
gym_gridverse.grid_object module#
Every cell in the grid is represented by a grid objects
- class Color(value)[source]#
Bases:
Enum
Color of grid objects
- NONE = 0#
- RED = 1#
- GREEN = 2#
- BLUE = 3#
- YELLOW = 4#
- class GridObjectRegistry(initlist=None)[source]#
Bases:
UserList
- register(object_type)[source]#
Register a virtual subclass of an ABC.
Returns the subclass, to allow usage as a class decorator.
- Return type
- grid_object_registry = [<class 'gym_gridverse.grid_object.NoneGridObject'>, <class 'gym_gridverse.grid_object.Hidden'>, <class 'gym_gridverse.grid_object.Floor'>, <class 'gym_gridverse.grid_object.Wall'>, <class 'gym_gridverse.grid_object.Exit'>, <class 'gym_gridverse.grid_object.Door'>, <class 'gym_gridverse.grid_object.Key'>, <class 'gym_gridverse.grid_object.MovingObstacle'>, <class 'gym_gridverse.grid_object.Box'>, <class 'gym_gridverse.grid_object.Telepod'>, <class 'gym_gridverse.grid_object.Beacon'>]#
GridObject registry
- class GridObject(*args, **kwargs)[source]#
Bases:
object
Represents the contents of a grid cell
- abstract property color: gym_gridverse.grid_object.Color#
Color of this grid-object
- Return type
- abstract property blocks_movement: bool#
Whether this grid-object blocks the agent from moving on it
- Return type
- abstract property blocks_vision: bool#
Whether this grid-object blocks the agent’s vision.
- Return type
- abstract classmethod can_be_represented_in_state()[source]#
True iff
state_index
fully represents the grid-object state.GridObjects may have an internal state which is not fully representable by a single integer
state_index
, e.g., aBox
contains a reference to anotherGridObject
as its content. The unfortunate implication is that thisGridObject
(and, by extension, any Grido or Environment which contains this type ofGridObject
) cannot produce a truly fully observable State representation, which becomes disallowed. However, the GridObject, Grid, and Environment may still be used to represent partially observable control tasks.- Return type
- class NoneGridObject(*args, **kwargs)[source]#
Bases:
GridObject
An object which represents the complete absence of any other object.
- state_index = 0#
- color = 0#
- blocks_movement = False#
- blocks_vision = True#
- holdable = False#
- classmethod can_be_represented_in_state()[source]#
True iff
state_index
fully represents the grid-object state.GridObjects may have an internal state which is not fully representable by a single integer
state_index
, e.g., aBox
contains a reference to anotherGridObject
as its content. The unfortunate implication is that thisGridObject
(and, by extension, any Grido or Environment which contains this type ofGridObject
) cannot produce a truly fully observable State representation, which becomes disallowed. However, the GridObject, Grid, and Environment may still be used to represent partially observable control tasks.- Return type
- class Hidden(*args, **kwargs)[source]#
Bases:
GridObject
An object which represents some other unobservable object.
- state_index = 0#
- color = 0#
- blocks_movement = False#
- blocks_vision = True#
- holdable = False#
- classmethod can_be_represented_in_state()[source]#
True iff
state_index
fully represents the grid-object state.GridObjects may have an internal state which is not fully representable by a single integer
state_index
, e.g., aBox
contains a reference to anotherGridObject
as its content. The unfortunate implication is that thisGridObject
(and, by extension, any Grido or Environment which contains this type ofGridObject
) cannot produce a truly fully observable State representation, which becomes disallowed. However, the GridObject, Grid, and Environment may still be used to represent partially observable control tasks.- Return type
- class Floor(*args, **kwargs)[source]#
Bases:
GridObject
An empty walkable spot
- state_index = 0#
- color = 0#
- blocks_movement = False#
- blocks_vision = False#
- holdable = False#
- classmethod can_be_represented_in_state()[source]#
True iff
state_index
fully represents the grid-object state.GridObjects may have an internal state which is not fully representable by a single integer
state_index
, e.g., aBox
contains a reference to anotherGridObject
as its content. The unfortunate implication is that thisGridObject
(and, by extension, any Grido or Environment which contains this type ofGridObject
) cannot produce a truly fully observable State representation, which becomes disallowed. However, the GridObject, Grid, and Environment may still be used to represent partially observable control tasks.- Return type
- class Wall(*args, **kwargs)[source]#
Bases:
GridObject
An object which obstructs movement and vision.
- state_index = 0#
- color = 0#
- blocks_movement = True#
- blocks_vision = True#
- holdable = False#
- classmethod can_be_represented_in_state()[source]#
True iff
state_index
fully represents the grid-object state.GridObjects may have an internal state which is not fully representable by a single integer
state_index
, e.g., aBox
contains a reference to anotherGridObject
as its content. The unfortunate implication is that thisGridObject
(and, by extension, any Grido or Environment which contains this type ofGridObject
) cannot produce a truly fully observable State representation, which becomes disallowed. However, the GridObject, Grid, and Environment may still be used to represent partially observable control tasks.- Return type
- class Exit(color=Color.NONE)[source]#
Bases:
GridObject
The (second) most basic object in the grid: blocking cell
- state_index = 0#
- blocks_movement = False#
- blocks_vision = False#
- holdable = False#
- color = 0#
- classmethod can_be_represented_in_state()[source]#
True iff
state_index
fully represents the grid-object state.GridObjects may have an internal state which is not fully representable by a single integer
state_index
, e.g., aBox
contains a reference to anotherGridObject
as its content. The unfortunate implication is that thisGridObject
(and, by extension, any Grido or Environment which contains this type ofGridObject
) cannot produce a truly fully observable State representation, which becomes disallowed. However, the GridObject, Grid, and Environment may still be used to represent partially observable control tasks.- Return type
- class Door(state, color)[source]#
Bases:
GridObject
A door which can be open, closed or locked.
The following dynamics (upon actuation) occur:
- When not holding correct key with correct color:
open or closed -> open locked -> locked
- When holding correct key:
any state -> open
Can be OPEN, CLOSED or LOCKED.
- holdable = False#
- color = 0#
- classmethod can_be_represented_in_state()[source]#
True iff
state_index
fully represents the grid-object state.GridObjects may have an internal state which is not fully representable by a single integer
state_index
, e.g., aBox
contains a reference to anotherGridObject
as its content. The unfortunate implication is that thisGridObject
(and, by extension, any Grido or Environment which contains this type ofGridObject
) cannot produce a truly fully observable State representation, which becomes disallowed. However, the GridObject, Grid, and Environment may still be used to represent partially observable control tasks.- Return type
- classmethod num_states()[source]#
Number of internal states.
GridObjects themselves can have internal states, e.g., a Door may be
open
,closed
, orlocked
. This classmethod return the number of possible states that this GridObject may have.- Return type
- class Key(color)[source]#
Bases:
GridObject
A key to open locked doors.
- state_index = 0#
- blocks_movement = False#
- blocks_vision = False#
- holdable = True#
- color = 0#
- classmethod can_be_represented_in_state()[source]#
True iff
state_index
fully represents the grid-object state.GridObjects may have an internal state which is not fully representable by a single integer
state_index
, e.g., aBox
contains a reference to anotherGridObject
as its content. The unfortunate implication is that thisGridObject
(and, by extension, any Grido or Environment which contains this type ofGridObject
) cannot produce a truly fully observable State representation, which becomes disallowed. However, the GridObject, Grid, and Environment may still be used to represent partially observable control tasks.- Return type
- class MovingObstacle(*args, **kwargs)[source]#
Bases:
GridObject
An obstacle to be avoided that moves in the grid.
- state_index = 0#
- color = 0#
- blocks_movement = False#
- blocks_vision = False#
- holdable = False#
- classmethod can_be_represented_in_state()[source]#
True iff
state_index
fully represents the grid-object state.GridObjects may have an internal state which is not fully representable by a single integer
state_index
, e.g., aBox
contains a reference to anotherGridObject
as its content. The unfortunate implication is that thisGridObject
(and, by extension, any Grido or Environment which contains this type ofGridObject
) cannot produce a truly fully observable State representation, which becomes disallowed. However, the GridObject, Grid, and Environment may still be used to represent partially observable control tasks.- Return type
- class Box(content)[source]#
Bases:
GridObject
A box which can be broken and may contain another object.
- state_index = 0#
- color = 0#
- blocks_movement = True#
- blocks_vision = False#
- holdable = False#
- classmethod can_be_represented_in_state()[source]#
True iff
state_index
fully represents the grid-object state.GridObjects may have an internal state which is not fully representable by a single integer
state_index
, e.g., aBox
contains a reference to anotherGridObject
as its content. The unfortunate implication is that thisGridObject
(and, by extension, any Grido or Environment which contains this type ofGridObject
) cannot produce a truly fully observable State representation, which becomes disallowed. However, the GridObject, Grid, and Environment may still be used to represent partially observable control tasks.- Return type
- class Telepod(color)[source]#
Bases:
GridObject
A pod which teleports elsewhere.
- state_index = 0#
- blocks_movement = False#
- blocks_vision = False#
- holdable = False#
- color = 0#
- classmethod can_be_represented_in_state()[source]#
True iff
state_index
fully represents the grid-object state.GridObjects may have an internal state which is not fully representable by a single integer
state_index
, e.g., aBox
contains a reference to anotherGridObject
as its content. The unfortunate implication is that thisGridObject
(and, by extension, any Grido or Environment which contains this type ofGridObject
) cannot produce a truly fully observable State representation, which becomes disallowed. However, the GridObject, Grid, and Environment may still be used to represent partially observable control tasks.- Return type
- class Beacon(color)[source]#
Bases:
GridObject
A object to attract attention or convey information.
- state_index = 0#
- blocks_movement = False#
- blocks_vision = False#
- holdable = False#
- color = 0#
- classmethod can_be_represented_in_state()[source]#
True iff
state_index
fully represents the grid-object state.GridObjects may have an internal state which is not fully representable by a single integer
state_index
, e.g., aBox
contains a reference to anotherGridObject
as its content. The unfortunate implication is that thisGridObject
(and, by extension, any Grido or Environment which contains this type ofGridObject
) cannot produce a truly fully observable State representation, which becomes disallowed. However, the GridObject, Grid, and Environment may still be used to represent partially observable control tasks.- Return type
- GridObjectFactory#
A callable which returns grid objects.
alias of
Callable
[[],GridObject
]
gym_gridverse.gym module#
- class GymEnvironment(outer_env)[source]#
Bases:
Env
- metadata = {'render.modes': ['human', 'human_state', 'human_observation'], 'video.frames_per_second': 50}#
- state_space#
Environment state space, if any.
- seed(seed=None)[source]#
Sets the seed for this env’s random number generator(s).
Note
Some environments use multiple pseudorandom number generators. We want to capture all such seeds used in order to ensure that there aren’t accidental correlations between multiple generators.
- Returns
- Returns the list of seeds used in this env’s random
number generators. The first value in the list should be the “main” seed, or the value which a reproducer should pass to ‘seed’. Often, the main seed equals the provided ‘seed’, but this won’t be true if seed=None, for example.
- Return type
list<bigint>
- property state: Dict[str, numpy.ndarray]#
Returns the representation of the current state.
- property observation: Dict[str, numpy.ndarray]#
Returns the representation of the current observation.
- reset()[source]#
Resets the state of the environment.
- Returns
initial observation
- Return type
Dict[str, numpy.ndarray]
- step(action)[source]#
Runs the environment dynamics for one timestep.
- Parameters
action (int) – agent’s action
- Returns
(observation, reward, terminal, info dictionary)
- Return type
Tuple[Dict[str, numpy.ndarray], float, bool, Dict]
- render(mode='human')[source]#
Renders the environment.
The set of supported modes varies per environment. (And some environments do not support rendering at all.) By convention, if mode is:
human: render to the current display or terminal and return nothing. Usually for human consumption.
rgb_array: Return an numpy.ndarray with shape (x, y, 3), representing RGB values for an x-by-y pixel image, suitable for turning into a video.
ansi: Return a string (str) or StringIO.StringIO containing a terminal-style text representation. The text can include newlines and ANSI escape sequences (e.g. for colors).
Note
- Make sure that your class’s metadata ‘render.modes’ key includes
the list of supported modes. It’s recommended to call super() in implementations to use the functionality of this method.
- Parameters
mode (str) – the mode to render with
Example:
- class MyEnv(Env):
metadata = {‘render.modes’: [‘human’, ‘rgb_array’]}
- def render(self, mode=’human’):
- if mode == ‘rgb_array’:
return np.array(…) # return RGB frame suitable for video
- elif mode == ‘human’:
… # pop up a window and render
- else:
super(MyEnv, self).render(mode=mode) # just raise an exception
gym_gridverse.observation module#
Defines the Observation class
- class Observation(grid, agent)[source]#
Bases:
object
An observation is a pure data-class containing
grid
andagent
components.This class offers little functionality, and is just a holder for grid and agent. The grid is an instance of class
Grid
, which represents the gridworld from the agent’s POV. The agent is an instance of classAgent
, which represents the agent’s location, orientation, and held item, all from the agent’s POV.- grid: gym_gridverse.grid.Grid#
- agent: gym_gridverse.agent.Agent#
gym_gridverse.outer_env module#
- class OuterEnv(env, *, state_representation=None, observation_representation=None)[source]#
Bases:
object
Outer environment
Outer environments provide an interface primarily based on numeric data, with states and observations represented by
ndarray
, and actions byAction
.- property action_space: gym_gridverse.spaces.ActionSpace#
Returns the action space of the problem.
- Return type
- property state: Dict[str, numpy.ndarray]#
Returns the representation of the current state.
- Return type
Dict[str, numpy.ndarray]
- property observation: Dict[str, numpy.ndarray]#
Returns the representation of the current observation.
- Return type
Dict[str, numpy.ndarray]
gym_gridverse.recording module#
- Image#
An image, alias to np.ndarray
- FrameType#
A State, Observation, or image (np.ndarray)
alias of TypeVar(‘FrameType’, gym_gridverse.state.State, gym_gridverse.observation.Observation, numpy.ndarray)
- class Data(frames, actions, rewards, discount)[source]#
-
Data for recordings of states or observations
- frames: Sequence[gym_gridverse.recording.FrameType]#
- actions: Sequence[gym_gridverse.action.Action]#
- class DataBuilder(discount)[source]#
-
Builds Data object interactively
- frames: List[gym_gridverse.recording.FrameType]#
- actions: List[gym_gridverse.action.Action]#
- class HUD_Info(_typename, _fields=None, /, **kwargs)[source]#
Bases:
dict
- action: Optional[gym_gridverse.action.Action]#
- record(mode, images, *, filename=None, filenames=None, **kwargs)[source]#
Factory function for other recording functions
gym_gridverse.rendering module#
- Return type
Geom
gym_gridverse.rng module#
- T#
generic type
alias of TypeVar(‘T’)
gym_gridverse.spaces module#
- class StateSpace(grid_shape, object_types, colors)[source]#
Bases:
object
- property can_be_represented#
- property grid_state_shape: gym_gridverse.geometry.Shape#
- Return type
- class ObservationSpace(grid_shape, object_types, colors)[source]#
Bases:
object
- property grid_state_shape: gym_gridverse.geometry.Shape#
- Return type
gym_gridverse.state module#
Defines the State class
- class State(grid, agent)[source]#
Bases:
object
A state is a pure data-class containing
grid
andagent
components.This class offers little functionality, and is just a holder for grid and agent. The grid is an instance of class
Grid
, which represents the global state of the gridworld. The agent is an instance of classAgent
, which represents the agent’s location, orientation, and held item.- grid: gym_gridverse.grid.Grid#
- agent: gym_gridverse.agent.Agent#
Module contents#
Top-level package for gym-gridverse.