Skip to main content

A gym environment for LuckyWorld

Project description

gym-luckyworld

A gym environment for the Lucky World simulator

ACT policy on ALOHA env

Installation

Create a virtual environment with Python 3.10 and activate it, e.g. with miniconda:

conda create -y -n luckyworld python=3.9 && conda activate luckyworld

Install gym-luckyworld:

pip install gym-luckyworld

Quickstart

# example.py
import imageio
import gymnasium as gym
import numpy as np
import gym_luckyworld

env = gym.make("gym_luckyworld/LuckyWorld-PickandPlace-v0-v0")
observation, info = env.reset()
frames = []

for _ in range(1000):
    action = env.action_space.sample()
    observation, reward, terminated, truncated, info = env.step(action)
    image = env.render()
    frames.append(image)

    if terminated or truncated:
        observation, info = env.reset()

env.close()
imageio.mimsave("example.mp4", np.stack(frames), fps=25)

Description

LuckyWorld environment.

Two tasks are available:

  • TransferCubeTask: The right arm needs to first pick up the red cube lying on the table, then place it inside the gripper of the other arm.
  • InsertionTask: The left and right arms need to pick up the socket and peg respectively, and then insert in mid-air so the peg touches the “pins” inside the socket.

Action Space

The action space consists of continuous values for each arm and gripper, resulting in a 14-dimensional vector:

  • Six values for each arm's joint positions (absolute values).
  • One value for each gripper's position, normalized between 0 (closed) and 1 (open).

Observation Space

Observations are provided as a dictionary with the following keys:

  • qpos and qvel: Position and velocity data for the arms and grippers.
  • images: Camera feeds from different angles.
  • env_state: Additional environment state information, such as positions of the peg and sockets.

Rewards

  • TransferCubeTask:
    • 1 point for holding the box with the right gripper.
    • 2 points if the box is lifted with the right gripper.
    • 3 points for transferring the box to the left gripper.
    • 4 points for a successful transfer without touching the table.
  • InsertionTask:
    • 1 point for touching both the peg and a socket with the grippers.
    • 2 points for grasping both without dropping them.
    • 3 points if the peg is aligned with and touching the socket.
    • 4 points for successful insertion of the peg into the socket.

Success Criteria

Achieving the maximum reward of 4 points.

Starting State

The arms and the items (block, peg, socket) start at a random position and angle.

Arguments

>>> import gymnasium as gym
>>> import gym_luckyworld
>>> env = gym.make("gym_luckyworld/LuckyWorld-PickandPlace-v0-v0", obs_type="pixels", render_mode="rgb_array")
>>> env
<TimeLimit<OrderEnforcing<PassiveEnvChecker<LuckyWorldEnv<gym_luckyworld/LuckyWorld-PickandPlace-v0>>>>>
  • obs_type: (str) The observation type. Can be either pixels or pixels_agent_pos. Default is pixels.
  • render_mode: (str) The rendering mode. Only rgb_array is supported for now.
  • observation_width: (int) The width of the observed image. Default is 640.
  • observation_height: (int) The height of the observed image. Default is 480.
  • visualization_width: (int) The width of the visualized image. Default is 640.
  • visualization_height: (int) The height of the visualized image. Default is 480.

🔧 GPU Rendering (EGL)

Rendering on the GPU can be significantly faster than CPU. However, MuJoCo may silently fall back to CPU rendering if EGL is not properly configured. To force GPU rendering and avoid fallback issues, you can use the following snippet:

import distutils.util
import os
import subprocess

if subprocess.run('nvidia-smi').returncode:
  raise RuntimeError(
      'Cannot communicate with GPU. '
      'Make sure you are using a GPU runtime. '
      'Go to the Runtime menu and select Choose runtime type.'
  )

# Add an ICD config so that glvnd can pick up the Nvidia EGL driver.
# This is usually installed as part of an Nvidia driver package, but the
# kernel doesn't install its driver via APT, and as a result the ICD is missing.
# (https://github.com/NVIDIA/libglvnd/blob/master/src/EGL/icd_enumeration.md)
NVIDIA_ICD_CONFIG_PATH = '/usr/share/glvnd/egl_vendor.d/10_nvidia.json'
if not os.path.exists(NVIDIA_ICD_CONFIG_PATH):
  with open(NVIDIA_ICD_CONFIG_PATH, 'w') as f:
    f.write("""{
    "file_format_version" : "1.0.0",
    "ICD" : {
        "library_path" : "libEGL_nvidia.so.0"
    }
}
""")

# Check if installation was successful.
try:
  print('Checking that the installation succeeded:')
  import mujoco
  from mujoco import rollout
  mujoco.MjModel.from_xml_string('<mujoco/>')
except Exception as e:
  raise e from RuntimeError(
      'Something went wrong during installation. Check the shell output above '
      'for more information.\n'
      'If using a hosted Colab runtime, make sure you enable GPU acceleration '
      'by going to the Runtime menu and selecting "Choose runtime type".')

print('Installation successful.')

# Tell XLA to use Triton GEMM, this improves steps/sec by ~30% on some GPUs
xla_flags = os.environ.get('XLA_FLAGS', '')
xla_flags += ' --xla_gpu_triton_gemm_any=True'
os.environ['XLA_FLAGS'] = xla_flags

Contribute

Instead of using pip directly, we use poetry for development purposes to easily track our dependencies. If you don't have it already, follow the instructions to install it.

Install the project with dev dependencies:

poetry install --all-extras

Follow our style

# install pre-commit hooks
pre-commit install

# apply style and linter checks on staged files
pre-commit

Acknowledgment

gym-luckyworld is adapted from gym-aloha

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gym_luckyworld-0.0.1.tar.gz (8.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gym_luckyworld-0.0.1-py3-none-any.whl (9.6 kB view details)

Uploaded Python 3

File details

Details for the file gym_luckyworld-0.0.1.tar.gz.

File metadata

  • Download URL: gym_luckyworld-0.0.1.tar.gz
  • Upload date:
  • Size: 8.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.2 CPython/3.9.21 Linux/6.11.0-21-generic

File hashes

Hashes for gym_luckyworld-0.0.1.tar.gz
Algorithm Hash digest
SHA256 0dbd290052c6f20b48b3f40b450a371115ea86362c47b08c1817ed0c861922b1
MD5 bf149c729f8638d9a6d30fa3b206ac8f
BLAKE2b-256 029bf7a9fe27933d65f26b3e0ecfabc7032b30f5cea3a5c0aaa307b0873bf154

See more details on using hashes here.

File details

Details for the file gym_luckyworld-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: gym_luckyworld-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 9.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.2 CPython/3.9.21 Linux/6.11.0-21-generic

File hashes

Hashes for gym_luckyworld-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d447ff6a0353b2aba5c9888596e5070f53d1ffe2a6fada0f69214b6c61efff52
MD5 9b01553575becef2fcd96d4f3dc3e116
BLAKE2b-256 fcb9472c7072de1eba4feeef572dca41bb8eac10f102f888cc947961e65f13b4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page