CoolFace
Apppublic

Forest-Fire/gridworld-openenv

sourceHugging Facemitupdated 6mo agoView on Hugging Face
0likes
App README

๐Ÿš€ Autonomous Navigation RL Environment (OpenEnv Compatible)

A lightweight, API-driven Reinforcement Learning environment that simulates robot navigation in a 2D GridWorld with obstacles, traps, and dynamic challenges.


๐Ÿง  Overview

This project implements a GridWorld environment where an agent must navigate from a start position to a goal while avoiding hazards and penalties.

Environment Elements

  • โ€”๐ŸŸซ Obstacles โ€” Block movement
  • โ€”โš ๏ธ Traps โ€” Penalize the agent
  • โ€”๐Ÿ‘พ Enemy (Hard Mode) โ€” Introduces dynamic difficulty

The environment is exposed via a FastAPI interface and is fully Dockerized for easy deployment.


๐ŸŽฏ Features

  • โ€”โœ… OpenEnv-compliant API
  • โ€”โœ… Three difficulty levels: easy, medium, hard
  • โ€”โœ… Reward normalization (0.0 โ†’ 1.0)
  • โ€”โœ… Fully Dockerized setup
  • โ€”โœ… Lightweight and CPU-friendly
  • โ€”โœ… Inference script for evaluation
  • โ€”โœ… Stable API with no validation errors

๐ŸŽฎ Action Space

ActionMeaning
0Up
1Down
2Left
3Right

๐Ÿงฎ Reward System

The reward function is designed to guide efficient navigation:

  • โ€”โž– Step penalty (encourages shorter paths)
  • โ€”๐Ÿ“ Distance-based reward shaping
  • โ€”โš ๏ธ Trap penalty
  • โ€”๐Ÿ‘พ Enemy penalty (hard mode)
  • โ€”๐Ÿ Goal reward

๐Ÿ‘‰ Final reward is normalized to `[0, 1]`


๐ŸŒ API Endpoints

๐Ÿ”น Reset Environment


POST /reset?task=easy

Query Params:

  • โ€”task: easy | medium | hard

๐Ÿ”น Take a Step


POST /step

Request Body:

json
{
  "action": 1
}

Response:

json
{
  "state": [x, y],
  "reward": 0.85,
  "done": false
}

๐Ÿ”น Get Current State

GET /state

๐Ÿงช Inference

Run the evaluation script:

bash
python inference.py

Output Format

[START]
[STEP] action=...
[STEP] action=...
[END]

๐Ÿณ Docker Setup

Build Image

bash
docker build -t env-test .

Run Container

bash
docker run -p 7860:7860 env-test

The API will be available at:

http://localhost:7860

๐Ÿ“ Project Structure

app/
  โ”œโ”€โ”€ api.py        # FastAPI routes
  โ”œโ”€โ”€ env.py        # Core environment logic
  โ”œโ”€โ”€ models.py     # Data models (request/response)
  โ”œโ”€โ”€ tasks.py      # Task configurations
  โ”œโ”€โ”€ graders.py    # Evaluation logic

inference.py        # Agent interaction script
Dockerfile          # Container configuration
requirements.txt    # Dependencies
openenv.yaml        # OpenEnv specification
LICENSE

๐Ÿ“Š Tasks

DifficultyDescription
๐ŸŸข EasyFewer obstacles
๐ŸŸก MediumMore traps
๐Ÿ”ด HardEnemy + dense hazards

โš™๏ธ State Representation

  • โ€”Format: [x, y]
  • โ€”Represents agent position in the grid
  • โ€”Fully compliant with OpenEnv expectations

โœ… Submission Ready

  • โ€”โœ” Correct state format
  • โ€”โœ” Normalized rewards
  • โ€”โœ” Stable API responses
  • โ€”โœ” No validation errors

๐ŸŽ‰ This environment is fully evaluator-ready.


๐Ÿ“œ License

This project is released under the MIT License.

Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference