SimplerEnv Documentation

repository·main·Indexed 22 days ago

https://github.com/simpler-env/simplerenv

SimplerEnv provides simulated manipulation environments using SAPIEN and ManiSkill2/3 to evaluate robot policies with high real-to-sim fidelity. It supports scalable evaluation metrics like MMRV and Pearson correlation, and includes integration for agents such as RT-1 and Octo. The toolkit provides comprehensive guides for adding new robots, object assets, and simulation environments, as well as tools for system identification (SysID), visual matching, and policy debugging.

Tokens
5.8K
Snippets
10
Records
20
Agent score
78%

What's inside SimplerEnv

  1. Key terminology and implementation notes

    main

    When working with SimplerEnv, keep the following technical details in mind:

    • TCP: The term tcp is used throughout the codebase to refer to the tool center point of the robot end-effector.
    • Control Frequency: While the real-world Google Robot controller is non-blocking, SimplerEnv currently implements a 3hz fixed frequency control in simulation (consistent with the RT-1 paper).
  2. Add a new robot to SimplerEnv

    main

    To add a new robot, follow these three main phases: asset integration, agent implementation, and system identification.

    1. Asset Integration

    • Place your robot URDF in ManiSkill2_real2sim/mani_skill2_real2sim/assets/descriptions.
    • Use a test script in tools/robot_object_visualization to verify the robot in the SAPIEN viewer.
    • Visual Matching Tip: To reduce the real-to-sim gap, consider recoloring the robot (e.g., using GIMP) to match real-world observations.
    • Collision Issues: If links behave strangely due to mesh penetration, either remesh in Blender or ignore collisions between specific links (see agents/robots/widowx.py for implementation patterns).

    2. Agent Implementation

    • Create a new robot agent in ManiSkill2_real2sim/mani_skill2_real2sim/agents/robots by inheriting from ManiSkill2_real2sim/mani_skill2_real2sim/agents/base_agent.py.
    • Controllers: Add configurations for the arm and gripper in ManiSkill2_real2sim/mani_skill2_real2sim/agents/controllers/. Use base_controller.py as a reference.
    • Key Methods to Implement/Override:
      • set_action and before_simulation_step in base_agent.py.
      • step_action in ManiSkill2_real2sim/mani_skill2_real2sim/envs/sapien_env.py.
    • Cameras: Add cameras to the robot. Poses are relative to the link specified by actor_uid. SAPIEN uses the ROS convention: x forward, y left, z up. It is highly recommended to calibrate and input intrinsic parameters to minimize the evaluation gap.

    3. System Identification (SysID)

    • Dataset Creation: Modify tools/sysid/prepare_sysid_dataset.py to create a subset of trajectories from existing datasets (e.g., TensorFlow) using the required pickle file format.
    • Running SysID: Use tools/sysid/sysid.py (which uses simulated annealing) to find optimal stiffness and damping parameters.
    • Analysis: Use tools/sysid/analyze_sysid_results.py to examine logs. Iteratively refine parameters by reducing the search range based on the best results from previous rounds.
  3. Add new simulation environments

    main

    To implement a new environment, follow this workflow:

    1. Backgrounds: Add custom scene backgrounds to ManiSkill2_real2sim/data/hab2_bench_assets/stages. Note that backgrounds follow the Habitat convention (y-axis up).
    2. Visual Matching (Greenscreen): If using this setup, add the inpainted background image (with robot/objects removed) to ManiSkill2_real2sim/data/real_inpainting.
    3. Environment Implementation: Add the new environment class to ManiSkill2_real2sim/mani_skill2_real2sim/envs/custom_scenes.
      • Lifecycle: The reset function should assess if reconfiguration is needed (calling reconfigure in sapien_env.py to load assets) and then call initialize_episode.
      • Metadata: Populate or create JSON metadata files for object assets in ManiSkill2_real2sim/data/custom/info_*.json.
    4. Ray Tracing: For Drawer tasks, enable ray-tracing via env = gym.make(**kwargs, shadow_dir='rt') to ensure proper shadow/contrast for depth inference. Note that this is slow on non-RTX GPUs.
    5. Testing: Use the interactive script ManiSkill2_real2sim/mani_skill2_real2sim/examples/demo_manual_control_custom_envs.py to manually control the robot and verify visual alignment.
    6. Policy Integration:
      • Update simpler_env/utils/env/env_builder.py and simpler_env/utils/env/observation_utils.py to support your new environment.
      • If implementing new metrics, modify tools/calc_metrics.py.
  4. Implement and evaluate a new policy

    main

    To evaluate a new policy using existing environments:

    1. Implement Inference: Create a new directory in simpler_env/policies/{your_new_policy}. Follow the structure of simpler_env/policies/rt1 or simpler_env/policies/octo.
    2. Run Evaluation: Use simpler_env/simple_inference_visual_matching_prepackaged_envs.py for simulation evaluation.
    3. Debug (Optional): If policy behavior deviates from real-world performance, use a debugging script similar to simpler_env/utils/debug/{policy_name}_inference_real_video.py. This script feeds real evaluation video frames into the policy to check if action processing/ordering is incorrect.
    4. Customized Evaluation: For advanced setups:
      • Modify simpler_env/main_inference.py to support the new policy.
      • Add custom config scripts in scripts/.
      • (Optional) Update tools/calc_metrics.py to include new metrics.
  5. Set up RT-1 Inference

    main

    To use RT-1, you must download the checkpoints from Google Cloud Storage using gsutil. Create a checkpoints directory in the repository root and move the unzipped files there.

    Available checkpoint versions:

    • RT-1-X
    • RT-1-Converged
    • RT-1-15%
    • RT-1-Begin
    # Example for RT-1-X
    mkdir {this_repo}/checkpoints
    cd {this_repo}
    gsutil -m cp -r gs://gdm-robotics-open-x-embodiment/open_x_embodiment_and_rt_x_oss/rt_1_x_tf_trained_for_002272480_step.zip .
    unzip rt_1_x_tf_trained_for_002272480_step.zip
    mv rt_1_x_tf_trained_for_002272480_step checkpoints
    rm rt_1_x_tf_trained_for_002272480_step.zip
  6. Add new object assets to environments

    main

    To add new objects for simulation, follow these steps:

    1. Storage: Place assets in ManiSkill2_real2sim/data/custom.
    2. Asset Components: Each object requires:
      • Visual Mesh: A textured.dae (with .png textures) or a single textured.glb.
      • Collision Mesh: A collision.obj. This mesh should be watertight and convex.
    3. Processing:
      • If the collision mesh is not convex, process it using tools/coacd_process_mesh.py.
      • Use tools/robot_object_visualization/test_object.py to visualize the object and toggle the collision mesh visibility.
    4. Optimization:
      • For the visual matching setup, use GeTex to bake real-world textures onto simulation assets.
      • Geometry Tips: Collision meshes don't need to match visual geometry perfectly. You can use simple geometric shapes (like frustums) or make the bottom of objects (like cans or bottles) flat to prevent wobbling or rolling when placed on surfaces.

    Blender Exporting Guide

    When exporting from Blender to SAPIEN (which uses x forward, z up):

    • Axis Convention: If your Blender model is y forward, z up, export using the x forward, z up option in Blender. This ensures the x-axis becomes the longest side in SAPIEN.
    • Transformations: Clear parents (alt+p > clear parent), move to origin (object > set origin > geometry to origin), and apply all transforms (object > apply > all transforms) before exporting.
    • Collision Mesh Refinement: In Blender, you can make a collision mesh a convex hull (edit mode > mesh > convex hull) or use the decimate modifier to simplify it and reduce 'slipping' during grasping.
  7. Control the SAPIEN viewer

    main

    When using the SAPIEN viewer for simulation inspection, use the following controls:

    • Focus: Click an object/articulated object link and press f.
    • Camera Movement:
      • Rotate: Right mouse button.
      • Translate: Middle-mouse-button + Shift.
      • Zoom: Scroll middle mouse button (Shift + scroll for slower zoom).
    • Selection: Use the "scene hierarchy" in the bottom left to select actors and articulation links by name.
    • Joint Manipulation: Select an articulated object (e.g., a robot) and use the "articulation" scrollbar in the bottom right to change joint positions/angles.
    • Simulation Control: Press "pause" (top left) to pause the simulation.
    • Object Interaction:
      • Grab: Press g.
      • Move: Press g followed by x, y, or z to move the object along that axis.
  8. Install SimplerEnv

    main

    Follow these steps to set up a minimal installation of SimplerEnv.

    Prerequisites:

    • CUDA version >= 11.8 and < 13 (required for full installation including RT-1/Octo inference).
    • An NVIDIA GPU (RTX preferred; ray tracing may be slow on non-RTX GPUs like 1080Ti or A100). TPU is not supported.

    Setup Steps:

    1. Create and activate an Anaconda environment with Python 3.10 or 3.11:
      conda create -n simpler_env python=3.10
      conda activate simpler_env
    2. Clone the repository with submodules:
      git clone https://github.com/simpler-env/SimplerEnv --recurse-submodules
    3. Install numpy<2.0 to avoid IK errors in pinocchio:
      pip install numpy==1.24.4
    4. Install ManiSkill2 real-to-sim environments:
      cd {this_repo}/ManiSkill2_real2sim
      pip install -e .
    5. Install the SimplerEnv package:
      cd {this_repo}
      pip install -e .
    conda create -n simpler_env python=3.10
    conda activate simpler_env
    git clone https://github.com/simpler-env/SimplerEnv --recurse-submodules
    pip install numpy==1.24.4
    cd ManiSkill2_real2sim
    pip install -e .
    cd ..
    pip install -e .
  9. Set up Octo Inference

    main

    Octo requires jax with CUDA support. Note that Octo checkpoints are managed via HuggingFace and do not need manual downloading.

    Important for CUDA 12 users: If using CUDA 12, you need CUDA version >= 12.2. You may need to perform a runfile install of the corresponding CUDA and set environment variables when running inference scripts.

    # Install JAX with CUDA support
    pip install --upgrade "jax[cuda11_pip]==0.4.20" -f https://storage.googleapis.com/jax-releases/jax_cuda_releases.html
    
    # Clone and install Octo
    cd {this_repo}
    git clone https://github.com/octo-models/octo/
    cd octo
    git checkout 653c54acde686fde619855f2eac0dd6edad7116b
    pip install -e .
    
    # For CUDA 12 users (example environment setup):
    # PATH=/usr/local/cuda-12.3/bin:$PATH LD_LIBRARY_PATH=/usr/local/cuda-12.3/lib64:$LD_LIBRARY_PATH bash scripts/octo_xxx_script.sh
  10. Install SimplerEnv for full evaluation (RT-1 and Octo)

    main

    To perform evaluations using provided agents like RT-1 or Octo, or to add new robots and environments, follow these installation steps. This requires ffmpeg and specific versions of tensorflow and jax.

    System Dependencies

    sudo apt install ffmpeg

    Python Dependencies

    pip install tensorflow==2.15.0
    pip install -r requirements_full_install.txt
    pip install tensorflow[and-cuda]==2.15.1
    # Install simulated annealing utils for system identification
    pip install git+https://github.com/nathanrooy/simulated-annealing
    sudo apt install ffmpeg
    
    pip install tensorflow==2.15.0
    pip install -r requirements_full_install.txt
    pip install tensorflow[and-cuda]==2.15.1
    
    pip install git+https://github.com/nathanrooy/simulated-annealing
  11. Compare policy evaluation using MMRV and Pearson Correlation

    main

    SimplerEnv provides metrics to compare your offline simulation evaluation approach against real-world performance. The two primary metrics are:

    • Mean Maximum Rank Violation (MMRV)
    • Pearson Correlation Coefficient

    To evaluate your approach your_sim_eval(task, policy), compare its results against the provided REAL_PERF data using the simpler_env.utils.metrics module.

    from simpler_env.utils.metrics import mean_maximum_rank_violation, pearson_correlation, REAL_PERF
    
    sim_eval_perf = [
        your_sim_eval(task="google_robot_move_near", policy=p) 
        for p in ["rt-1-x", "octo", ...]
    ]
    real_eval_perf = [
        REAL_PERF["google_robot_move_near"][p] for p in ["rt-1-x", "octo", ...]
    ]
    
    mmrv = mean_maximum_rank_violation(real_eval_perf, sim_eval_perf)
    pearson = pearson_correlation(real_eval_perf, sim_eval_perf)