Operant
High-performance SIMD-optimized Gymnasium-compatible reinforcement learning environments in Rust with Python bindings.
~600x faster than Gymnasium for vectorized environments.
What is This?
Operant provides native Rust implementations of Gymnasium environments with:
- SIMD vectorization: Process 8 environments simultaneously per instruction (AVX2)
- Struct-of-Arrays layout: Cache-friendly memory access patterns
- Zero-copy numpy: Direct array access without Python overhead
- Gymnasium compatibility: Drop-in replacement for standard Gym environments
Unlike PufferLib which wraps existing Gymnasium environments for vectorization, Operant implements environments natively in Rust for maximum performance.
Supported Environments
| Environment | State Dim | Action Space | Physics | Reward |
|---|---|---|---|---|
| CartPole | 4 | Discrete(2) | Inverted pendulum balance | +1 per step alive |
| MountainCar | 2 | Discrete(3) | Sparse reward climbing | -1 per step |
| Pendulum | 3 | Continuous(1) | Swing-up control | Cost minimization |
All environments provide Gymnasium-compatible observation_space and action_space properties for easy integration with RL frameworks.
Performance
CartPole Benchmark (4096 envs)
============================================================
Operant... 97.54M steps/sec
Gymnasium... 0.16M steps/sec
Speedup: ~600x faster than Gymnasium
Requirements
- Python 3.10+
Installation
Python (PyPI)
Rust (crates.io)
From Source (Development)
Requires Rust nightly and Poetry:
# 1. Install Rust
|
# 2. Install Poetry
|
# 3. Setup project
Usage
Python
CartPole (Discrete Actions)
# Create 4096 parallel environments
= 4096
=
, = # Shape: (4096, 4)
=
, , , , =
Multi-threaded Execution
For heavier environments or large batch sizes, enable parallel execution:
# Use 4 worker threads for parallel step execution
=
MountainCar (Discrete Actions)
= 4096
=
, = # Shape: (4096, 2)
=
, , , , =
Pendulum (Continuous Actions)
= 4096
=
, = # Shape: (4096, 3) - [cos(θ), sin(θ), θ_dot]
=
, , , , =
Rust
use ;
Logging and Metrics
# Context manager automatically handles cleanup
# ... training loop ...
Migration from v0.1.x
Old imports (deprecated):
New imports (recommended):
The old import style will continue to work until v0.4.0, but will emit deprecation warnings.
Benchmarks
Quick Benchmark
Compare Operant at 4096 environments:
Full Benchmark
Test across multiple environment counts (1, 16, 256, 1024, 4096):
Architecture
Operant uses a Struct-of-Arrays (SoA) memory layout with SIMD vectorization:
- f32x8 SIMD: Processes 8 environments simultaneously per instruction
- SoA Layout: Cache-friendly memory access patterns
- Zero-copy: Direct numpy array access without Python overhead
- Rust + PyO3: Native performance with Python ergonomics
Development
# Run tests
# Build in debug mode (faster compilation)
# Build in release mode (faster runtime)
License
MIT