Functional wrappers¶
These wrappers keep the functional gymnax API. Import them from gymnax.wrappers.
LogWrapper ¶
Bases: GymnaxWrapper
Track episode returns and lengths and report them through info.
step adds four entries to info:
returned_episode_returns: return of the most recently completed episode.returned_episode_lengths: length of the most recently completed episode.returned_episode: whether this transition completed an episode.returned_episode_valid: whether any episode has completed so far. Until then the two counters above hold the placeholder value 0.
Parameters:
-
env(Environment) –Environment to wrap.
reset ¶
Reset the wrapped environment and all episode statistics.
step ¶
step(key: Array, state: LogEnvState, action: int | float, params: EnvParams | None = None) -> tuple[jax.Array, LogEnvState, jax.Array, bool, bool, dict[Any, Any]]
Step the wrapped environment and update the episode statistics.
Parameters:
-
key(Array) –PRNG key.
-
state(LogEnvState) –Current wrapper state.
-
action(int | float) –Action to take.
-
params(EnvParams | None, default:None) –Environment parameters. Defaults to the environment defaults.
Returns:
-
tuple[Array, LogEnvState, Array, bool, bool, dict[Any, Any]]–A tuple
(obs, state, reward, terminated, truncated, info), whereinfoadditionally holds the episode statistics.
LogEnvState ¶
State of an environment wrapped in LogWrapper.
Attributes:
-
env_state(EnvState) –State of the wrapped environment.
-
episode_returns(Array) –Sum of rewards in the running episode.
-
episode_lengths(Array) –Number of steps in the running episode.
-
returned_episode_returns(Array) –Return of the most recently completed episode.
-
returned_episode_lengths(Array) –Length of the most recently completed episode.
-
returned_episode_valid(Array) –Whether an episode has completed since the wrapper was reset.
FlattenObservationWrapper ¶
Bases: GymnaxWrapper
Flatten observations into one-dimensional arrays.
Applies to the observations returned by reset and step, to
info["final_observation"] and to the bounds of the observation space. Only
Box observation spaces are supported.
Parameters:
-
env(Environment) –Environment to wrap.
observation_space ¶
Observation space of the wrapped environment with a flat shape.
reset ¶
Reset the wrapped environment and flatten the observation.
step ¶
step(key: Array, state: EnvState, action: int | float, params: EnvParams | None = None) -> tuple[jax.Array, environment.EnvState, float, bool, bool, Any]
Step the wrapped environment and flatten both observations.
StickyActionWrapper ¶
Bases: GymnaxWrapper
Repeat the previously executed action with a fixed probability.
At every step the requested action is replaced by the action executed in the
previous step with probability sticky_action_prob. Requires a Discrete
action space.
Parameters:
-
env(Environment) –Environment to wrap.
-
sticky_action_prob(float, default:0.0) –Probability in
[0, 1]of repeating the previous action.
Raises:
-
ValueError–If the probability is not a finite value in
[0, 1]or the action space is notDiscrete.
reset ¶
Reset the wrapped environment and set the previous action to 0.
step ¶
step(key: Array, state: StickyActionState, action: int | Array, params: EnvParams | None = None) -> tuple[jax.Array, StickyActionState, jax.Array, jax.Array, jax.Array, dict[Any, Any]]
Step with the requested action or, when it sticks, the previous one.
StickyActionState ¶
State of an environment wrapped in StickyActionWrapper.
Attributes:
-
env_state(Any) –State of the wrapped environment.
-
last_action(Array) –Action executed in the previous step, 0 after a reset.
Base class¶
GymnaxWrapper ¶
Base class for Gymnax wrappers.
Attributes and methods that a wrapper does not override are forwarded to the wrapped environment.
Parameters:
-
env(Environment) –Environment to wrap.