Implementation:ARISE Initiative Robosuite Wrapper Base
| Knowledge Sources | |
|---|---|
| Domains | Robotics, Software Architecture, Simulation |
| Last Updated | 2026-02-15 07:00 GMT |
Overview
The Wrapper class is the base class for all environment wrappers in robosuite, providing transparent delegation of environment methods with support for data collection, logging, and observation transformation.
Description
The Wrapper class implements the decorator pattern for robosuite environments, allowing transparent interception and modification of environment interactions. By default, all methods delegate directly to the wrapped environment, making the wrapper invisible to calling code. Subclasses override specific methods to add functionality like data logging, observation normalization, or action transformation.
The class provides default implementations for the core environment interface: step, reset, render, observation_spec, action_spec, and action_dim. The unwrapped property recursively retrieves the innermost environment, bypassing all wrapper layers.
A safety mechanism against double-wrapping is provided via _warn_double_wrap, which traverses the wrapper chain and raises an exception if the same wrapper class appears more than once. This prevents accidental duplicate application of wrappers.
The __getattr__ fallback method ensures that any method or attribute not explicitly defined on the wrapper is transparently forwarded to the wrapped environment. For callable attributes, it wraps the return value to prevent the wrapped environment from "leaking" out - if a wrapped method returns the environment itself, the wrapper returns self instead, maintaining the wrapper chain.
Usage
Use this class as the base for custom environment wrappers. Subclass it and override the methods you need to modify. Common use cases include data collection wrappers, reward shaping wrappers, observation normalization wrappers, and gym-compatible interface wrappers.
Code Reference
Source Location
- Repository: ARISE_Initiative_Robosuite
- File: robosuite/wrappers/wrapper.py
Signature
class Wrapper:
def __init__(self, env)
@classmethod
def class_name(cls) -> str
def _warn_double_wrap(self) -> None
def step(self, action)
def reset(self)
def render(self, **kwargs)
def observation_spec(self)
@property
def action_spec(self)
@property
def action_dim(self) -> int
@property
def unwrapped(self)
Import
from robosuite.wrappers.wrapper import Wrapper
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| env | MujocoEnv | Yes | The robosuite environment to wrap |
| action | np.ndarray | Yes (step) | Action to take in the environment |
Outputs
| Name | Type | Description |
|---|---|---|
| step() | tuple | (observations, reward, done, info) from the wrapped environment |
| reset() | OrderedDict | Observation dictionary after environment reset |
| observation_spec() | OrderedDict | Observation space specification |
| action_spec | tuple(np.ndarray, np.ndarray) | (low, high) action limits |
| action_dim | int | Dimensionality of the action space |
| unwrapped | MujocoEnv | The innermost unwrapped environment |
| class_name() | str | The wrapper class name |
Usage Examples
import numpy as np
from robosuite.wrappers.wrapper import Wrapper
import robosuite
# Basic wrapping of an environment
env = robosuite.make("Lift", robots="Panda")
wrapped_env = Wrapper(env)
# The wrapper delegates all calls transparently
obs = wrapped_env.reset()
obs, reward, done, info = wrapped_env.step(np.zeros(wrapped_env.action_dim))
# Access the unwrapped environment
original_env = wrapped_env.unwrapped
# Create a custom wrapper subclass
class LoggingWrapper(Wrapper):
def __init__(self, env):
super().__init__(env)
self.step_count = 0
def step(self, action):
self.step_count += 1
obs, reward, done, info = self.env.step(action)
print(f"Step {self.step_count}: reward={reward:.4f}")
return obs, reward, done, info
logged_env = LoggingWrapper(env)