gxm.Environment#
- class Environment(*args, **kwargs)#
Bases:
Dynamics[TEnvironmentState,Timestep],Protocol[TEnvironmentState]Base class for RL environments in
gxm.Extends
Dynamicswith episode structure: each step returns aTimestepthat includes reward, termination, and truncation signals. Environments should inherit from this class and implementinit,step, andreset.- __init__(*args, **kwargs)#
Methods
__init__(*args, **kwargs)get_wrapper(wrapper_type)Retrieve the first wrapper of a specific type from the dynamics.
has_wrapper(wrapper_type)Check if the dynamics or any of its wrappers is of a specific type.
init(key)Initialize the environment and return the initial state.
reset(key, state)Reset the environment to its initial state.
step(key, state, action)Perform a step in the environment given an action.
Attributes
unwrappedRetrieve the base dynamics by unwrapping all wrappers.
idThe unique identifier of the dynamics.
action_spaceThe action space of the dynamics.
observation_spaceThe observation space of the dynamics.
- 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=DynamicsState),Timestep]- Returns:
A tuple containing the initial environment state and the initial timestep.
- abstract reset(key, state)#
Reset the environment to its initial state.
- Parameters:
key (
Array) – A JAX random key for any stochasticity in the environment.state (
TypeVar(TEnvironmentState, bound=DynamicsState)) – The current state of the environment.
- Return type:
tuple[TypeVar(TEnvironmentState, bound=DynamicsState),Timestep]- Returns:
A tuple containing the reset environment state and the initial timestep.
- abstract step(key, state, action)#
Perform a step in the environment given an action.
- Parameters:
key (
Array) – A JAX random key for any stochasticity in the environment.state (
TypeVar(TEnvironmentState, bound=DynamicsState)) – The current state of the environment.action (
Any) – The action to take in the environment.
- Return type:
tuple[TypeVar(TEnvironmentState, bound=DynamicsState),Timestep]- Returns:
A tuple containing the new environment state and the resulting timestep.