Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Principle:Farama Foundation Gymnasium Vector Rendering

From Leeroopedia
Revision as of 17:25, 16 February 2026 by Admin (talk | contribs) (Auto-imported from principles/Farama_Foundation_Gymnasium_Vector_Rendering.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Knowledge Sources
Domains Reinforcement_Learning, Visualization
Last Updated 2026-02-15 03:00 GMT

Overview

Rendering and video recording capabilities for vectorized multi-environment settings enable visual monitoring and evaluation of parallel training runs.

Description

Vector rendering provides visualization and recording capabilities specifically designed for vectorized (multi-environment) reinforcement learning setups. When training with multiple parallel environments, standard single-environment rendering is insufficient because it cannot display the state of multiple environments simultaneously or record video from parallel rollouts. Vector rendering wrappers extend the visualization pipeline to handle batched environment instances, compositing multiple sub-environment renders into a single display or recording individual environment videos.

The vector rendering system includes two main capabilities. Human rendering displays a live, tiled view of all parallel environments in a window, with sub-environments arranged in a grid layout that automatically adapts to the number of instances. This allows researchers to visually monitor the behavior of multiple environments during training, quickly spotting issues like reward hacking, degenerate policies, or environment bugs across instances. Video recording captures frames from the vectorized environment into video files, supporting configurable recording triggers (every N episodes, specific episode indices, etc.) and multiple video codecs.

These rendering capabilities are critical for debugging and evaluating multi-environment training pipelines. Without visual feedback, it is difficult to diagnose subtle issues that may not be apparent from reward curves alone. The vector rendering wrappers integrate with the standard environment lifecycle, automatically handling episode boundaries, frame buffering, and resource cleanup.

Usage

Use vector human rendering when you need to visually monitor multiple parallel environments during training or evaluation. Use vector video recording to capture evaluation rollouts for presentations, papers, or debugging. Configure the screen_size parameter to control the display resolution. The rendering wrappers require the base environment to support rgb_array render mode. Use the video recording wrapper to systematically record episodes at specified intervals for later analysis.

Theoretical Basis

Vector rendering composites multiple sub-environment renders into a single display. Given N parallel environments, each producing a frame FiH×W×3:

Grid layout computation:

ncols=N

nrows=N/ncols

Frame compositing:

def composite_frames(frames, num_rows, num_cols, sub_env_size):
    canvas = np.zeros((num_rows * sub_h, num_cols * sub_w, 3), dtype=np.uint8)
    for i, frame in enumerate(frames):
        row = i // num_cols
        col = i % num_cols
        scaled_frame = resize(frame, sub_env_size)
        canvas[row*sub_h:(row+1)*sub_h, col*sub_w:(col+1)*sub_w] = scaled_frame
    return canvas

Video recording follows a frame accumulation pattern:

class RecordVideo(VectorWrapper):
    def step(self, actions):
        obs, rewards, terms, truncs, infos = self.env.step(actions)
        if self.is_recording:
            frame = self.env.render()
            self.recorded_frames.append(frame)
        if episode_complete and self.is_recording:
            save_video(self.recorded_frames, self.video_folder)
            self.recorded_frames = []
        return obs, rewards, terms, truncs, infos

The human rendering pipeline maintains a Pygame window and clock for frame-rate-limited display:

while running:
    frame = env.render()            # get composite frame from vector env
    surface = pygame.surfarray.make_surface(frame)
    window.blit(surface, (0, 0))
    pygame.display.flip()
    clock.tick(render_fps)

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment