gym_gridverse package#

Subpackages#

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#
is_move()[source]#

True if the action is a movement action

Return type

bool

is_turn()[source]#

True if the action is a turn action

Return type

bool

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.

front()[source]#
Return type

Position

property position: gym_gridverse.geometry.Position#
Return type

Position

property orientation: gym_gridverse.geometry.Orientation#
Return type

Orientation

gym_gridverse.debugging module#

reset_gv_debug(debug=None)[source]#

Sets the library-wide debugging boolean.

Return type

bool

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

bool

checkraise(condition_f, error_type, error_message_fmt, *args, **kwargs)[source]#

gym_gridverse.design module#

draw_wall_boundary(grid)[source]#

draw boundary of walls on grid

Return type

List[Position]

draw_room(grid, area, factory)[source]#

use factory-created grid-objects to draw room boundary on grid

Return type

List[Position]

draw_room_grid(grid, ys, xs, factory)[source]#

use factory-created grid-objects to draw a grid of rooms on grid

Return type

List[Position]

draw_area(grid, area, factory, *, fill)[source]#

use factory-created grid-objects to draw area on grid

Return type

List[Position]

draw_line_horizontal(grid, y, xs, factory)[source]#

use factory-created grid-objects to draw horizontal line on grid

Return type

List[Position]

draw_line_vertical(grid, ys, x, factory)[source]#

use factory-created grid-objects to draw vertical line on grid

Return type

List[Position]

draw_cartesian_product(grid, ys, xs, factory)[source]#

use factory-created grid-objects to draw on grid

Return type

List[Position]

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.

height: int#
width: int#
property as_tuple: Tuple[int, int]#
Return type

Tuple[int, int]

class Area(ys, xs)[source]#

Bases: object

2D area, which extends vertically and horizontally

ys: Tuple[int, int]#
xs: Tuple[int, int]#
static from_positions(positions)[source]#
Return type

Area

property ymin: int#
Return type

int

property ymax: int#
Return type

int

property xmin: int#
Return type

int

property xmax: int#
Return type

int

property height: int#
Return type

int

property width: int#
Return type

int

y_coordinates()[source]#

iterator over y coordinates

Return type

Iterable[int]

x_coordinates()[source]#

iterator over x coordinates

Return type

Iterable[int]

positions(selection='all')[source]#

iterator over all/border/inside positions

Parameters

selection (str) – ‘all’, ‘border’, or ‘inside’

Returns

selected positions

Return type

Iterable[Position]

contains(position)[source]#
Return type

bool

class Position(y, x)[source]#

Bases: object

2D position (y, x), with y extending downward and x extending rightward

y: int#
x: int#
property yx: Tuple[int, int]#
Return type

Tuple[int, int]

static from_orientation(orientation)[source]#
Return type

Position

static manhattan_distance(p, q)[source]#
Return type

float

static euclidean_distance(p, q)[source]#
Return type

float

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
Parameters
  • position (Position) – The center of the return boundary (excluded)

  • distance (int) – The distance of the boundary returned

Returns

List of positions (excluding pos) representing the boundary

Return type

List[Position]

distance_function_factory(name)[source]#

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.

Parameters
  • shape (Union[Shape, Tuple[int, int]]) –

  • factory (GridObjectFactory) –

Returns

The grid of the appropriate size, with generated objects

Return type

Grid

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
  • position (Union[Position, Tuple[int, int]]) –

  • factory (GridObjectFactory) –

Return type

GridObject

swap(p, q)[source]#

Swaps the grid objects at two positions.

Parameters
subgrid(area)[source]#

Returns subgrid slice at given area.

Cells included in the area but outside of the grid are represented as Hidden objects.

Parameters

area (Area) – The area to be sliced

Returns

New instance, sliced appropriately

Return type

Grid

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

Type[GridObject]

names()[source]#

Returns the names of registered grid-objects

Return type

List[str]

from_name(name)[source]#

Returns the grid-object class associated with a name

Return type

Type[GridObject]

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 GridObjectMeta(name, bases, namespace, **kwargs)[source]#

Bases: ABCMeta

class GridObject(*args, **kwargs)[source]#

Bases: object

Represents the contents of a grid cell

abstract property state_index: int#

State index of this grid-object

Return type

int

abstract property color: gym_gridverse.grid_object.Color#

Color of this grid-object

Return type

Color

