Skip to main content

Reinforcement Learning toolkit for Assetto Corsa and Car Racing environments

Project description

Assetto Corsa RL

A comprehensive reinforcement learning toolkit for training agents in Assetto Corsa and Car Racing environments using Soft Actor-Critic (SAC) with optional VAE-based vision encoding.

Features

  • ๐ŸŽ๏ธ Assetto Corsa Integration: Full telemetry and control integration with Assetto Corsa
  • ๐ŸŽฎ Car Racing Support: OpenAI Gym Car Racing environment compatibility
  • ๐Ÿง  SAC Implementation: State-of-the-art Soft Actor-Critic algorithm
  • ๐Ÿ‘๏ธ Vision-Based Learning: VAE encoder for image-based observations
  • ๐Ÿ“Š Behavioral Cloning: Pretrain agents from human demonstrations
  • ๐Ÿ› ๏ธ Complete CLI: Unified command-line interface for all operations
  • ๐Ÿ“ˆ WandB Integration: Experiment tracking and visualization

Installation

From PyPI (Recommended)

pip install assetto-corsa-rl

From Source

git clone https://github.com/yourusername/assetto-corsa-rl.git
cd assetto-corsa-rl
pip install -e .

Development Installation

pip install -e ".[dev]"

Quick Start

Assetto Corsa

1. Record Racing Line

acrl ac record-line --output racing_lines.json --laps 2

2. Train Agent

acrl ac train

3. Test Agent

acrl ac load --ckpt models/checkpoint.pt --episodes 5

Car Racing (Gym)

Train Agent

acrl gym train

Test Agent

acrl gym load --model pretrained.pt --episodes 5 --render

CLI Reference

Global Commands

acrl --version          # Show version
acrl --help             # Show help

Assetto Corsa Commands

Training

# Train SAC agent
acrl ac train

# Pretrain with behavioral cloning
acrl ac pretrain --data-dir datasets/demonstrations --epochs 50

# Train VAE encoder
acrl ac train-vae --input-dir datasets/ac_images --epochs 100

Testing

# Load and test trained agent
acrl ac load --ckpt models/checkpoint.pt --episodes 5 --deterministic

# Visualize VAE reconstructions
acrl ac load-vae --ckpt vae.ckpt --env ac

Data Collection

# Record racing line
acrl ac record-line --output racing_lines.json --laps 2 --track monza

# Record demonstrations
acrl ac record-demo --output-dir datasets/demonstrations --duration 300

# Save image dataset
acrl ac save-images --output-dir datasets/ac_images --frame-stack 4

Visualization

# Visualize racing line
acrl ac vis-line --input racing_lines.json --lap 0

# Visualize image dataset
acrl ac vis-images --input-dir datasets/ac_images

Car Racing Commands

# Train agent
acrl gym train

# Test agent
acrl gym load --model checkpoint.pt --episodes 5 --render

# Train VAE
acrl gym train-vae --epochs 10 --batch-size 128

# Visualize VAE
acrl gym load-vae --model vae.ckpt --frames 4

Project Structure

assetto-corsa-rl/
โ”œโ”€โ”€ src/
โ”‚   โ””โ”€โ”€ assetto_corsa_rl/
โ”‚       โ”œโ”€โ”€ ac_env.py           # Assetto Corsa environment
โ”‚       โ”œโ”€โ”€ cli.py              # Command-line interface
โ”‚       โ”œโ”€โ”€ model/
โ”‚       โ”‚   โ”œโ”€โ”€ sac.py          # SAC implementation
โ”‚       โ”‚   โ””โ”€โ”€ vae.py          # VAE encoder
โ”‚       โ””โ”€โ”€ train/
โ”‚           โ””โ”€โ”€ train_core.py   # Training loop
โ”œโ”€โ”€ scripts/
โ”‚   โ”œโ”€โ”€ ac/                     # Assetto Corsa scripts
โ”‚   โ””โ”€โ”€ car-racing/             # Car Racing scripts
โ”œโ”€โ”€ configs/                    # Configuration files
โ”œโ”€โ”€ tests/                      # Unit tests
โ””โ”€โ”€ pyproject.toml             # Package configuration

Configuration

The toolkit uses YAML configuration files in the configs/ directory:

  • configs/ac/env_config.yaml - Environment settings
  • configs/ac/model_config.yaml - Model architecture
  • configs/ac/train_config.yaml - Training hyperparameters

Requirements

  • Python >= 3.9
  • PyTorch >= 2.0.0
  • TorchRL >= 0.2.0
  • Gymnasium >= 0.29.0
  • OpenCV >= 4.8.0
  • Click >= 8.1.0

See requirements.txt for full list.

Development

Running Tests

pytest tests/

Code Formatting

black src/ tests/
isort src/ tests/

Type Checking

mypy src/

Contributing

Contributions are welcome! Please:

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests
  5. Submit a pull request

License

MIT License - see LICENSE file for details

Citation

If you use this toolkit in your research, please cite:

@software{assetto_corsa_rl,
  title = {Assetto Corsa RL: Reinforcement Learning Toolkit},
  author = {Contributors},
  year = {2026},
  url = {https://github.com/yourusername/assetto-corsa-rl}
}

Acknowledgments

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

assetto_corsa_rl-0.1.0.tar.gz (85.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

assetto_corsa_rl-0.1.0-py3-none-any.whl (41.7 kB view details)

Uploaded Python 3

File details

Details for the file assetto_corsa_rl-0.1.0.tar.gz.

File metadata

  • Download URL: assetto_corsa_rl-0.1.0.tar.gz
  • Upload date:
  • Size: 85.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.14

File hashes

Hashes for assetto_corsa_rl-0.1.0.tar.gz
Algorithm Hash digest
SHA256 dde33526d8fc72dfb0b732d4b1832af25cee94186665dc60459c6ad8c1894fc3
MD5 9e500cc88b00eff503942a1e9cce6528
BLAKE2b-256 8bdd727860327be2e1eb035f26967220c709c1d2bf90ced4fc860cc18d70ec20

See more details on using hashes here.

File details

Details for the file assetto_corsa_rl-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for assetto_corsa_rl-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8413f62292425487b742a4b29328120d129f2898e6df11396f1f54eae32cd050
MD5 3a168dad99f50f1bfdad9ba7e8854328
BLAKE2b-256 8f468b54a257f7c25d4d13cde9ad9ab7759b0cbb6737343126b0f9a6fb7bc1df

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page