Wrapper
lerax.wrapper.AbstractWrapper
Bases:
Base class for environment wrappers.
Attributes:
| Name | Type | Description |
|---|---|---|
|
|
The name of the environment |
|
|
The wrapped environment |
|
|
The environment without any wrappers |
|
|
The action space of the environment after wrapping |
|
|
The observation space of the environment after wrapping |
initial
abstractmethod
Generate the initial state of the environment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
|
A JAX PRNG key for any stochasticity in the initial state. |
required |
Returns:
| Type | Description |
|---|---|
|
An initial environment state. |
action_mask
abstractmethod
Generate an action mask from the environment state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
|
The current environment state. |
required |
key
|
|
A JAX PRNG key for any stochasticity in the action mask. |
required |
Returns:
| Type | Description |
|---|---|
|
A mask indicating valid and invalid actions for the environment state. |
transition
abstractmethod
Update the environment state given an action.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
|
The current environment state. |
required |
action
|
|
The action to take. |
required |
key
|
|
A JAX PRNG key for any stochasticity in the transition. |
required |
Returns:
| Type | Description |
|---|---|
|
The next environment state. |
observation
abstractmethod
Generate an observation from the environment state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
|
The current environment state. |
required |
key
|
|
A JAX PRNG key for any stochasticity in the observation. |
required |
Returns:
| Type | Description |
|---|---|
|
An observation corresponding to the environment state. |
reward
abstractmethod
reward(
state: StateType,
action: ActType,
next_state: StateType,
*,
key: Key,
) -> Float[Array, ""]
Generate a reward from the environment state transition.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
|
The current environment state. |
required |
action
|
|
The action taken. |
required |
next_state
|
|
The next environment state. |
required |
key
|
|
A JAX PRNG key for any stochasticity in the reward. |
required |
Returns:
| Type | Description |
|---|---|
|
A reward corresponding to the environment state transition. |
terminal
abstractmethod
Determine whether the environment state is terminal.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
|
The current environment state. |
required |
key
|
|
A JAX PRNG key for any stochasticity in the terminal condition. |
required |
Returns:
| Type | Description |
|---|---|
|
A boolean indicating whether the environment state is terminal. |
truncate
abstractmethod
Determine whether the environment state is truncated.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
|
The current environment state. |
required |
Returns:
| Type | Description |
|---|---|
|
A boolean indicating whether the environment state is truncated. |
state_info
abstractmethod
Generate additional info from the environment state.
In many cases, this can simply return an empty dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
|
The current environment state. |
required |
Returns:
| Type | Description |
|---|---|
|
A dictionary of additional info from the environment state. |
transition_info
abstractmethod
Generate additional info from the environment state transition.
In many cases, this can simply return an empty dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
|
The current environment state. |
required |
action
|
|
The action taken. |
required |
next_state
|
|
The next environment state. |
required |
Returns:
| Type | Description |
|---|---|
|
A dictionary of additional info from the environment state transition. |
render_states
render_states(
states: Sequence[StateType],
renderer: AbstractRenderer | Literal["auto"] = "auto",
dt: float = 0.0,
)
Render a sequence of frames from multiple states.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
states
|
|
A sequence of environment states to render. |
required |
renderer
|
|
The renderer to use for rendering. If "auto", uses the default renderer. |
'auto'
|
dt
|
|
The time delay between rendering each frame, in seconds. |
0.0
|
render_stacked
render_stacked(
states: StateType,
renderer: AbstractRenderer | Literal["auto"] = "auto",
dt: float = 0.0,
)
Render multiple frames from stacked states.
Stacked states are typically batched states stored in a pytree structure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
states
|
|
A pytree of stacked environment states to render. |
required |
renderer
|
|
The renderer to use for rendering. If "auto", uses the default renderer. |
'auto'
|
dt
|
|
The time delay between rendering each frame, in seconds. |
0.0
|
reset
Wrap the functional logic into a Gym API reset method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
|
A JAX PRNG key for any stochasticity in the reset. |
required |
Returns:
| Type | Description |
|---|---|
|
A tuple of the initial state, initial observation, and additional info. |
step
step(
state: StateType, action: ActType, *, key: Key
) -> tuple[
StateType,
ObsType,
Float[Array, ""],
Bool[Array, ""],
Bool[Array, ""],
dict,
]
Wrap the functional logic into a Gym API step method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
|
The current environment state. |
required |
action
|
|
The action to take. |
required |
key
|
|
A JAX PRNG key for any stochasticity in the step. |
required |
Returns:
| Type | Description |
|---|---|
|
A tuple of the next state, observation, reward, terminal flag, truncate flag, and additional info. |
default_renderer
Return the default renderer for the wrapped environment
options: members: ["env", "unwrapped", "initial", "action_mask", "transition", "observation", "reward", "terminal", "truncate", "state_info", "transition_info", "reset", "step", "default_renderer", "render"]
lerax.wrapper.AbstractWrapperState
options: members: ["env_state", "unwrapped"]