abstract property blocks_movement: bool#

Whether this grid-object blocks the agent from moving on it

Return type

bool

abstract property blocks_vision: bool#

Whether this grid-object blocks the agent’s vision.

Return type

bool

abstract property holdable: bool#

Whether the agent can pick up this grid-object

Return type

bool

classmethod type_index()[source]#
Return type

int

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., a Box contains a reference to another GridObject as its content. The unfortunate implication is that this GridObject (and, by extension, any Grido or Environment which contains this type of GridObject) 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

bool

abstract classmethod num_states()[source]#

Number of internal states.

GridObjects themselves can have internal states, e.g., a Door may be open, closed, or locked. This classmethod return the number of possible states that this GridObject may have.

Return type

int

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., a Box contains a reference to another GridObject as its content. The unfortunate implication is that this GridObject (and, by extension, any Grido or Environment which contains this type of GridObject) 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

bool

classmethod num_states()[source]#

Number of internal states.

GridObjects themselves can have internal states, e.g., a Door may be open, closed, or locked. This classmethod return the number of possible states that this GridObject may have.

Return type

int

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., a Box contains a reference to another GridObject as its content. The unfortunate implication is that this GridObject (and, by extension, any Grido or Environment which contains this type of GridObject) 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

bool

classmethod num_states()[source]#

Number of internal states.

GridObjects themselves can have internal states, e.g., a Door may be open, closed, or locked. This classmethod return the number of possible states that this GridObject may have.

Return type

int

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., a Box contains a reference to another GridObject as its content. The unfortunate implication is that this GridObject (and, by extension, any Grido or Environment which contains this type of GridObject) 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

bool

classmethod num_states()[source]#

Number of internal states.

GridObjects themselves can have internal states, e.g., a Door may be open, closed, or locked. This classmethod return the number of possible states that this GridObject may have.

Return type

int

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., a Box contains a reference to another GridObject as its content. The unfortunate implication is that this GridObject (and, by extension, any Grido or Environment which contains this type of GridObject) 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

bool

classmethod num_states()[source]#

Number of internal states.

GridObjects themselves can have internal states, e.g., a Door may be open, closed, or locked. This classmethod return the number of possible states that this GridObject may have.

Return type

int

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., a Box contains a reference to another GridObject as its content. The unfortunate implication is that this GridObject (and, by extension, any Grido or Environment which contains this type of GridObject) 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

bool

classmethod num_states()[source]#

Number of internal states.

GridObjects themselves can have internal states, e.g., a Door may be open, closed, or locked. This classmethod return the number of possible states that this GridObject may have.

Return type

int

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#
class Status(value)[source]#

Bases: Enum

An enumeration.

OPEN = 0#
CLOSED = 1#
LOCKED = 2#
state: Status#
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., a Box contains a reference to another GridObject as its content. The unfortunate implication is that this GridObject (and, by extension, any Grido or Environment which contains this type of GridObject) 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

bool

classmethod num_states()[source]#

Number of internal states.

GridObjects themselves can have internal states, e.g., a Door may be open, closed, or locked. This classmethod return the number of possible states that this GridObject may have.

Return type

int

property state_index: int#

State index of this grid-object

Return type

int

property blocks_movement: bool#

Whether this grid-object blocks the agent from moving on it

Return type

bool

property blocks_vision: bool#

Whether this grid-object blocks the agent’s vision.

Return type

bool

property is_open: bool#

returns whether the door is opened.

Return type

bool

property is_locked: bool#

returns whether the door is locked.

Return type

bool

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., a Box contains a reference to another GridObject as its content. The unfortunate implication is that this GridObject (and, by extension, any Grido or Environment which contains this type of GridObject) 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

bool

classmethod num_states()[source]#

Number of internal states.

GridObjects themselves can have internal states, e.g., a Door may be open, closed, or locked. This classmethod return the number of possible states that this GridObject may have.

Return type

int

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., a Box contains a reference to another GridObject as its content. The unfortunate implication is that this GridObject (and, by extension, any Grido or Environment which contains this type of GridObject) 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

bool

classmethod num_states()[source]#

Number of internal states.

GridObjects themselves can have internal states, e.g., a Door may be open, closed, or locked. This classmethod return the number of possible states that this GridObject may have.

Return type

int

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., a Box contains a reference to another GridObject as its content. The unfortunate implication is that this GridObject (and, by extension, any Grido or Environment which contains this type of GridObject) 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

bool

classmethod num_states()[source]#

Number of internal states.

GridObjects themselves can have internal states, e.g., a Door may be open, closed, or locked. This classmethod return the number of possible states that this GridObject may have.

Return type

int

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., a Box contains a reference to another GridObject as its content. The unfortunate implication is that this GridObject (and, by extension, any Grido or Environment which contains this type of GridObject) 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

bool

classmethod num_states()[source]#

Number of internal states.

GridObjects themselves can have internal states, e.g., a Door may be open, closed, or locked. This classmethod return the number of possible states that this GridObject may have.

Return type

int

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., a Box contains a reference to another GridObject as its content. The unfortunate implication is that this GridObject (and, by extension, any Grido or Environment which contains this type of GridObject) 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

bool

classmethod num_states()[source]#

Number of internal states.

GridObjects themselves can have internal states, e.g., a Door may be open, closed, or locked. This classmethod return the number of possible states that this GridObject may have.

Return type

int

GridObjectFactory#

A callable which returns grid objects.

alias of Callable[[], GridObject]

gym_gridverse.gym module#

outer_space_to_gym_space(space)[source]#
Return type

Space

from_factory(factory)[source]#
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>

set_state_representation(name)[source]#

Changes the state representation.

set_observation_representation(name)[source]#

Changes the observation representation.

property state: Dict[str, numpy.ndarray]#

Returns the representation of the current state.

Return type

Dict[str, ndarray]

property observation: Dict[str, numpy.ndarray]#

Returns the representation of the current observation.

Return type

Dict[str, ndarray]

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

close()[source]#

Override close in your subclass to perform any necessary cleanup.

Environments will automatically close() themselves when garbage collected or when the program exits.

class GymStateWrapper(env)[source]#

Bases: Wrapper

Gym Wrapper to replace the standard observation representation with state instead.

Doesn’t change underlying environment, won’t change render

property observation: Dict[str, numpy.ndarray]#
Return type

Dict[str, ndarray]

reset()[source]#

reset the environment state

Returns

initial state

Return type

Dict[str, numpy.ndarray]

step(action)[source]#

performs environment step

Parameters

action (int) – agent’s action

Returns

(state, reward, terminal, info dictionary)

Return type

Tuple[Dict[str, numpy.ndarray], float, bool, Dict]

outer_env_factory(yaml_filename)[source]#
Return type

OuterEnv

factory() OuterEnv#

gym_gridverse.observation module#

Defines the Observation class

class Observation(grid, agent)[source]#

Bases: object

An observation is a pure data-class containing grid and agent 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 class Agent, 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 by Action.

property action_space: gym_gridverse.spaces.ActionSpace#

Returns the action space of the problem.

Return type

ActionSpace

reset()[source]#

Resets the state

Return type

None

step(action)[source]#

Runs the dynamics for one timestep, and returns reward and done flag

Parameters

action (Action) – agent’s action

Returns

(reward, terminality)

Return type

Tuple[float, bool]

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]#

Bases: Generic[FrameType]

Data for recordings of states or observations

frames: Sequence[gym_gridverse.recording.FrameType]#
actions: Sequence[gym_gridverse.action.Action]#
rewards: Sequence[float]#
discount: float#
property is_state_data: bool#
Return type

bool

property is_observation_data: bool#
Return type

bool

property is_image_data: bool#
Return type

bool

class DataBuilder(discount)[source]#

Bases: Generic[FrameType]

Builds Data object interactively

frames: List[gym_gridverse.recording.FrameType]#
actions: List[gym_gridverse.action.Action]#
rewards: List[float]#
discount: float#
append0(frame)[source]#
append(frame, action, reward)[source]#
build()[source]#
Return type

Data[TypeVar(FrameType, State, Observation, ndarray)]

class HUD_Info(_typename, _fields=None, /, **kwargs)[source]#

Bases: dict

action: Optional[gym_gridverse.action.Action]#
reward: Optional[float]#
ret: Optional[float]#
done: Optional[bool]#
generate_images(data)[source]#

Generate images associated with the input data

Return type

Iterator[ndarray]

record(mode, images, *, filename=None, filenames=None, **kwargs)[source]#

Factory function for other recording functions

record_images(filenames, images, **kwargs)[source]#

Create image files from input images

