An evolutionary reinforcement learning framework
Project description
EvoRL
An evolutionary reinforcement learning framework that combines evolutionary algorithms with deep RL.
Features
- 🧬 Evolutionary optimization of RL agents
- 🤖 Multiple agent types (DQN, PPO)
- 🔄 Various evolution strategies (CEM, PGPE, NES)
- 📊 Environment normalization and preprocessing
- 🚀 Easy to extend and customize
Installation
pip install evorl
For development installation with additional tools:
pip install "evorl[dev]"
Quick Start
Basic Usage
from evorl import DQNAgent, NormalizedEnv
import gymnasium as gym
# Create environment
env = NormalizedEnv(gym.make("CartPole-v1"))
# Create and train a single agent
agent = DQNAgent(
state_dim=env.observation_space.shape[0],
action_dim=env.action_space.n
)
# Training loop
episodes = 100
for episode in range(episodes):
obs, _ = env.reset()
done = False
total_reward = 0
while not done:
action = agent.select_action(obs)
next_obs, reward, terminated, truncated, _ = env.step(action)
done = terminated or truncated
agent.update((obs, action, reward, next_obs, done))
total_reward += reward
obs = next_obs
print(f"Episode {episode}: Reward = {total_reward}")
Evolutionary Training
from evorl import Population, CEM
# Create population of agents
population = Population(
agent_class=DQNAgent,
state_dim=env.observation_space.shape[0],
action_dim=env.action_space.n,
population_size=10
)
# Create evolution strategy
strategy = CEM(elite_frac=0.2)
# Evolution loop
generations = 20
for generation in range(generations):
# Evaluate population
metrics = population.evaluate(env, n_episodes=3)
print(f"Generation {generation}: Mean Fitness = {metrics['mean_fitness']:.2f}")
# Create next generation
updates = strategy.compute_updates(population.population, population.fitness_scores)
population.apply_updates(updates)
Documentation
For detailed documentation, visit evorl.ai
Available Components
Agents
DQNAgent: Deep Q-Network implementationPPOAgent: Proximal Policy Optimization implementation
Evolution Strategies
CEM: Cross-Entropy MethodPGPE: Policy Gradients with Parameter ExplorationNES: Natural Evolution Strategies
Environment Wrappers
NormalizedEnv: Observation and reward normalization
Development
# Clone the repository
git clone https://github.com/zhangalex1/evorl.git
cd evorl
# Install in development mode
pip install -e ".[dev]"
# Run tests
pytest tests/
# Run with coverage
pytest tests/ --cov=evorl
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
MIT License - see LICENSE for details
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 evorl-2.0.0.tar.gz.
File metadata
- Download URL: evorl-2.0.0.tar.gz
- Upload date:
- Size: 13.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.10.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
98a19deccde04b6bedc9f55c8fe772c75a6c4aee80e892e4f91f0ab3c34ee567
|
|
| MD5 |
a0dcc328299894baec776a8fcc1fc7e9
|
|
| BLAKE2b-256 |
0d48c9e7ff388f6f98bf3fedbfaa63d8e6b80cfdf7fefdb64466ca87dc25ee00
|
File details
Details for the file evorl-2.0.0-py3-none-any.whl.
File metadata
- Download URL: evorl-2.0.0-py3-none-any.whl
- Upload date:
- Size: 13.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.10.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4a2b95e38db973b2eb04c7d9681523f5879daf1ae41b4a1e929863b4d3305727
|
|
| MD5 |
1a33a7a2c64187894cd4e643a86283ed
|
|
| BLAKE2b-256 |
c0a7b076d76ec79561de424eb9fc7b22abeb2ff03fb02c044d7fd90bb9e1f1aa
|