Spaces:
Runtime error
Runtime error
File size: 2,738 Bytes
7d5289a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
---
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](https://gymnasium.farama.org/environments/classic_control/).
## 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`
```python
# 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:**
```bash
cd OpenEnv
# Build the image
docker build \
-f src/envs/gym_env/server/Dockerfile \
-t gym-env:latest \
.
``` |