A Python library for competitive reinforcement learning environments
Project description
RL Arena ๐ฎ
A Python library for competitive reinforcement learning environments, similar to kaggle-environments but focused on multi-agent RL research and competitions.
๐ Features
- Easy-to-use API: Familiar Gymnasium-style interface
- Competitive Multi-Agent: Built for head-to-head competition
- Extensible: Simple framework for adding new environments
- Well-tested: Comprehensive test suite with >80% coverage
- Type-safe: Full type hints for better development experience
- Reproducible: Deterministic environments with seed support
- Visualization System: Real-time rendering with Matplotlib
- Replay Recording: Save and replay matches in JSON format
- HTML5 Replays: Interactive browser-based match playback
๐ฆ Installation
From PyPI (recommended)
pip install rl-arena
From Source
git clone https://github.com/rl-arena/rl-arena-env.git
cd rl-arena-env
pip install -e .
For Development
git clone https://github.com/rl-arena/rl-arena-env.git
cd rl-arena-env
pip install -e ".[dev]"
๐ Quick Start (30 seconds!)
RL-Arena makes it easy to: Create environments โ Train agents โ Test โ Submit
import rl_arena
# 1๏ธโฃ Create environment
env = rl_arena.make("pong")
# 2๏ธโฃ Train agent (DQN)
model = rl_arena.train_dqn("pong", total_timesteps=10000)
# 3๏ธโฃ Test agent
agent = rl_arena.create_agent(model)
results = rl_arena.evaluate(agent, "pong", n_episodes=10)
print(f"Average reward: {results['mean_reward']:.2f}")
# 4๏ธโฃ Create submission file
rl_arena.create_submission(
agent,
"my_submission.py",
agent_name="MyAgent",
author="your_name"
)
That's it! Submit my_submission.py to rl-arena-backend.
๐ Basic Usage
Environment Creation
import rl_arena
# Create environment
env = rl_arena.make("pong")
# Use built-in agents
agent1 = rl_arena.RandomAgent()
agent2 = rl_arena.RuleBasedAgent()
# Run a game
observations, info = env.reset(seed=42)
done = False
while not done:
# Get actions from agents
actions = [
agent1.act(observations[0]),
agent2.act(observations[1])
]
# Step environment
observations, rewards, terminated, truncated, info = env.step(actions)
done = terminated or truncated
# Render
env.render()
print(f"Final scores: {info['scores']}")
env.close()
๐ฏ Available Environments
| Environment | Players | Description | Complexity |
|---|---|---|---|
| pong | 2 | Classic Pong game | โญ Easy |
More environments coming soon! Contributions welcome!
๐ฎ Environment Details
Pong
Classic 2-player Pong game with customizable physics.
env = rl_arena.make("pong", configuration={
"winning_score": 11, # First to 11 wins
"max_steps": 1000, # Episode length limit
"ball_speed": 0.02, # Ball movement speed
"paddle_height": 0.2, # Paddle size
})
State Space: Ball position & velocity, paddle positions, scores
Action Space: Discrete(3) - UP, STAY, DOWN
Rewards: +1 for scoring, -1 for conceding
See Pong documentation for more details.
๐ Documentation
- Complete Library API Guide: Full API reference with examples
- Environment Creation Tutorial: Create custom environments
- Interactive Mode Guide: Play against AI interactively
๐จ Development
Running Tests
# Run all tests
pytest
# Run with coverage
pytest --cov=rl_arena tests/
# Run specific test file
pytest tests/test_core.py -v
Code Quality
# Format code
black rl_arena/ tests/ examples/
# Type checking
mypy rl_arena/
# Linting
flake8 rl_arena/ tests/ examples/
๐ค Contributing
We welcome contributions! Here's how you can help:
- Add New Environments: See Environment Creation Tutorial
- Fix Bugs: Check open issues
- Improve Documentation: Help make RL Arena more accessible
- Add Examples: Share your agent implementations
Quick Contribution Workflow
# Fork and clone
git clone https://github.com/YOUR-USERNAME/rl-arena-env.git
cd rl-arena-env
# Create branch
git checkout -b feature/my-new-environment
# Make changes, add tests, update docs
# Run tests and linting
pytest
black rl_arena/ tests/
flake8 rl_arena/
# Commit and push
git commit -m "feat: Add new environment"
git push origin feature/my-new-environment
# Open Pull Request on GitHub
๐ Examples
Train and Evaluate Agent
import rl_arena
# Train DQN agent
model = rl_arena.train_dqn("pong", total_timesteps=50000)
# Evaluate performance
agent = rl_arena.create_agent(model)
results = rl_arena.evaluate(agent, "pong", n_episodes=20)
print(f"Win rate: {results['mean_reward']:.2%}")
Interactive Play (Human vs AI)
# Requires pygame: pip install pygame
player = rl_arena.play("pong", fps=60)
player.play(
player1_agent=None, # Human player
player2_agent=agent, # Your trained AI
)
Record and Replay Matches
from rl_arena.utils.replay import save_replay, replay_to_html
# Record match
recorder = rl_arena.MatchRecorder()
env = rl_arena.make("pong")
env.set_recorder(recorder)
# ... play game ...
# Save replay
recording = recorder.get_recording()
save_replay(recording, "match.json")
# Generate HTML replay
html = replay_to_html(recording, "pong", "replay.html")
Create Submission File
# Create submission for competition
rl_arena.create_submission(
agent=agent,
output_path="submission.py",
agent_name="MyPongMaster",
author="your_name",
description="DQN agent trained for 50K steps"
)
# Validate submission
result = rl_arena.validate("submission.py")
if result['valid']:
print("โ
Ready to submit!")
๐ Use Cases
- Research: Study multi-agent RL algorithms
- Education: Learn RL in competitive settings
- Competitions: Host RL tournaments and competitions
- Benchmarking: Compare agent performance across environments
- Fun: Build and battle AI agents!
๐๏ธ Project Structure
rl-arena-env/
โโโ rl_arena/ # Main package
โ โโโ core/ # Base classes and interfaces
โ โโโ envs/ # Environment implementations
โ โ โโโ pong/ # Pong environment
โ โ โโโ __template__/ # Template for new environments
โ โโโ utils/ # Utilities (replay, logging, etc.)
โโโ tests/ # Test suite
โโโ examples/ # Example scripts
โโโ docs/ # Documentation
โโโ .github/ # CI/CD workflows
๐ Acknowledgments
- Inspired by kaggle-environments
- Built on Gymnasium
- Thanks to all contributors
๐ฌ Contact & Support
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Email: kwaklloyd@gmail.com
๐ License
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
โญ Star History
If you find RL Arena useful, please consider starring the repository!
Made with โค๏ธ by the RL Arena community
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file rl_arena-0.1.1.tar.gz.
File metadata
- Download URL: rl_arena-0.1.1.tar.gz
- Upload date:
- Size: 63.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5a4d9f56965a4a39877f426fd92dcbbd711f644b4bea785f93ba235db6a23f40
|
|
| MD5 |
373bbe5a40956277e97e1b2cc7ac2d9d
|
|
| BLAKE2b-256 |
991e0d8df1dfa03a6d5739c158858f5a851aac6c3051f5285d5a7a7c93c0dd88
|
File details
Details for the file rl_arena-0.1.1-py3-none-any.whl.
File metadata
- Download URL: rl_arena-0.1.1-py3-none-any.whl
- Upload date:
- Size: 53.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4bdbce4ce5257ddfac5404a37f4e272b55b5098078d118b8143a4310a6a5b372
|
|
| MD5 |
f977da8b3fd1fe5f86a8b70f371da2c4
|
|
| BLAKE2b-256 |
41cd8f1aea40369a24aa0b04e40e34fa1430164c84b7ec893ecb9cc57071b7e7
|