gym_gridverse.representations package#

Submodules#

gym_gridverse.representations.observation_representations module#

class ArrayObservationRepresentation(observation_space)[source]#

Bases: ArrayRepresentation[Observation]

class GridObjectObservationRepresentation(observation_space)[source]#

Bases: ArrayRepresentation[GridObject]

make_observation_representation(name, observation_space)[source]#

Factory function for observation representations

Parameters
  • name (str) – name of the representation

  • observation_space (ObservationSpace) – inner-environment observation space

Return type

ObservationRepresentation

class DictObservationRepresentation(observation_space, representations)[source]#

Bases: ObservationRepresentation

property space: Dict[str, gym_gridverse.representations.spaces.Space]#

returns representation space as as dictionary of numpy arrays

Return type

Dict[str, Space]

convert(observation)[source]#

returns observation representation as dictionary of numpy arrays

Return type

Dict[str, ndarray]

class GridObservationRepresentation(observation_space, grid_object_representation)[source]#

Bases: ArrayObservationRepresentation

property space: gym_gridverse.representations.spaces.Space#
Return type

Space

convert(observation)[source]#
Return type

ndarray

class ItemObservationRepresentation(observation_space, grid_object_representation)[source]#

Bases: ArrayObservationRepresentation

property space: gym_gridverse.representations.spaces.Space#
Return type

Space

convert(observation)[source]#
Return type

ndarray

class AgentIDGridObservationRepresentation(observation_space)[source]#

Bases: ArrayObservationRepresentation

property space: gym_gridverse.representations.spaces.Space#
Return type

Space

convert(observation)[source]#
Return type

ndarray

class DefaultGridObjectObservationRepresentation(observation_space)[source]#

Bases: GridObjectObservationRepresentation

The default representation for a grid-object

Simply returns the grid-object indices. See gym_gridverse.representations.representation.default_grid_object_representation_space() and gym_gridverse.representations.representation.default_grid_object_convert() for more information.

property space: gym_gridverse.representations.spaces.Space#
Return type

Space

convert(grid_object)[source]#
Return type

ndarray

class NoOverlapGridObjectObservationRepresentation(observation_space)[source]#

Bases: GridObjectObservationRepresentation

The no-overlap representation for a grid-object

Guarantees that each channel uses separate indices. See gym_gridverse.representations.representation.no_overlap_grid_object_representation_space() and gym_gridverse.representations.representation.no_overlap_grid_object_convert() for more information.

property space: gym_gridverse.representations.spaces.Space#
Return type

Space

convert(grid_object)[source]#
Return type

ndarray

class CompactGridObjectObservationRepresentation(observation_space)[source]#

Bases: GridObjectObservationRepresentation

The compact representation for a grid-object

Guarantees that each channel uses separate indices, and removes empty gaps between indices. See gym_gridverse.representations.representation.compact_grid_object_representation_space() and gym_gridverse.representations.representation.compact_grid_object_convert() for more information.

property space: gym_gridverse.representations.spaces.Space#
Return type

Space

convert(grid_object)[source]#
Return type

ndarray

gym_gridverse.representations.representation module#

class StateRepresentation(state_space)[source]#

Bases: object

Converts a State into a dictionary of ndarray.

abstract property space: Dict[str, gym_gridverse.representations.spaces.Space]#

returns representation space as as dictionary of numpy arrays

Return type

Dict[str, Space]

abstract convert(state)[source]#

returns state representation as dictionary of numpy arrays

Return type

Dict[str, ndarray]

class ObservationRepresentation(observation_space)[source]#

Bases: object

Converts a Observation into a dictionary of ndarray.

abstract property space: Dict[str, gym_gridverse.representations.spaces.Space]#

returns representation space as as dictionary of numpy arrays

Return type

Dict[str, Space]

abstract convert(observation)[source]#

returns observation representation as dictionary of numpy arrays

Return type

Dict[str, ndarray]

class ArrayRepresentation[source]#

Bases: Generic[T]

