Skip to main content

gym-hil

A collection of gymnasium environments for Human-In-the-Loop (HIL) reinforcement learning, compatible with Hugging Face's LeRobot codebase.

Overview

The gym-hil package provides environments designed for human-in-the-loop reinforcement learning. The list of environments are integrated with external devices like gamepads and keyboards, making it easy to collect demonstrations and perform interventions during learning.

Currently available environments:

  • Franka Panda Robot: A robotic manipulation environment for Franka Panda robot based on MuJoCo

What is Human-In-the-Loop (HIL) RL?

Human-in-the-Loop (HIL) Reinforcement Learning keeps a human inside the control loop while the agent is training. During every rollout, the policy proposes an action, but the human may instantly override it for as many consecutive steps as needed; the robot then executes the human's command instead of the policy's choice. This approach improves sample efficiency and promotes safer exploration, as corrective actions pull the system out of unrecoverable or dangerous states and guide it toward high-value behaviors.

Human-in-the-Loop RL Schema

Demo Video

Watch the gym-hil demo video
Click the image to watch a demo of gym-hil in action!

We use HIL-SERL from LeRobot to train this policy. The policy was trained for 10 minutes with human in the loop. After only 10 minutes of training, the policy successfully performs the task.

Installation

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

conda create -y -n gym_hil python=3.10 && conda activate gym_hil

Install gym-hil from PyPI:

pip install gym-hil

or from source:

git clone https://github.com/HuggingFace/gym-hil.git && cd gym-hil
pip install -e .

Franka Environment Quick Start

import time
import imageio
import gymnasium as gym
import numpy as np

import gym_hil

# Use the Franka environment
env = gym.make("gym_hil/PandaPickCubeBase-v0", render_mode="human", image_obs=True)
action_spec = env.action_space

obs, info = env.reset()
frames = []

for i in range(200):
    obs, rew, done, truncated, info = env.step(env.action_space.sample())
    # info contains the key "is_intervention" (boolean) indicating if a human intervention occurred
    # If info["is_intervention"] is True, then info["teleop_action"] contains the action that was executed
    images = obs["pixels"]
    frames.append(np.concatenate((images["front"], images["wrist"]), axis=0))

    if done:
        obs, info = env.reset()

env.close()
imageio.mimsave("franka_render_test.mp4", frames, fps=20)

Available Environments

Franka Panda Robot Environments

  • PandaPickCubeBase-v0: The core environment with the Franka arm and a cube to pick up.
  • PandaPickCubeGamepad-v0: Includes gamepad control for teleoperation.
  • PandaPickCubeKeyboard-v0: Includes keyboard control for teleoperation.

Teleoperation

For Franka environments, you can use the gamepad or keyboard to control the robot:

python examples/test_teleoperation.py

To run the teleoperation with keyboard you can use the option --use-keyboard.

Human-in-the-Loop Wrappers

The hil_wrappers.py module provides wrappers for human-in-the-loop interaction:

  • EEActionWrapper: Transforms actions to end-effector space for intuitive control
  • InputsControlWrapper: Adds gamepad or keyboard control for teleoperation
  • GripperPenaltyWrapper: Optional wrapper to add penalties for excessive gripper actions

These wrappers make it easy to build environments for human demonstrations and interactive learning.

Controller Configuration

You can customize gamepad button and axis mappings by providing a controller configuration file.

python examples/test_teleoperation.py --controller-config path/to/controller_config.json

If no path is specified, the default configuration file bundled with the package (controller_config.json) will be used.

You can also pass the configuration path when creating an environment in your code:

env = gym.make(
    "gym_hil/PandaPickCubeGamepad-v0",
    controller_config_path="path/to/controller_config.json",
    # other parameters...
)

To add a new controller, run the script, copy the controller name from the console, add it to the JSON config, and rerun the script.

The default controls are:

  • Left analog stick: Move in X-Y plane
  • Right analog stick (vertical): Move in Z axis
  • RB button: Toggle intervention mode
  • LT button: Close gripper
  • RT button: Open gripper
  • Y/Triangle button: End episode with SUCCESS
  • A/Cross button: End episode with FAILURE
  • X/Square button: Rerecord episode

The configuration file is a JSON file with the following structure:

{
  "default": {
    "axes": {
      "left_x": 0,
      "left_y": 1,
      "right_x": 2,
      "right_y": 3
    },
    "buttons": {
      "a": 1,
      "b": 2,
      "x": 0,
      "y": 3,
      "lb": 4,
      "rb": 5,
      "lt": 6,
      "rt": 7
    },
    "axis_inversion": {
      "left_x": false,
      "left_y": true,
      "right_x": false,
      "right_y": true
    }
  },
  "Xbox 360 Controller": {
    ...
  }
}

LeRobot Compatibility

All environments in gym-hil are designed to work seamlessly with Hugging Face's LeRobot codebase for human-in-the-loop reinforcement learning. This makes it easy to:

  • Collect human demonstrations
  • Train agents with human feedback
  • Perform interactive learning with human intervention

Contribute

# install pre-commit hooks
pre-commit install

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

Acknowledgment

The Franka environment in gym-hil is adapted from franka-sim initially built by Kevin Zakka.

Version History

  • v0: Original version

Metadata

Release files for gym-hil 0.1.14

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gym-hil 0.1.14
File Size Uploaded Provenance Actions
gym_hil-0.1.14.tar.gz 5.7 MB Without provenance Details for gym_hil-0.1.14.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for gym-hil 0.1.14
File Interpreter ABI Platform Actions
gym_hil-0.1.14-py3-none-any.whl Python 3 none any Details for gym_hil-0.1.14-py3-none-any.whl

Total release size: 11.4 MB

Release files / gym_hil-0.1.14.tar.gz

Download URL gym_hil-0.1.14.tar.gz
Size 5.7 MB
Tags Source
SHA-256 checksum
How to use checksums
aeee688dcb3ec72e7bcbe604df4a3f990cce49c8a2da469dd67c3a4eeb4c6bbb
BLAKE2b-256 checksum
How to use checksums
0c64b5cfe59d6a69d20497218f01ad2bdaa2a5a72b850bdb1a445d804ecc9948
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.1

Release files / gym_hil-0.1.14-py3-none-any.whl

Download URL gym_hil-0.1.14-py3-none-any.whl
Size 5.8 MB
Tags Python 3
SHA-256 checksum
How to use checksums
9a2799d47a4561e0b0bb8d37fb3d84934657240be328d13991ea06758726533d
BLAKE2b-256 checksum
How to use checksums
7297a7a9c3886306a89046ba5c989bc8b79008e7ec973228bad1fa20d7a94bba
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.1

Security for gym-hil 0.1.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page