# hub.space.gym.gym
Domain specification
# GymSpace
This class wraps a gymnasium space (gym.spaces) as a scikit-decide space.
WARNING
Using this class requires gymnasium to be installed.
# Constructor GymSpace
GymSpace(
gym_space: gym.Space
) -> None
Initialize GymSpace.
# Parameters
- gym_space: The Gym space (gym.spaces) to wrap.
# contains Space
contains(
self,
x: T
) -> bool
Check whether x is a valid member of this space.
# Parameters
- x: The member to consider.
# Returns
True if x is a valid member of this space (False otherwise).
# from_jsonable SerializableSpace
from_jsonable(
self,
sample_n: Sequence
) -> Iterable[T]
Convert a JSONable data type to a batch of samples from this space.
# Parameters
- sample_n: The JSONable data type to convert.
# Returns
The resulting batch of samples.
# sample SamplableSpace
sample(
self
) -> T
Uniformly randomly sample a random element of this space.
# Returns
The sampled element.
# to_jsonable SerializableSpace
to_jsonable(
self,
sample_n: Iterable[T]
) -> Sequence
Convert a batch of samples from this space to a JSONable data type.
# Parameters
- sample_n: The batch of samples to convert.
# Returns
The resulting JSONable data type.
# unwrapped GymSpace
unwrapped(
self
) -> gym.Space
Unwrap the Gym space (gym.spaces) and return it.
# Returns
The original Gym space.
# BoxSpace
This class wraps a gymnasium Box space (gym.spaces.Box) as a scikit-decide space.
WARNING
Using this class requires gymnasium to be installed.
# Constructor BoxSpace
BoxSpace(
low,
high,
shape = None,
dtype = <class 'numpy.float32'>
)
Initialize GymSpace.
# Parameters
- gym_space: The Gym space (gym.spaces) to wrap.
# contains Space
contains(
self,
x: T
) -> bool
Check whether x is a valid member of this space.
# Parameters
- x: The member to consider.
# Returns
True if x is a valid member of this space (False otherwise).
# from_jsonable SerializableSpace
from_jsonable(
self,
sample_n: Sequence
) -> Iterable[T]
Convert a JSONable data type to a batch of samples from this space.
# Parameters
- sample_n: The JSONable data type to convert.
# Returns
The resulting batch of samples.
# sample SamplableSpace
sample(
self
) -> T
Uniformly randomly sample a random element of this space.
# Returns
The sampled element.
# to_jsonable SerializableSpace
to_jsonable(
self,
sample_n: Iterable[T]
) -> Sequence
Convert a batch of samples from this space to a JSONable data type.
# Parameters
- sample_n: The batch of samples to convert.
# Returns
The resulting JSONable data type.
# unwrapped GymSpace
unwrapped(
self
) -> gym.Space
Unwrap the Gym space (gym.spaces) and return it.
# Returns
The original Gym space.
# DiscreteSpace
This class wraps a gymnasium Discrete space (gym.spaces.Discrete) as a scikit-decide space.
WARNING
Using this class requires gymnasium to be installed.
# Constructor DiscreteSpace
DiscreteSpace(
n,
element_class = <class 'int'>
)
Initialize GymSpace.
# Parameters
- gym_space: The Gym space (gym.spaces) to wrap.
# contains Space
contains(
self,
x: T
) -> bool
Check whether x is a valid member of this space.
# Parameters
- x: The member to consider.
# Returns
True if x is a valid member of this space (False otherwise).
# from_jsonable SerializableSpace
from_jsonable(
self,
sample_n: Sequence
) -> Iterable[T]
Convert a JSONable data type to a batch of samples from this space.
# Parameters
- sample_n: The JSONable data type to convert.
# Returns
The resulting batch of samples.
# get_elements EnumerableSpace
get_elements(
self
) -> Iterable[T]
Get the elements of this space.
# Returns
The elements of this space.
# sample SamplableSpace
sample(
self
) -> T
Uniformly randomly sample a random element of this space.
# Returns
The sampled element.
# to_jsonable SerializableSpace
to_jsonable(
self,
sample_n: Iterable[T]
) -> Sequence
Convert a batch of samples from this space to a JSONable data type.
# Parameters
- sample_n: The batch of samples to convert.
# Returns
The resulting JSONable data type.
# unwrapped GymSpace
unwrapped(
self
) -> gym.Space
Unwrap the Gym space (gym.spaces) and return it.
# Returns
The original Gym space.
# MultiDiscreteSpace
This class wraps a gymnasium MultiDiscrete space (gym.spaces.MultiDiscrete) as a scikit-decide space.
WARNING
Using this class requires gymnasium to be installed.
# Constructor MultiDiscreteSpace
MultiDiscreteSpace(
nvec,
element_class = <class 'numpy.ndarray'>
)
Initialize GymSpace.
# Parameters
- gym_space: The Gym space (gym.spaces) to wrap.
# contains Space
contains(
self,
x: T
) -> bool
Check whether x is a valid member of this space.
# Parameters
- x: The member to consider.
# Returns
True if x is a valid member of this space (False otherwise).
# from_jsonable SerializableSpace
from_jsonable(
self,
sample_n: Sequence
) -> Iterable[T]
Convert a JSONable data type to a batch of samples from this space.
# Parameters
- sample_n: The JSONable data type to convert.
# Returns
The resulting batch of samples.
# get_elements EnumerableSpace
get_elements(
self
) -> Iterable[T]
Get the elements of this space.
# Returns
The elements of this space.
# sample SamplableSpace
sample(
self
) -> T
Uniformly randomly sample a random element of this space.
# Returns
The sampled element.
# to_jsonable SerializableSpace
to_jsonable(
self,
sample_n: Iterable[T]
) -> Sequence
Convert a batch of samples from this space to a JSONable data type.
# Parameters
- sample_n: The batch of samples to convert.
# Returns
The resulting JSONable data type.
# unwrapped GymSpace
unwrapped(
self
) -> gym.Space
Unwrap the Gym space (gym.spaces) and return it.
# Returns
The original Gym space.
# MultiBinarySpace
This class wraps a gymnasium MultiBinary space (gym.spaces.MultiBinary) as a scikit-decide space.
WARNING
Using this class requires gymnasium to be installed.
# Constructor MultiBinarySpace
MultiBinarySpace(
n,
element_class = <class 'numpy.ndarray'>
)
Initialize GymSpace.
# Parameters
- gym_space: The Gym space (gym.spaces) to wrap.
# contains Space
contains(
self,
x: T
) -> bool
Check whether x is a valid member of this space.
# Parameters
- x: The member to consider.
# Returns
True if x is a valid member of this space (False otherwise).
# from_jsonable SerializableSpace
from_jsonable(
self,
sample_n: Sequence
) -> Iterable[T]
Convert a JSONable data type to a batch of samples from this space.
# Parameters
- sample_n: The JSONable data type to convert.
# Returns
The resulting batch of samples.
# get_elements EnumerableSpace
get_elements(
self
) -> Iterable[T]
Get the elements of this space.
# Returns
The elements of this space.
# sample SamplableSpace
sample(
self
) -> T
Uniformly randomly sample a random element of this space.
# Returns
The sampled element.
# to_jsonable SerializableSpace
to_jsonable(
self,
sample_n: Iterable[T]
) -> Sequence
Convert a batch of samples from this space to a JSONable data type.
# Parameters
- sample_n: The batch of samples to convert.
# Returns
The resulting JSONable data type.
# unwrapped GymSpace
unwrapped(
self
) -> gym.Space
Unwrap the Gym space (gym.spaces) and return it.
# Returns
The original Gym space.
# TupleSpace
This class wraps a gymnasium Tuple space (gym.spaces.Tuple) as a scikit-decide space.
WARNING
Using this class requires gymnasium to be installed.
# Constructor TupleSpace
TupleSpace(
spaces: tuple[Union[GymSpace[T], gym.Space]],
element_class = <class 'tuple'>
)
Initialize GymSpace.
# Parameters
- gym_space: The Gym space (gym.spaces) to wrap.
# contains Space
contains(
self,
x: T
) -> bool
Check whether x is a valid member of this space.
# Parameters
- x: The member to consider.
# Returns
True if x is a valid member of this space (False otherwise).
# from_jsonable SerializableSpace
from_jsonable(
self,
sample_n: Sequence
) -> Iterable[T]
Convert a JSONable data type to a batch of samples from this space.
# Parameters
- sample_n: The JSONable data type to convert.
# Returns
The resulting batch of samples.
# sample SamplableSpace
sample(
self
) -> T
Uniformly randomly sample a random element of this space.
# Returns
The sampled element.
# to_jsonable SerializableSpace
to_jsonable(
self,
sample_n: Iterable[T]
) -> Sequence
Convert a batch of samples from this space to a JSONable data type.
# Parameters
- sample_n: The batch of samples to convert.
# Returns
The resulting JSONable data type.
# unwrapped GymSpace
unwrapped(
self
) -> gym.Space
Unwrap the Gym space (gym.spaces) and return it.
# Returns
The original Gym space.
# DictSpace
This class wraps a gymnasium Dict space (gym.spaces.Dict) as a scikit-decide space.
WARNING
Using this class requires gymnasium to be installed.
# Constructor DictSpace
DictSpace(
spaces: dict[Any, Union[GymSpace[T], gym.Space]] = None,
element_class = <class 'dict'>,
**spaces_kwargs
)
Initialize GymSpace.
# Parameters
- gym_space: The Gym space (gym.spaces) to wrap.
# contains Space
contains(
self,
x: T
) -> bool
Check whether x is a valid member of this space.
# Parameters
- x: The member to consider.
# Returns
True if x is a valid member of this space (False otherwise).
# from_jsonable SerializableSpace
from_jsonable(
self,
sample_n: Sequence
) -> Iterable[T]
Convert a JSONable data type to a batch of samples from this space.
# Parameters
- sample_n: The JSONable data type to convert.
# Returns
The resulting batch of samples.
# sample SamplableSpace
sample(
self
) -> T
Uniformly randomly sample a random element of this space.
# Returns
The sampled element.
# to_jsonable SerializableSpace
to_jsonable(
self,
sample_n: Iterable[T]
) -> Sequence
Convert a batch of samples from this space to a JSONable data type.
# Parameters
- sample_n: The batch of samples to convert.
# Returns
The resulting JSONable data type.
# unwrapped GymSpace
unwrapped(
self
) -> gym.Space
Unwrap the Gym space (gym.spaces) and return it.
# Returns
The original Gym space.
# EnumSpace
This class creates a gymnasium Discrete space (gym.spaces.Discrete) from an enumeration and wraps it as a scikit-decide enumerable space.
WARNING
Using this class requires gymnasium to be installed.
# Constructor EnumSpace
EnumSpace(
enum_class: EnumMeta
) -> None
Initialize EnumSpace.
# Parameters
- enum_class: The enumeration class for creating the Gym Discrete space (gym.spaces.Discrete) to wrap.
# contains Space
contains(
self,
x: T
) -> bool
Check whether x is a valid member of this space.
# Parameters
- x: The member to consider.
# Returns
True if x is a valid member of this space (False otherwise).
# from_jsonable SerializableSpace
from_jsonable(
self,
sample_n: Sequence
) -> Iterable[T]
Convert a JSONable data type to a batch of samples from this space.
# Parameters
- sample_n: The JSONable data type to convert.
# Returns
The resulting batch of samples.
# get_elements EnumerableSpace
get_elements(
self
) -> Iterable[T]
Get the elements of this space.
# Returns
The elements of this space.
# sample SamplableSpace
sample(
self
) -> T
Uniformly randomly sample a random element of this space.
# Returns
The sampled element.
# to_jsonable SerializableSpace
to_jsonable(
self,
sample_n: Iterable[T]
) -> Sequence
Convert a batch of samples from this space to a JSONable data type.
# Parameters
- sample_n: The batch of samples to convert.
# Returns
The resulting JSONable data type.
# unwrapped GymSpace
unwrapped(
self
) -> gym_spaces.Discrete
Unwrap the Gym Discrete space (gym.spaces.Discrete) and return it.
# Returns
The original Gym Discrete space created from the enumeration.
# ListSpace
This class creates a gymnasium Discrete space (gym.spaces.Discrete) from a list of elements and wraps it as a scikit-decide enumerable space. If ordering is not important contrary to the 'contains' test, it is advised to use the 'SetSpace' class instead.
WARNING
Using this class requires gymnasium to be installed.
# Constructor ListSpace
ListSpace(
elements: Iterable[T]
) -> None
Initialize ListSpace.
# Parameters
- elements: The list of elements for creating the Gym Discrete space (gym.spaces.Discrete) to wrap.
# contains Space
contains(
self,
x: T
) -> bool
Check whether x is a valid member of this space.
# Parameters
- x: The member to consider.
# Returns
True if x is a valid member of this space (False otherwise).
# from_jsonable SerializableSpace
from_jsonable(
self,
sample_n: Sequence
) -> Iterable[T]
Convert a JSONable data type to a batch of samples from this space.
# Parameters
- sample_n: The JSONable data type to convert.
# Returns
The resulting batch of samples.
# get_elements EnumerableSpace
get_elements(
self
) -> Iterable[T]
Get the elements of this space.
# Returns
The elements of this space.
# sample SamplableSpace
sample(
self
) -> T
Uniformly randomly sample a random element of this space.
# Returns
The sampled element.
# to_jsonable SerializableSpace
to_jsonable(
self,
sample_n: Iterable[T]
) -> Sequence
Convert a batch of samples from this space to a JSONable data type.
# Parameters
- sample_n: The batch of samples to convert.
# Returns
The resulting JSONable data type.
# unwrapped GymSpace
unwrapped(
self
) -> gym_spaces.Discrete
Unwrap the Gym Discrete space (gym.spaces.Discrete) and return it.
# Returns
The original Gym Discrete space created from the list.
# SetSpace
This class creates a gymnasium Discrete space (gym.spaces.Discrete) from a set of elements and wraps it as a scikit-decide enumerable space.
WARNING
Using this class requires gymnasium to be installed.
# Constructor SetSpace
SetSpace(
elements: Iterable[T]
) -> None
Initialize SetSpace.
# Parameters
- elements: The set of elements for creating the Gym Discrete space (gym.spaces.Discrete) to wrap.
# contains Space
contains(
self,
x: T
) -> bool
Check whether x is a valid member of this space.
# Parameters
- x: The member to consider.
# Returns
True if x is a valid member of this space (False otherwise).
# from_jsonable SerializableSpace
from_jsonable(
self,
sample_n: Sequence
) -> Iterable[T]
Convert a JSONable data type to a batch of samples from this space.
# Parameters
- sample_n: The JSONable data type to convert.
# Returns
The resulting batch of samples.
# get_elements EnumerableSpace
get_elements(
self
) -> Iterable[T]
Get the elements of this space.
# Returns
The elements of this space.
# sample SamplableSpace
sample(
self
) -> T
Uniformly randomly sample a random element of this space.
# Returns
The sampled element.
# to_jsonable SerializableSpace
to_jsonable(
self,
sample_n: Iterable[T]
) -> Sequence
Convert a batch of samples from this space to a JSONable data type.
# Parameters
- sample_n: The batch of samples to convert.
# Returns
The resulting JSONable data type.
# unwrapped GymSpace
unwrapped(
self
) -> gym_spaces.Discrete
Unwrap the Gym Discrete space (gym.spaces.Discrete) and return it.
# Returns
The original Gym Discrete space created from the list.
# DataSpace
This class creates a gymnasium Dict space (gym.spaces.Dict) from a dataclass and wraps it as a scikit-decide space.
WARNING
Using this class requires gymnasium to be installed.
# Constructor DataSpace
DataSpace(
data_class: type,
spaces: Union[dict[str, gym.Space], list[tuple[str, gym.Space]]]
) -> None
Initialize DataSpace.
# Parameters
- data_class: The dataclass for creating the Gym Dict space (gym.spaces.Dict) to wrap.
- spaces: The spaces description passed to the created Dict space (see gym.spaces.Dict constructor documentation).
# Example
from skdecide.wrappers.space import DataSpace
@dataclass(frozen=True)
class Action:
position: int
velocity: int
my_action_space = DataSpace(Action, {"position": gym.spaces.Discrete(2), "velocity": gym.spaces.Discrete(3)})
# contains Space
contains(
self,
x: T
) -> bool
Check whether x is a valid member of this space.
# Parameters
- x: The member to consider.
# Returns
True if x is a valid member of this space (False otherwise).
# from_jsonable SerializableSpace
from_jsonable(
self,
sample_n: Sequence
) -> Iterable[T]
Convert a JSONable data type to a batch of samples from this space.
# Parameters
- sample_n: The JSONable data type to convert.
# Returns
The resulting batch of samples.
# sample SamplableSpace
sample(
self
) -> T
Uniformly randomly sample a random element of this space.
# Returns
The sampled element.
# to_jsonable SerializableSpace
to_jsonable(
self,
sample_n: Iterable[T]
) -> Sequence
Convert a batch of samples from this space to a JSONable data type.
# Parameters
- sample_n: The batch of samples to convert.
# Returns
The resulting JSONable data type.
# unwrapped GymSpace
unwrapped(
self
) -> gym_spaces.Dict
Unwrap the Gym Dict space (gym.spaces.Dict) and return it.
# Returns
The original Gym Dict space created from the dataclass.
# VariableSpace
This class wraps a gymnasium Space (gym.spaces.Space) to allow dynamic length of elements.
# Constructor VariableSpace
VariableSpace(
space: gym.Space,
max_len: int,
**kwargs
)
Initialize GymSpace.
# Parameters
- gym_space: The Gym space (gym.spaces) to wrap.
# contains Space
contains(
self,
x: T
) -> bool
Check whether x is a valid member of this space.
# Parameters
- x: The member to consider.
# Returns
True if x is a valid member of this space (False otherwise).
# from_jsonable SerializableSpace
from_jsonable(
self,
sample_n: Sequence
) -> Iterable[T]
Convert a JSONable data type to a batch of samples from this space.
# Parameters
- sample_n: The JSONable data type to convert.
# Returns
The resulting batch of samples.
# sample SamplableSpace
sample(
self
)
Uniformly randomly sample a random element of this space.
# Returns
The sampled element.
# to_jsonable SerializableSpace
to_jsonable(
self,
sample_n: Iterable[T]
) -> Sequence
Convert a batch of samples from this space to a JSONable data type.
# Parameters
- sample_n: The batch of samples to convert.
# Returns
The resulting JSONable data type.
# unwrapped GymSpace
unwrapped(
self
)
Unwrap the Gym space (gym.spaces) and return it.
# Returns
The original Gym space.