Animation
POGEMA can record episodes as SVG, HTML canvas, or MP4 animations and export static TikZ figures. The AnimationWrapper is included by default but inactive — it adds zero overhead until enabled.
In POGEMA 2.0, rendering options are passed directly as keyword arguments. The deprecated AnimationMonitor wrapper and public AnimationConfig API were removed.
Basic Usage
from pogema import pogema_v0, GridConfig
env = pogema_v0(GridConfig(num_agents=4, size=8, seed=42))
env.enable_animation()
obs, info = env.reset()
while True:
obs, reward, terminated, truncated, info = env.step(env.sample_actions())
if all(terminated) or all(truncated):
break
Rendering Options
All rendering options are passed directly to the relevant render or save method:
| Parameter | Type | Default | Description |
|---|---|---|---|
show_agents |
bool |
True |
Render agents on grid |
egocentric_idx |
int \| None |
None |
Follow specific agent |
static_frame_idx |
int \| None |
None |
Render single frame instead of animation |
show_grid_lines |
bool |
True |
Show grid lines |
show_controls |
bool |
True |
Show playback controls (HTML only) |
background_color |
str \| None |
None |
Solid #RRGGBB drawing background |
border |
'none' \| 'thin' \| 'full' |
'thin' |
Amount of observation border to render |
from pogema import pogema_v0, GridConfig
env = pogema_v0(GridConfig(num_agents=4, size=8, seed=42))
env.enable_animation()
obs, info = env.reset()
while True:
obs, reward, terminated, truncated, info = env.step(env.sample_actions())
if all(terminated) or all(truncated):
break
# SVG animation
env.save_animation('render.svg', show_grid_lines=False)
# HTML canvas animation (with playback controls)
env.save_html_animation('render.html', show_controls=True)
# Shared by SVG, HTML, MP4, and TikZ
env.save_animation('dark.svg', background_color='#111827')
Video Export
Video export is available as an optional dependency:
TikZ Export
TikZ export is dependency-free and produces a static source fragment of the latest frame for use with \usepackage{tikz}:
Egocentric View
Follow a specific agent's perspective:
from pogema import pogema_v0, GridConfig
env = pogema_v0(GridConfig(num_agents=4, size=8, seed=42, obs_radius=3))
env.enable_animation()
obs, info = env.reset()
while True:
obs, reward, terminated, truncated, info = env.step(env.sample_actions())
if all(terminated) or all(truncated):
break
Static Frame
Render a single timestep instead of an animation:
from pogema import pogema_v0, GridConfig
env = pogema_v0(GridConfig(num_agents=4, size=8, seed=42))
env.enable_animation()
obs, info = env.reset()
while True:
obs, reward, terminated, truncated, info = env.step(env.sample_actions())
if all(terminated) or all(truncated):
break
A* Baseline
See agents solving the task optimally:
from pogema import pogema_v0, GridConfig, BatchAStarAgent
env = pogema_v0(GridConfig(
num_agents=4, size=8, seed=42,
observation_type='POMAPF',
))
env.enable_animation()
agent = BatchAStarAgent()
obs, info = env.reset()
while True:
obs, reward, terminated, truncated, info = env.step(agent.act(obs))
if all(terminated) or all(truncated):
break
agent.reset_states()