Implementation:Farama Foundation Gymnasium DictInfoToList
| Knowledge Sources | |
|---|---|
| Domains | Reinforcement_Learning, Wrappers |
| Last Updated | 2026-02-15 03:00 GMT |
Overview
A vector wrapper that converts the info dictionary format used by vectorized environments from a flat dictionary with arrays to a list of per-environment dictionaries.
Description
The DictInfoToList wrapper converts the info output of vector environments from the default dictionary format (where each key maps to an array of values across all environments) to a list of dictionaries (one per environment).
Vector environments use a compact dictionary format with binary mask keys prefixed by underscore (e.g., _k) to indicate which environments have valid data for each key. For example:
- Dict format:
{"k": array([0., 0., 0.5, 0.3]), "_k": array([False, False, True, True])} - List format:
[{}, {}, {"k": 0.5}, {"k": 0.3}]
The conversion handles:
- Simple array values -- Distributes array elements to per-environment dicts based on the binary mask.
- Nested dict values -- Recursively converts nested dictionary structures.
- Missing binary keys -- If no binary mask exists, all environments receive the value.
This wrapper should be the outermost wrapper when used with other wrappers that modify info (like RecordEpisodeStatistics).
Usage
Use this wrapper when your code expects per-environment info dictionaries (list format) rather than the default batched dictionary format used by vectorized environments. Common when porting single-environment code to work with vector environments.
Code Reference
Source Location
- Repository: Farama_Foundation_Gymnasium
- File:
gymnasium/wrappers/vector/dict_info_to_list.py
Signature
class DictInfoToList(VectorWrapper):
def __init__(self, env: VectorEnv): ...
Import
from gymnasium.wrappers.vector import DictInfoToList
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| env | VectorEnv | Yes | The vector environment to wrap |
Outputs
| Name | Type | Description |
|---|---|---|
| observation | ObsType | Unchanged observations from the vector environment |
| rewards | ArrayType | Unchanged rewards from the vector environment |
| terminations | ArrayType | Unchanged termination flags |
| truncations | ArrayType | Unchanged truncation flags |
| info | list[dict[str, Any]] | Info converted to a list of per-environment dictionaries |
Usage Examples
import numpy as np
import gymnasium as gym
from gymnasium.wrappers.vector import DictInfoToList
# Default dict info format
envs = gym.make_vec("CartPole-v1", num_envs=3)
obs, info = envs.reset(seed=123)
info # {}
# Converted to list format
envs = gym.make_vec("CartPole-v1", num_envs=3)
envs = DictInfoToList(envs)
obs, info = envs.reset(seed=123)
info # [{}, {}, {}]
# With environments that return richer info
envs = gym.make_vec("HalfCheetah-v5", num_envs=2)
envs = DictInfoToList(envs)
_ = envs.reset(seed=123)
_ = envs.action_space.seed(123)
_, _, _, _, infos = envs.step(envs.action_space.sample())
# infos is a list of dicts, one per environment
# [{'x_position': 0.033, 'x_velocity': -0.063, ...}, {'x_position': 0.102, ...}]