stormvogel.extensions.gym_grid

Convert gymnasium grid environments to stormvogel models, and render them as gifs.

Attributes

Functions

gymnasium_grid_to_stormvogel(env[, action_label_map])

Convert a FrozenLake, Taxi, or Cliffwalking gymnasium environment to an explicit stormvogel model.

to_coordinate(s, env)

Calculate the state's coordinates.

to_state(x, y, env)

Calculate the state index from coordinates.

get_target_state(env)

Calculate the target state for an environment.

to_gymnasium_scheduler(→ Callable[[int], int])

Convert a stormvogel scheduler to a gymnasium scheduler.

gymnasium_render_model_gif(→ str)

Render a gymnasium model to a gif.

Module Contents

stormvogel.extensions.gym_grid.GRID_ACTION_LABEL_MAP
stormvogel.extensions.gym_grid.gymnasium_grid_to_stormvogel(env, action_label_map: dict[int, str] = GRID_ACTION_LABEL_MAP)

Convert a FrozenLake, Taxi, or Cliffwalking gymnasium environment to an explicit stormvogel model.

Parameters:
  • env – Gymnasium environment.

  • action_label_map – Mapping from action numbers to action labels.

Returns:

Stormvogel model.

stormvogel.extensions.gym_grid.to_coordinate(s, env)

Calculate the state’s coordinates.

Work for FrozenLake, Cliffwalking, and Taxi.

Parameters:
  • s – State index.

  • env – Gymnasium environment.

Returns:

(x, y) coordinate tuple.

stormvogel.extensions.gym_grid.to_state(x, y, env)

Calculate the state index from coordinates.

Work for FrozenLake, CliffWalking, and Taxi.

Parameters:
  • x – X coordinate.

  • y – Y coordinate.

  • env – Gymnasium environment.

Returns:

State index.

stormvogel.extensions.gym_grid.get_target_state(env)

Calculate the target state for an environment.

Work for FrozenLake and Cliffwalking.

Parameters:

env – Gymnasium environment.

Returns:

Target state index.

stormvogel.extensions.gym_grid.to_gymnasium_scheduler(model: stormvogel.model.Model, scheduler: stormvogel.result.Scheduler | Callable[[stormvogel.model.State], stormvogel.model.Action], action_label_map: dict[int, str] = GRID_ACTION_LABEL_MAP) Callable[[int], int]

Convert a stormvogel scheduler to a gymnasium scheduler.

Intended for models converted via gymnasium_grid_to_stormvogel().

Parameters:
Returns:

A callable mapping environment state ids to action numbers.

stormvogel.extensions.gym_grid.gymnasium_render_model_gif(env, gymnasium_scheduler: Callable[[int], int] | None = None, filename: str = 'my_gif', max_length: int = 50, fps: int = 2, loop: int = 0) str

Render a gymnasium model to a gif.

Use gymnasium_scheduler to pick actions; leave as None for random actions.

Parameters:
  • env – Gymnasium environment.

  • gymnasium_scheduler – Function mapping a state number to an action number.

  • filename – Name of the gif file to save.

  • max_length – Maximum number of frames to render.

  • fps – Frames per second for the gif.

  • loop – Number of times to loop the gif. 0 means loop forever.

Returns:

Filesystem path of the saved gif.