burtenshaw's picture
burtenshaw HF Staff
Upload folder using huggingface_hub
7d5289a verified
metadata
title: Gym Environment Server
emoji: ๐ŸŽฎ
colorFrom: '#0E84B5'
colorTo: '#34D399'
sdk: docker
pinned: false
app_port: 8000
base_path: /web
tags:
  - openenv

Gym Environment

Integration of OpenAI Gym/Gymnasium environments with the OpenEnv framework. Gymnasium provides a wide variety of environments for reinforcement learning research and development.

Supported Environments

Gymnasium includes numerous environments across different categories:

Classic Control

  • CartPole - Balance a pole on a moving cart
  • Pendulum - Swing up and balance an inverted pendulum
  • Acrobot - Swing up a two-link robotic arm
  • MountainCar - Drive up a mountain with limited power

Box2D

  • LunarLander - Land a spacecraft safely
  • BipedalWalker - Train a 2D biped to walk
  • CarRacing - Race a car around a track

And many more! For a complete list, see Gymnasium documentation.

Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ RL Training Code (Client)          โ”‚
โ”‚   GymEnv.step(action)              โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
               โ”‚ HTTP
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ FastAPI Server (Docker)            โ”‚
โ”‚   GymEnvironment                   โ”‚
โ”‚     โ”œโ”€ Wraps Gymnasium Env         โ”‚
โ”‚     โ”œโ”€ Handles observations        โ”‚
โ”‚     โ””โ”€ Action execution            โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Installation & Usage

Option 1: Local Development (without Docker)

Requirements:

  • Python 3.11+
  • gymnasium installed: pip install gymnasium
# Connect to local server
from envs.gym_env import GymEnvironment, GymAction

# Start local server manually
# python -m envs.gym_env.server.app

env = GymEnvironment(base_url="http://0.0.0.0:8000")

# Reset environment
result = env.reset()
print(f"Observation : {result.observation.state}")
print(f"Action space: {result.observation.legal_actions}")

# Take actions
for _ in range(100):
    action = 1  # Example action
    result = env.step(GymAction(action=[action]))
    print(f"Reward: {result.reward}, Done: {result.done}")
    if result.done:
        break

# Cleanup
env.close()

Option 2: Docker (Recommended)

Build Gym image:

cd OpenEnv

# Build the image
docker build \
  -f src/envs/gym_env/server/Dockerfile \
  -t gym-env:latest \
  .