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.0-cp313-cp313-win_amd64.whl (169.8 kB view details)

Uploaded CPython 3.13Windows x86-64

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

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.12Windows x86-64

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

Uploaded CPython 3.12macOS 11.0+ ARM64

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

Uploaded CPython 3.11Windows x86-64

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

Uploaded CPython 3.11macOS 11.0+ ARM64

operant-0.3.0-cp310-cp310-win_amd64.whl (171.3 kB view details)

Uploaded CPython 3.10Windows x86-64

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

Uploaded CPython 3.10macOS 11.0+ ARM64

operant-0.3.0-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.0-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: operant-0.3.0-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.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 17db2d45eb51ddd2761e1df5a5173ede54470d61bfb0abc0483265908690c368
MD5 167ebc4a287154ac0f36d57d9664f655
BLAKE2b-256 848b79c1fbaddff4cb1c5a4e9e44817ae49d77c95a83b4530137f988d17ac1bb

See more details on using hashes here.

Provenance

The following attestation bundles were made for operant-0.3.0-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.0-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for operant-0.3.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 07a8b294b6dd375384e98a911b1b39f97edb5e2132b659e662b3bf43adc8bfca
MD5 e39fa781e8ed42a57e61877383e0297d
BLAKE2b-256 a8b6636a0313cbb90bd4d5bf2d9873de98bb0f5c361704dd8d0f679e1cfa880d

See more details on using hashes here.

Provenance

The following attestation bundles were made for operant-0.3.0-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.0-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: operant-0.3.0-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.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 8f126a69e8e27f9fffd1a3b26cc1a4d2806eb2dad794fcba28ef6038162c0383
MD5 e46774ed9585a654f75648a5c742e472
BLAKE2b-256 66c6903f4f85b5f21a038bdaa52af8cb375fc0fa5bf244ae2252cb79dcdda765

See more details on using hashes here.

Provenance

The following attestation bundles were made for operant-0.3.0-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.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for operant-0.3.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ce34807da57c4d3c79cbc8b5c68fb3581540c50b53c7bb62ed7cc7387c10613f
MD5 f5fe34e7e62b42771323aac7d9ef90a1
BLAKE2b-256 94251559d234da667273d7488a4a4f72ffaf4b1cc4ee17ea31ef37705bc35a79

See more details on using hashes here.

Provenance

The following attestation bundles were made for operant-0.3.0-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.0-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: operant-0.3.0-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.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 19e4fbed9c85985dd08ebe53d8c661fbaa9e85556b8bba11c9c0c9b9e205e5f0
MD5 ed4649986ffffafca95dcb77833b8749
BLAKE2b-256 60f17725bfd8f53425e35fbd0df98c5d2d25d4af0d8b033e356d2396db7460d6

See more details on using hashes here.

Provenance

The following attestation bundles were made for operant-0.3.0-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.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for operant-0.3.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 94f289dc169b83983584593e3200a4aa35f2cfd52a6d505f4be63dd035ec8368
MD5 32db7521b68bd405b7a49463638b0ef5
BLAKE2b-256 e7d9bf1e769176a2801157830ec0167817e9c64797cb736545d3c73275ceabed

See more details on using hashes here.

Provenance

The following attestation bundles were made for operant-0.3.0-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.0-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: operant-0.3.0-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 171.3 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.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 0d2f3d3f1949ef2819fe9e82255358fb9201f0abc4d0c35276d6be6d513c6a4f
MD5 5377090d435e21cc9fa1060095fbc4c0
BLAKE2b-256 553559c641a3c54ef8d4e4e76f830a9fde9b01b5f2acbc7a56adeb7b16cb971d

See more details on using hashes here.

Provenance

The following attestation bundles were made for operant-0.3.0-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.0-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for operant-0.3.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 baeedacc9ab6a9a361e2282dace7cb222bcdc241577091be757200497e4e2ce4
MD5 cfeeac686e70246f42300fe9f80498f8
BLAKE2b-256 af0574bd0521dcb8c36e992facd9b7716f2498f03a14067df5f2a0c58665fa0f

See more details on using hashes here.

Provenance

The following attestation bundles were made for operant-0.3.0-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.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for operant-0.3.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5caedcb26db00a34ef8d012f02fafe04d04ff57c6337a143d8009405138bfdcf
MD5 a065f91ab19e08ff36fb59dc0a21542b
BLAKE2b-256 77a69db9e5b284e4b7ce095a5209e34f220fabd98aee07e4d7f4b1e1ed9f1ae5

See more details on using hashes here.

Provenance

The following attestation bundles were made for operant-0.3.0-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