gym_gridverse.utils package#

Submodules#

gym_gridverse.utils.custom module#

is_custom(name)[source]#

Checks if input name indicates a custom function/object

A custom name is expressed as <module_name>:<stripped_name>.

Parameters

name (str) – Potentially custom name

Returns

True iff the input name is custom

Return type

bool

import_custom(name)[source]#

Imports custom module and returns stripped name.

A custom name is expressed as <module_name>:<stripped_name>.

Parameters

name (str) – Custom name

Returns

The stripped name

Return type

str

import_if_custom(name)[source]#

Conditionally imports custom module and returns stripped name.

Combines is_custom() and import_custom().

Parameters

name (str) – Potentially custom name

Returns

If custom, the stripped name, else the input name

Return type

str

gym_gridverse.utils.fast_copy module#

T#

generic type

alias of TypeVar(‘T’)

fast_copy(x)[source]#

returns a deep copy of a generic python object, faster than deepcopy

Return type

TypeVar(T)

gym_gridverse.utils.functions module#

checkraise_kwargs(kwargs, required_keys)[source]#
select_kwargs(kwargs, keys)[source]#

gym_gridverse.utils.protocols module#

get_positional_parameters(signature, n)[source]#
Return type

List[Parameter]

get_keyword_parameter(signature, name)[source]#
Return type

Parameter

gym_gridverse.utils.raytracing module#

Ray#

Ray, a list of positions

alias of List[Position]

compute_ray(position, area, *, radians, step_size, unique=True)[source]#

Returns a ray from a given position.

A ray is a list of positions which are hit by a direct line starting at the center of the given position and moving along the given direction (in radians) until the area is left.

Parameters
  • position (Position) – initial position, must be in area.

  • area (Area) – boundary over rays.

  • radians (float) – ray direction.

  • step_size (float) – ray step granularity.

  • unique (bool) – If true, the same position can appear twice in the ray.

Returns

ray from the given position until the area boundary

Return type

Ray

compute_rays(position, area)[source]#

Returns rays obtained at 1° granularity.

A ray is a list of positions which are hit by a direct line starting at the center of the given position and moving along a direction until the area is left. This method will search for the ingeter directions between 0° and 359°.

Parameters
  • position (Position) – initial position, must be in area.

  • area (Area) – boundary over rays.

Return type

List[Ray]

compute_rays_fancy(position, area)[source]#

Returns rays obtained by targeting edge points.

A ray is a list of positions which are hit by a direct line starting at the center of the given position and moving along a direction until the area is left. This method will search in the directions towards all other cell edges.

Parameters
  • position (Position) – initial position, must be in area.

  • area (Area) – boundary over rays.

Return type

List[Ray]

cached_compute_rays(position, area)#

Returns rays obtained at 1° granularity.

A ray is a list of positions which are hit by a direct line starting at the center of the given position and moving along a direction until the area is left. This method will search for the ingeter directions between 0° and 359°.

Parameters
  • position (Position) – initial position, must be in area.

  • area (Area) – boundary over rays.

Return type

List[Ray]

cached_compute_rays_fancy(position, area)#

Returns rays obtained by targeting edge points.

A ray is a list of positions which are hit by a direct line starting at the center of the given position and moving along a direction until the area is left. This method will search in the directions towards all other cell edges.

Parameters
  • position (Position) – initial position, must be in area.

  • area (Area) – boundary over rays.

Return type

List[Ray]

gym_gridverse.utils.registry module#

class FunctionRegistry(dict=None, /, **kwargs)[source]#

Bases: UserDict

abstract get_protocol_parameters(signature)[source]#
Return type

List[Parameter]

get_nonprotocol_parameters(signature)[source]#
Return type

List[Parameter]

abstract check_signature(function)[source]#
register(function=None, *, name=None)[source]#

Register a function in this registry.

This method can be either called directly or used as a decorator. Before registration, the function signature is checked to make sure it matches the appropriate protocol, and the name is checked to avoid conflicts. If name is not given, function.__name__ is used.

Usage:

>>> @registry.register
>>> def function_1(...):
        ...
>>> @registry.register(name='alt_name_2')
>>> def function_2(...):
        ...
>>> def function_3(...):
        ...
>>> registry.register(function_3)
>>> def function_4(...):
        ...
>>> registry.register(function_4, name='alt_name_4')
Parameters
  • function – (Callable, optional)

  • name (Optional[str]) – (str, optional)

gym_gridverse.utils.rl module#

make_return_computer(discount)[source]#

Coroutine which receives rewards and yields cumulative discounted returns

Return type

Callable[[float], float]

gym_gridverse.utils.space_builders module#

class StateSpaceBuilder[source]#

Bases: object

set_grid_shape(grid_shape)[source]#
set_object_types(object_types)[source]#
set_colors(colors)[source]#
build()[source]#
Return type

StateSpace

class ObservationSpaceBuilder[source]#

Bases: object

set_grid_shape(grid_shape)[source]#
set_object_types(object_types)[source]#
set_colors(colors)[source]#
build()[source]#
Return type

ObservationSpace

Module contents#