Skip to main content

High-performance SIMD-optimized RL environments in Rust

Project description

Operant

PyPI version Python 3.10+

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

From PyPI (Recommended)

pip install operant

From Source (Development)

Requires Rust nightly and Poetry:

# 1. Install Rust
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

# 2. Install Poetry
curl -sSL https://install.python-poetry.org | python3 -

# 3. Setup project
poetry install
poetry run maturin develop --release

Usage

CartPole (Discrete Actions)

import numpy as np
from operant.envs import CartPoleVecEnv

# Create 4096 parallel environments
num_envs = 4096
env = CartPoleVecEnv(num_envs)
obs = env.reset(seed=42)  # Shape: (4096, 4)

for step in range(10000):
    actions = np.random.randint(0, 2, size=num_envs, dtype=np.int32)
    obs, rewards, terminals, truncations = env.step(actions)

MountainCar (Discrete Actions)

from operant.envs import MountainCarVecEnv

num_envs = 4096
env = MountainCarVecEnv(num_envs)
obs = env.reset(seed=42)  # Shape: (4096, 2)

for step in range(10000):
    actions = np.random.randint(0, 3, size=num_envs, dtype=np.int32)
    obs, rewards, terminals, truncations = env.step(actions)

Pendulum (Continuous Actions)

from operant.envs import PendulumVecEnv

num_envs = 4096
env = PendulumVecEnv(num_envs)
obs = env.reset(seed=42)  # Shape: (4096, 3) - [cos(θ), sin(θ), θ_dot]

for step in range(10000):
    actions = np.random.uniform(-2.0, 2.0, size=num_envs).astype(np.float32)
    obs, rewards, terminals, truncations = env.step(actions)

Logging and Metrics

from operant.utils import Logger

# Context manager automatically handles cleanup
with Logger(csv_path="training.csv") as logger:
    for step in range(1000):
        # ... training loop ...
        logger.log(steps=num_envs, reward=mean_reward, length=mean_length)

Migration from v0.1.x

Old imports (deprecated):

from operant import PyCartPoleVecEnv, Logger

New imports (recommended):

from operant.envs import CartPoleVecEnv
from operant.utils import Logger

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:

poetry run python benches/cartpole_benchmark.py

Full Benchmark

Test across multiple environment counts (1, 16, 256, 1024, 4096):

poetry run python benches/cartpole_benchmark.py --all

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
poetry run pytest

# Build in debug mode (faster compilation)
poetry run maturin develop

# Build in release mode (faster runtime)
poetry run maturin develop --release

License

MIT

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

operant-0.3.1-cp314-cp314-win_amd64.whl (170.3 kB view details)

Uploaded CPython 3.14Windows x86-64

