tinyspace#

tinyspace#

Dataclass#

class tinyspace.TinySpace(shape, dtype, low, high, cls=None, desc=None)[source]#

A simple and lightweight spaces implementation for RL environments, in place of gym.spaces.

Any Space is a TinySpace with the following args or a dict where each value is a TinySpace.

You can either use this dataclass or just define a Space using dicts, since tinyspace prefers subscriptable access. However, because a TinySpace is a dataclass, dot access also works.

Parameters

Typing#

tinyspace.Space#

alias of Union[tinyspace.TinySpace, Mapping[str, tinyspace.TinySpace]]

Creating#

tinyspace.space_from_dict(d)[source]#
Parameters

d (Union[Dict[str, TypeVar(T)], Dict[str, Dict]]) – a dict to convert to a Space

tinyspace.from_gym_space(gym_space, to_tinyspace=True)[source]#
Parameters
  • gym_space – A gym.Space.

  • to_tinyspace (bool) – If True, then converts to TinySpace dataclass. If False, then leaves it dict.

Return type

Union[TinySpace, Mapping[str, TinySpace]]

tinyspace.to_gym_space(space)[source]#

Convert from tinyspace to gym.spaces.

Parameters

space (Union[TinySpace, Mapping[str, TinySpace]]) – The space to convert.

tinyspace.convert_gymenv_spaces(gym_env, to_tinyspace=True)[source]#

Convert a gym.Env to use tinyspace instead of gym.spaces.

Parameters

gym_env – A gym.Env.

Using#

tinyspace.is_ndshape(space)[source]#

Checks if space.shape is “nd”, meaning atleast one dimension has variable length.

Parameters

space (Union[TinySpace, Mapping[str, TinySpace]]) – A Space to check.

Return type

bool

tinyspace.sample_from_space(space, zeros=True, batch_size=1, ndim_pad=1, to_torch_tensor=False)[source]#
Return type

Union[Dict, ndarray, Tensor]

tinyspace.collate_obs(obses, space, to_torch_tensor=False)[source]#
Parameters