Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Implementation:Farama Foundation Gymnasium Make Vec

From Leeroopedia
Knowledge Sources
Domains Reinforcement_Learning, Parallelism
Last Updated 2026-02-15 03:00 GMT

Overview

Concrete tool for creating batched parallel environments provided by the Gymnasium library.

Description

The gymnasium.make_vec function creates a VectorEnv by instantiating multiple copies of an environment with the specified vectorization mode (sync or async). It supports applying wrappers to each sub-environment and accepts all arguments that gymnasium.make accepts.

Usage

Use gymnasium.make_vec for creating vectorized environments from registered IDs. For custom environment factories, use SyncVectorEnv or AsyncVectorEnv directly.

Code Reference

Source Location

  • Repository: Gymnasium
  • File: gymnasium/envs/registration.py
  • Lines: L832-987

Signature

def make_vec(
    id: str | EnvSpec,
    num_envs: int = 1,
    vectorization_mode: VectorizeMode | str | None = None,
    vector_kwargs: dict[str, Any] | None = None,
    wrappers: Sequence[Callable[[Env], Wrapper]] | None = None,
    **kwargs,
) -> gymnasium.vector.VectorEnv:
    """Create a vector environment according to the given ID.

    Args:
        id: A string for the environment id or an EnvSpec.
        num_envs: Number of parallel environments.
        vectorization_mode: "sync" or "async" (default inferred from spec).
        vector_kwargs: Additional kwargs for the vector env constructor.
        wrappers: Wrapper callables applied to each sub-environment.
        **kwargs: Additional arguments passed to each sub-environment.

    Returns:
        A VectorEnv instance.
    """

Import

import gymnasium as gym

envs = gym.make_vec("CartPole-v1", num_envs=4)

I/O Contract

Inputs

Name Type Required Description
id str or EnvSpec Yes Environment identifier
num_envs int No Number of parallel environments (default 1)
vectorization_mode str or None No "sync" or "async"
wrappers Sequence[Callable] or None No Per-environment wrappers

Outputs

Name Type Description
envs VectorEnv Vectorized environment with batched interface

Usage Examples

A2C Training Setup

import gymnasium as gym

# Create 10 parallel LunarLander environments
envs = gym.make_vec("LunarLander-v3", num_envs=10, vectorization_mode="sync")

# Access batched spaces
print(envs.single_observation_space)  # Box(8,)
print(envs.single_action_space)       # Discrete(4)
print(envs.num_envs)                  # 10

# Batched interaction
obs, infos = envs.reset(seed=42)
print(obs.shape)  # (10, 8)

actions = envs.action_space.sample()  # (10,) array
obs, rewards, terms, truncs, infos = envs.step(actions)

envs.close()

Related Pages

Implements Principle

Requires Environment

Uses Heuristic

Page Connections

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