operant-0.3.1-cp314-cp314-macosx_11_0_arm64.whl (275.7 kB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

operant-0.3.1-cp313-cp313-win_amd64.whl (169.8 kB view details)

Uploaded CPython 3.13Windows x86-64

operant-0.3.1-cp313-cp313-macosx_11_0_arm64.whl (275.3 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

operant-0.3.1-cp312-cp312-win_amd64.whl (169.9 kB view details)

Uploaded CPython 3.12Windows x86-64

operant-0.3.1-cp312-cp312-macosx_11_0_arm64.whl (275.4 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

operant-0.3.1-cp311-cp311-win_amd64.whl (171.7 kB view details)

Uploaded CPython 3.11Windows x86-64

operant-0.3.1-cp311-cp311-macosx_11_0_arm64.whl (277.2 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

operant-0.3.1-cp310-cp310-win_amd64.whl (171.4 kB view details)

Uploaded CPython 3.10Windows x86-64

operant-0.3.1-cp310-cp310-macosx_11_0_arm64.whl (277.2 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

operant-0.3.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (324.2 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

File details

Details for the file operant-0.3.1-cp314-cp314-win_amd64.whl.

File metadata

  • Download URL: operant-0.3.1-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 170.3 kB
  • Tags: CPython 3.14, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for operant-0.3.1-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 0caea10670d2223838ee715b924e898509c4e8060bf9538eb680addbd9321804
MD5 aa568eeecf2a245bc1faebe56cbe299d
BLAKE2b-256 cd347512b7f7667c17421ab2cdc7ac398d63e93b4c3bc9a87ee67068c0ea501f

See more details on using hashes here.

Provenance

The following attestation bundles were made for operant-0.3.1-cp314-cp314-win_amd64.whl:

Publisher: publish.yml on galenoshea/operant

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file operant-0.3.1-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for operant-0.3.1-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9565b8688f88f8dad01bd3b092163f38341f815318efd9d941a0b300e65a0701
MD5 926a38975d82f2ac45f0e821dfaaefa8
BLAKE2b-256 82d961aff660686ce91bcec25373d91602753c675ea7965ed5fc48bcb89c33ba

See more details on using hashes here.

Provenance

The following attestation bundles were made for operant-0.3.1-cp314-cp314-macosx_11_0_arm64.whl:

Publisher: publish.yml on galenoshea/operant

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file operant-0.3.1-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: operant-0.3.1-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 169.8 kB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for operant-0.3.1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 e4b88149f36d0263c4c9912661bab6723271c93f698230eb1bb4467fb751658e
MD5 db7934f181af646629548900e654499f
BLAKE2b-256 5e61f18ee365359b2a702eea36bd71e837dd4662fd81ccb9c99103ec894416ad

See more details on using hashes here.

Provenance

The following attestation bundles were made for operant-0.3.1-cp313-cp313-win_amd64.whl:

Publisher: publish.yml on galenoshea/operant

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file operant-0.3.1-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for operant-0.3.1-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6a4e0a2bf481da090a99a6608b37dcc16ce952c46e4cd315bf2b4cce470fe50c
MD5 eec407b7cb8d02bd9f014f4151893285
BLAKE2b-256 f4b97f3f5f17e58be75fc85447850542a82c9ffac61347b24e3b20e617143927

See more details on using hashes here.

Provenance

The following attestation bundles were made for operant-0.3.1-cp313-cp313-macosx_11_0_arm64.whl:

Publisher: publish.yml on galenoshea/operant

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file operant-0.3.1-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: operant-0.3.1-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 169.9 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for operant-0.3.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 82860968e459a034d065c31ca6b46f98588ef0862aa7f65e2f0c8649ba326001
MD5 62c3b48d4c6dc458d8eb121e56a1479b
BLAKE2b-256 a3299b2442d86ce79aa203a437759a1b9c8920f4b8105dfaabe27894447381df

See more details on using hashes here.

Provenance

The following attestation bundles were made for operant-0.3.1-cp312-cp312-win_amd64.whl:

Publisher: publish.yml on galenoshea/operant

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file operant-0.3.1-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for operant-0.3.1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 cac42cb010ee8a7877f8491422e002b44c11481e9cb6a40228419ebb5f980246
MD5 4ae570d4b3bb995de37653b1bf5e90c1
BLAKE2b-256 b175c96b57a55f26932e40f423020790fd1510c842b036b5680a6cd7fb67985c

See more details on using hashes here.

Provenance

The following attestation bundles were made for operant-0.3.1-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: publish.yml on galenoshea/operant

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file operant-0.3.1-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: operant-0.3.1-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 171.7 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for operant-0.3.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 f6948026b3261c06612a70dc3961e360c7f2dbb6ccf7ef86945a786097865b65
MD5 3928deeedc4ac7e72bdfc6c68487c63a
BLAKE2b-256 38405d0eeb413a2942c5d60f7aba7d2d93f8af7e9937480de8bf235dc8bf0b90

See more details on using hashes here.

Provenance

The following attestation bundles were made for operant-0.3.1-cp311-cp311-win_amd64.whl:

Publisher: publish.yml on galenoshea/operant

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file operant-0.3.1-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for operant-0.3.1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 75fae7e0b179f14c019b3f2179548e860c8c4ad8b4a78ba6baba1fee07c14329
MD5 658b6815072f4cf00551fd551eb1cbb1
BLAKE2b-256 0a8d0c61e93838dd8ed3fe5f08ad11ce4243e23b3824b3f0875e58fdcd9f3096

See more details on using hashes here.

Provenance

The following attestation bundles were made for operant-0.3.1-cp311-cp311-macosx_11_0_arm64.whl:

Publisher: publish.yml on galenoshea/operant

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file operant-0.3.1-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: operant-0.3.1-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 171.4 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for operant-0.3.1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 7371d2d2c7c661a039e8c3e01cf5ee9b94acd067dadeea5ae8cb0773ff26855b
MD5 fdbf12bb6b00d4ebea41768003bcead1
BLAKE2b-256 6e0aa70e444b3ed21280282a90c7dfcd121e0324332aaf7524b6309d17027707

See more details on using hashes here.

Provenance

The following attestation bundles were made for operant-0.3.1-cp310-cp310-win_amd64.whl:

Publisher: publish.yml on galenoshea/operant

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file operant-0.3.1-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for operant-0.3.1-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 18a744f78b50409f7df574a12c25a4b1e5fb7278a6ada6d2e4454625bf0c8f93
MD5 220db25e982ce038cca433c56e6c834c
BLAKE2b-256 6319716ad72dbe25d17ccc796caf656bebe0a57fb41973a22ce902bb5edebbed

See more details on using hashes here.

Provenance

The following attestation bundles were made for operant-0.3.1-cp310-cp310-macosx_11_0_arm64.whl:

Publisher: publish.yml on galenoshea/operant

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file operant-0.3.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for operant-0.3.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 57e794983f5dd5f39125c5cd54bfbaed47ee83ee90a6b65339b48defe72b00a2
MD5 9925d36a11dc4ee2d15596357b269bea
BLAKE2b-256 a618a5fff2e425e50b0eaac5a279dee9651515235686739d36fcbdb7f2c24f9c

See more details on using hashes here.

Provenance

The following attestation bundles were made for operant-0.3.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: publish.yml on galenoshea/operant

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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