gxm.Environment#
- class Environment#
Bases:
Generic[TEnvironmentState],ABCBase class for environments in
gxm. Environments should inherit from this class and implement theinit,step,reset, andnum_actionsmethods.- __init__()#
Methods
__init__()get_wrapper(wrapper_type)Retrieve the first wrapper of a specific type from the environment.
has_wrapper(wrapper_type)Check if the environment or any of its wrappers is of a specific type.
init(key)Initialize the environment and return the initial state.
reset(key, env_state)Reset the environment to its initial state.
step(key, env_state, action)Perform a step in the environment given an action.
Attributes
Retrieve the base environment by unwrapping all wrappers.
The unique identifier of the environment.
The action space of the environment.
The observation space of the environment.
- get_wrapper(wrapper_type)#
Retrieve the first wrapper of a specific type from the environment.
- Parameters:
wrapper_type (
type[Environment]) – The type of the wrapper to retrieve.- Return type:
- Returns:
The first wrapper of the specified type.
- Raises:
ValueError – If no wrapper of the specified type is found.
- has_wrapper(wrapper_type)#
Check if the environment or any of its wrappers is of a specific type.
- Parameters:
wrapper_type (
type[Environment]) – The type to check for.- Return type:
bool- Returns:
True if the environment or any of its wrappers is of the specified type, False otherwise.
-
id:
str# The unique identifier of the environment.
- abstract init(key)#
Initialize the environment and return the initial state.
- Parameters:
key (
Array) – A JAX random key for any stochastic initialization.- Return type:
tuple[TypeVar(TEnvironmentState, bound=EnvironmentState),Timestep]- Returns:
A tuple containing the initial environment state and the initial timestep.
- abstract reset(key, env_state)#
Reset the environment to its initial state.
- Parameters:
key (
Array) – A JAX random key for any stochasticity in the environment.env_state (
TypeVar(TEnvironmentState, bound=EnvironmentState)) – The current state of the environment.
- Return type:
tuple[TypeVar(TEnvironmentState, bound=EnvironmentState),Timestep]- Returns:
A tuple containing the reset environment state and the initial timestep.
- abstract step(key, env_state, action)#
Perform a step in the environment given an action.
- Parameters:
key (
Array) – A JAX random key for any stochasticity in the environment.env_state (
TypeVar(TEnvironmentState, bound=EnvironmentState)) – The current state of the environment.action (
Any) – The action to take in the environment.
- Return type:
tuple[TypeVar(TEnvironmentState, bound=EnvironmentState),Timestep]- Returns:
A tuple containing the new environment state and the resulting timestep.
- property unwrapped: Environment#
Retrieve the base environment by unwrapping all wrappers.
- Returns:
The base environment without any wrappers.