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.

Principle:ARISE Initiative Robosuite Environment Factory

From Leeroopedia

Metadata

Property Value
Sources robosuite
Domains Robotics_Simulation, Software_Architecture
Last Updated 2026-02-15 12:00 GMT

Overview

Design pattern for instantiating simulation environments from a registry using a factory function that resolves environment names to concrete classes.

Description

The Factory Pattern in robosuite allows creation of any registered environment by name string. The EnvMeta metaclass automatically registers every MujocoEnv subclass into REGISTERED_ENVS at class definition time. The make() factory function looks up the class and instantiates it with user-provided kwargs. The environment hierarchy: MujocoEnvRobotEnvManipulationEnv → task-specific environments (Lift, Stack, etc.).

Usage

Use this pattern whenever creating a new simulation environment. This is the standard entry point for all robosuite workflows.

Theoretical Basis

The Environment Factory implements the Factory Method Pattern, a creational design pattern that provides an interface for creating objects without specifying their exact classes. This pattern promotes loose coupling by eliminating the need to bind application-specific classes into the code.

Metaclass Auto-Registration

The EnvMeta metaclass intercepts class creation and automatically registers each MujocoEnv subclass:

class EnvMeta(type):
    def __new__(meta, name, bases, class_dict):
        cls = super().__new__(meta, name, bases, class_dict)
        if name != 'MujocoEnv':
            REGISTERED_ENVS[name] = cls
        return cls

class MujocoEnv(metaclass=EnvMeta):
    pass

When a subclass is defined (e.g., class Lift(ManipulationEnv)), the metaclass automatically adds it to the global registry, making it discoverable by the factory function.

Factory Method Implementation

The factory function resolves environment names to classes and handles instantiation:

def make(env_name, *args, **kwargs):
    # Lookup: String name → Class reference
    if env_name not in REGISTERED_ENVS:
        raise Exception(f"Environment {env_name} not found")

    env_class = REGISTERED_ENVS[env_name]

    # Instantiation: Class reference → Instance
    return env_class(*args, **kwargs)

Initialization Hierarchy

Keyword arguments flow through the class hierarchy during instantiation:

# 1. Task-specific environment (e.g., Lift)
class Lift(ManipulationEnv):
    def __init__(self, robots, ..., **kwargs):
        # Task-specific initialization
        self.reward_scale = kwargs.pop('reward_scale', 1.0)
        super().__init__(robots=robots, **kwargs)

# 2. ManipulationEnv
class ManipulationEnv(RobotEnv):
    def __init__(self, robots, env_configuration="default", **kwargs):
        # Manipulation-specific setup
        self.env_configuration = env_configuration
        super().__init__(robots=robots, **kwargs)

# 3. RobotEnv
class RobotEnv(MujocoEnv):
    def __init__(self, robots, controller_configs=None, **kwargs):
        # Robot and controller setup
        self.robots = self._input2list(robots)
        self.controller_configs = controller_configs
        super().__init__(**kwargs)

# 4. MujocoEnv (base)
class MujocoEnv:
    def __init__(self, has_renderer=False, has_offscreen_renderer=True,
                 render_camera="frontview", control_freq=20,
                 horizon=1000, **kwargs):
        # Core simulation setup
        self.has_renderer = has_renderer
        self.control_freq = control_freq
        self.horizon = horizon
        # Initialize MuJoCo simulation

Each level extracts relevant parameters and passes the remaining kwargs up the chain, ensuring proper initialization order from base to derived classes.

Benefits

  • Decoupling: Client code depends on abstract factory interface, not concrete classes
  • Extensibility: New environments are automatically registered without modifying factory code
  • Discoverability: All available environments can be queried from the registry
  • Consistency: Uniform instantiation interface across all environment types

Related Pages

Page Connections

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