record_gif(filename, images, *, loop=0, fps=2.0, duration=None, **kwargs)[source]#

Create a gif file from input images

record_mp4(filename, images, *, fps=2.0, duration=None, **kwargs)[source]#

Create an mp4 file from input images

gym_gridverse.rendering module#

class Group(geoms)[source]#

Bases: Geom

like rendering.Compound, but without sharing attributes

render1()[source]#
make_grid(start, end, num_rows, num_cols)[source]#
Return type

Geom

make_spiral(polar_from, polar_to, res)[source]#
make_grid_background()[source]#
Return type

Geom

make_agent()[source]#
Return type

Geom

make_exit(exit_)[source]#
Return type

Geom

make_hidden(hidden)[source]#
Return type

Geom

make_wall(wall)[source]#
Return type

Geom

make_door(door)[source]#
Return type

Geom

make_capsule(length, width, *, filled=True)[source]#
make_key(key)[source]#
Return type

Geom

make_moving_obstacle(obstacle)[source]#
Return type

Geom

make_telepod(telepod)[source]#
Return type

Geom

make_beacon(beacon)[source]#
Return type

Geom

make_unknown(obj)[source]#
Return type

Geom

convert_pos(position, *, num_rows)[source]#
Return type

Tuple[float, float]

class GridVerseViewer(shape, *, caption=None)[source]#

Bases: object

close()[source]#
flip_visibility()[source]#
flip_hud()[source]#
property window: pyglet.window.BaseWindow#
Return type

BaseWindow

render(state_or_observation, *, action=None, reward=None, ret=None, done=None, return_rgb_array=False)[source]#

gym_gridverse.rng module#

make_rng(seed=None)[source]#

make a new rng object

Return type

Generator

reset_gv_rng(seed=None)[source]#

reset the gym-gridverse module rng

Return type

Generator

get_gv_rng()[source]#

get (and reset if necessary) gym-gridverse module rng

Return type

Generator

get_gv_rng_if_none(rng)[source]#

get gym-gridverse module rng if input is None

Return type

Generator

T#

generic type

alias of TypeVar(‘T’)

choice(rng, data)[source]#

randomly chooses one element from the input data

Return type

TypeVar(T)

choices(rng, data, *, size, **kwargs)[source]#

randomly chooses multiple elements from the input data

Return type

List[TypeVar(T)]

shuffle(rng, data)[source]#

randomly shuffles the data

Return type

List[TypeVar(T)]

gym_gridverse.spaces module#

class StateSpace(grid_shape, object_types, colors)[source]#

Bases: object

contains(state)[source]#

True if the state satisfies the state-space

Return type

bool

property can_be_represented#
property agent_state_size: Tuple[int, int, int, int, int]#
Return type

Tuple[int, int, int, int, int]

property agent_state_shape: int#
Return type

int

property grid_state_shape: gym_gridverse.geometry.Shape#
Return type

Shape

property max_object_color: int#
Return type

int

property max_type_index: int#
Return type

int

property max_state_index: int#
Return type

int

property max_grid_object_type: int#
Return type

int

property max_grid_object_status: int#
Return type

int

property max_agent_object_type: int#
Return type

int

property max_agent_object_status: int#
Return type

int

class ActionSpace(actions)[source]#

Bases: object

contains(action)[source]#

True if the action satisfies the action-space

Return type

bool

int_to_action(action)[source]#
Return type

Action

action_to_int(action)[source]#
Return type

int

property num_actions: int#
Return type

int

class ObservationSpace(grid_shape, object_types, colors)[source]#

Bases: object

contains(observation)[source]#

True if the observation satisfies the observation-space

Return type

bool

property agent_state_size: Tuple[int, int, int, int, int]#
Return type

Tuple[int, int, int, int, int]

property agent_state_shape: int#
Return type

int

property grid_state_shape: gym_gridverse.geometry.Shape#
Return type

Shape

property max_object_color: int#
Return type

int

property max_type_index: int#
Return type

int

property max_state_index: int#
Return type

int

property max_grid_object_type: int#
Return type

int

property max_grid_object_status: int#
Return type

int

property max_agent_object_type: int#
Return type

int

property max_agent_object_status: int#
Return type

int

gym_gridverse.state module#

Defines the State class

class State(grid, agent)[source]#

Bases: object

A state is a pure data-class containing grid and agent 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 class Agent, 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.