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.

Implementation:Danijar Dreamerv3 Make Env

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

Overview

Concrete tool for constructing wrapped RL environments from a task string using a registry-based factory provided by DreamerV3.

Description

The make_env() and wrap_env() functions in dreamerv3/main.py implement the environment factory. make_env parses the task string to identify the environment suite, looks up the constructor in a registry dict, instantiates it with suite-specific config, and passes the result through wrap_env which applies NormalizeAction, UnifyDtypes, CheckSpaces, and ClipAction wrappers.

The registry supports: dummy, gym, dm, crafter, dmc, atari, atari100k, dmlab, minecraft, loconav, pinpad, langroom, procgen, bsuite, and memmaze.

Usage

Call this when creating environment instances for any run mode. Used by make_agent (to extract obs_space/act_space), train (for training envs), train_eval (for train + eval envs), eval_only (for eval envs), and parallel (for distributed env processes).

Code Reference

Source Location

  • Repository: dreamerv3
  • File: dreamerv3/main.py
  • Lines: L212-258

Signature

def make_env(config, index, **overrides):
    """
    Construct a wrapped environment from config.

    Args:
        config: elements.Config with task string and env settings.
        index: int, environment replica index (used for seeding).
        **overrides: Additional keyword arguments passed to environment constructor.

    Returns:
        embodied.Env: Wrapped environment with normalized interface.
    """

def wrap_env(env, config):
    """
    Apply standard wrapper chain to an environment.

    Args:
        env: embodied.Env instance to wrap.
        config: elements.Config for wrapper settings.

    Returns:
        embodied.Env: Environment with NormalizeAction, UnifyDtypes,
                       CheckSpaces, ClipAction wrappers applied.
    """

Import

from dreamerv3.main import make_env, wrap_env

I/O Contract

Inputs

Name Type Required Description
config elements.Config Yes Configuration with config.task (e.g., "atari_pong"), config.env.{suite} settings, config.seed
index int Yes Environment replica index, used for deterministic seeding
overrides dict No Per-environment keyword overrides passed to constructor

Outputs

Name Type Description
env embodied.Env Wrapped environment exposing obs_space (dict of Space), act_space (dict of Space), and step(action) -> obs_dict

Usage Examples

Single Environment

from dreamerv3.main import make_env
import elements

# Assuming config is already loaded
env = make_env(config, index=0)
print(env.obs_space)  # {'image': Space(uint8, (64, 64, 3)), 'reward': Space(float32, ()), ...}
print(env.act_space)  # {'action': Space(float32, (6,)), 'reset': Space(bool, ())}

# Step the environment
obs = env.step({'action': np.zeros(6), 'reset': True})
env.close()

Multiple Parallel Environments

from functools import partial as bind

# Create factory functions for N environments
fns = [bind(make_env, config, i) for i in range(args.envs)]
driver = embodied.Driver(fns, parallel=True)

Related Pages

Implements Principle

Page Connections

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