abstract property space: gym_gridverse.representations.spaces.Space#
Return type

Space

abstract convert(obj)[source]#
Return type

ndarray

default_grid_object_representation_space(grid_object_types, grid_object_colors)[source]#

The default space of the representation

Returns a Space representing the space of a grid-object represented using type-index, status-index, and color-index.

NOTE: used by DefaultGridObjectStateRepresentation and DefaultGridObjectObservationRepresentation, refactored here because of DRY.

Return type

Space

default_grid_object_representation_convert(grid_object)[source]#

The default conversion of a grid-object

Converts a grid-object into a 3-channel array of:

  • object type index

  • object state index

  • object color index

NOTE: used by DefaultGridObjectStateRepresentation and DefaultObservationGridObjectObservationRepresentation, refactored here because of DRY.

Return type

ndarray

no_overlap_grid_object_representation_space(grid_object_types, grid_object_colors)[source]#

The no-overlap space of the representation

Returns a Space representing the space of a grid-object represented using type-index, status-index, and color-index. Guarantees no overlap across channels, meaning that each channel uses separate indices.

NOTE: used by NoOverlapGridObjectStateRepresentation and NoOverlapGridObjectObservationRepresentation, refactored here because of DRY.

Return type

Space

no_overlap_grid_object_representation_convert(grid_object_types, grid_object_colors, grid_object)[source]#

The no-overlap conversion of a grid-object

Converts a GridObject into a 3-channel array of type-index, status-index, and color-index. Guarantees no overlap across channels, meaning that each channel uses separate indices.

NOTE: used by NoOverlapGridObjectStateRepresentation and NoOverlapGridObjectObservationRepresentation, refactored here because of DRY.

Return type

ndarray

compact_grid_object_representation_space(grid_object_type_map, grid_object_state_map, grid_object_color_map)[source]#

The compact space of the representation

Returns a Space representing the space of a grid-object represented using type-index, status-index, and color-index. Guarantees a compact no overlap representation across channels, meaning that each channel uses separate indices, and there are no gaps between the used indices.

NOTE: used by CompactGridObjectStateRepresentation and CompactGridObjectObservationRepresentation, refactored here because of DRY.

Return type

Space

compact_grid_object_representation_convert(grid_object_type_map, grid_object_state_map, grid_object_color_map, grid_object)[source]#

The no-overlap conversion of a grid-object

Converts a GridObject into a 3-channel array of type-index, status-index, and color-index. Guarantees a compact no overlap representation across channels, meaning that each channel uses separate indices, and there are no gaps between the used indices.

NOTE: used by CompactGridObjectStateRepresentation and CompactGridObjectObservationRepresentation, refactored here because of DRY.

Return type

ndarray

gym_gridverse.representations.spaces module#

class SpaceType(value)[source]#

Bases: Enum

An enumeration.

CATEGORICAL = 0#
DISCRETE = 1#
CONTINUOUS = 2#
is_dtype_integer(x)[source]#

checks if array has an integer type

Parameters

x (numpy.ndarray) – x

Return type

bool

is_dtype_floating(x)[source]#

checks if array has a floating type

Parameters

x (numpy.ndarray) – x

Return type

bool

is_dtype_compatible(x, space_type)[source]#

checks if array type is compatible with space type

Parameters
Return type

bool

class Space(space_type, lower_bound, upper_bound)[source]#

Bases: object

initializes a bounded space

lower_bound and upper_bound must have the same shape, and a dtype compatible with the space_type. Each element of lower_bound must be lower or equal to the corresponding element of upper_bound.

Parameters
__init__(space_type, lower_bound, upper_bound)[source]#

initializes a bounded space

lower_bound and upper_bound must have the same shape, and a dtype compatible with the space_type. Each element of lower_bound must be lower or equal to the corresponding element of upper_bound.

Parameters
property shape: Tuple[int, ...]#
Return type

Tuple[int, ...]

contains(x)[source]#

checks if array is of the correct shape and type, and within the space bounds

Parameters

x (numpy.ndarray) – x

