Functional Env

class gymnasium.functional.FuncEnv(options: dict[str, Any] | None = None)[source]

Base class (template) for functional envs.

This API is meant to be used in a stateless manner, with the environment state being passed around explicitly. That being said, nothing here prevents users from using the environment statefully, it’s just not recommended. A functional env consists of the following functions (in this case, instance methods):

  • initial: returns the initial state of the POMDP

  • observation: returns the observation in a given state

  • transition: returns the next state after taking an action in a given state

  • reward: returns the reward for a given (state, action, next_state) tuple

  • terminal: returns whether a given state is terminal

  • state_info: optional, returns a dict of info about a given state

  • step_info: optional, returns a dict of info about a given (state, action, next_state) tuple

The class-based structure serves the purpose of allowing environment constants to be defined in the class, and then using them by name in the code itself.

For the moment, this is predominantly for internal use. This API is likely to change, but in the future we intend to flesh it out and officially expose it to end users.

Initialize the environment constants.

transform(func: Callable[[Callable], Callable])[source]

Functional transformations.

initial(rng: Any, params: Params | None = None) StateType[source]

Generates the initial state of the environment with a random number generator.

transition(state: StateType, action: ActType, rng: Any, params: Params | None = None) StateType[source]

Updates (transitions) the state with an action and random number generator.

observation(state: StateType, params: Params | None = None) ObsType[source]

Generates an observation for a given state of an environment.

reward(state: StateType, action: ActType, next_state: StateType, params: Params | None = None) RewardType[source]

Computes the reward for a given transition between state, action to next_state.

terminal(state: StateType, params: Params | None = None) TerminalType[source]

Returns if the state is a final terminal state.

state_info(state: StateType, params: Params | None = None) dict[source]

Info dict about a single state.

transition_info(state: StateType, action: ActType, next_state: StateType, params: Params | None = None) dict[source]

Info dict about a full transition.

render_init(**kwargs) RenderStateType[source]

Initialize the render state.

render_image(state: StateType, render_state: RenderStateType, params: Params | None = None) tuple[RenderStateType, np.ndarray][source]

Show the state.

render_close(render_state: RenderStateType)[source]

Close the render state.

Converting Jax-based Functional environments to standard Env

class gymnasium.envs.functional_jax_env.FunctionalJaxEnv(func_env: FuncEnv, metadata: dict[str, Any] | None = None, render_mode: str | None = None, reward_range: tuple[float, float] = (-float('inf'), float('inf')), spec: EnvSpec | None = None)[source]

A conversion layer for jax-based environments.

Initialize the environment from a FuncEnv.

reset(*, seed: int | None = None, options: dict | None = None)[source]

Resets the environment using the seed.

step(action: ActType)[source]

Steps through the environment using the action.

render()[source]

Returns the render state if render_mode is “rgb_array”.