Return type

bool

static make_categorical_space(upper_bound)[source]#

initializes a bounded categorical space

upper_bound must have an integer dtype. Each element of upper_bound must be non-negative.

Parameters

upper_bound (numpy.ndarray) – upper_bound

Return type

Space

static make_discrete_space(lower_bound, upper_bound)[source]#

initializes a bounded discrete space

lower_bound and upper_bound must have the same shape, and an integer dtype. Each element of lower_bound must be lower or equal to the corresponding element of upper_bound.

Parameters
Return type

Space

static make_continuous_space(lower_bound, upper_bound)[source]#

initializes a bounded continuous space

lower_bound and upper_bound must have the same shape, and a floating dtype. Each element of lower_bound must be lower or equal to the corresponding element of upper_bound.

Parameters
Return type

Space

gym_gridverse.representations.state_representations module#

class ArrayStateRepresentation(state_space)[source]#

Bases: ArrayRepresentation[State]

class GridObjectStateRepresentation(state_space)[source]#

Bases: ArrayRepresentation[GridObject]

make_state_representation(name, state_space)[source]#

Factory function for state representations

Parameters
  • name (str) – name of the representation

  • state_space (StateSpace) – inner-environment state space

Return type

StateRepresentation

class DictStateRepresentation(state_space, representations)[source]#

Bases: StateRepresentation

property space: Dict[str, gym_gridverse.representations.spaces.Space]#

returns representation space as as dictionary of numpy arrays

Return type

Dict[str, Space]

convert(state)[source]#

returns state representation as dictionary of numpy arrays

Return type

Dict[str, ndarray]

class GridStateRepresentation(state_space, grid_object_representation)[source]#

Bases: ArrayStateRepresentation

property space: gym_gridverse.representations.spaces.Space#
Return type

Space

convert(state)[source]#
Return type

ndarray

class ItemStateRepresentation(state_space, grid_object_representation)[source]#

Bases: ArrayStateRepresentation

property space: gym_gridverse.representations.spaces.Space#
Return type

Space

convert(state)[source]#
Return type

ndarray

class AgentIDGridStateRepresentation(state_space)[source]#

Bases: ArrayStateRepresentation

property space: gym_gridverse.representations.spaces.Space#
Return type

Space

convert(state)[source]#
Return type

ndarray

class AgentStateRepresentation(state_space)[source]#

Bases: ArrayStateRepresentation

property space: gym_gridverse.representations.spaces.Space#
Return type

Space

convert(state)[source]#
Return type

ndarray

class DefaultGridObjectStateRepresentation(state_space)[source]#

Bases: GridObjectStateRepresentation

The default representation for a grid-object

Simply returns the grid-object indices. See gym_gridverse.representations.representation.default_grid_object_representation_space() and gym_gridverse.representations.representation.default_grid_object_convert() for more information.

property space: gym_gridverse.representations.spaces.Space#
Return type

Space

convert(grid_object)[source]#
Return type

ndarray

class NoOverlapGridObjectStateRepresentation(state_space)[source]#

Bases: GridObjectStateRepresentation

The no-overlap representation for a grid-object

Guarantees that each channel uses separate indices. See gym_gridverse.representations.representation.no_overlap_grid_object_representation_space() and gym_gridverse.representations.representation.no_overlap_grid_object_convert() for more information.

property space: gym_gridverse.representations.spaces.Space#
Return type

Space

convert(grid_object)[source]#
Return type

ndarray

class CompactGridObjectStateRepresentation(state_space)[source]#

Bases: GridObjectStateRepresentation

The compact representation for a grid-object

Guarantees that each channel uses separate indices, and removes empty gaps between indices. See gym_gridverse.representations.representation.compact_grid_object_representation_space() and gym_gridverse.representations.representation.compact_grid_object_convert() for more information.

property space: gym_gridverse.representations.spaces.Space#
Return type

Space

convert(grid_object)[source]#
Return type

ndarray

Module contents#

All that is in between the high-level implementation and low level representation for users