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.2-cp314-cp314-win_amd64.whl (171.5 kB view details)

Uploaded CPython 3.14Windows x86-64

operant-0.3.2-cp314-cp314-macosx_11_0_arm64.whl (276.9 kB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

operant-0.3.2-cp313-cp313-win_amd64.whl (171.0 kB view details)

Uploaded CPython 3.13Windows x86-64

operant-0.3.2-cp313-cp313-macosx_11_0_arm64.whl (276.5 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

operant-0.3.2-cp312-cp312-win_amd64.whl (171.1 kB view details)

Uploaded CPython 3.12Windows x86-64

operant-0.3.2-cp312-cp312-macosx_11_0_arm64.whl (276.6 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

operant-0.3.2-cp311-cp311-win_amd64.whl (172.9 kB view details)

Uploaded CPython 3.11Windows x86-64

operant-0.3.2-cp311-cp311-macosx_11_0_arm64.whl (278.4 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

operant-0.3.2-cp310-cp310-win_amd64.whl (172.6 kB view details)

Uploaded CPython 3.10Windows x86-64

operant-0.3.2-cp310-cp310-macosx_11_0_arm64.whl (278.4 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

operant-0.3.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (325.4 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

File details

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

File metadata

  • Download URL: operant-0.3.2-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 171.5 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.2-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 cc35cfe1b253b69e498327cc0932d1909770d303bda6ad4d8242e48f41d55678
MD5 e0aeed83d5b188c4f09b76fb9f25af75
BLAKE2b-256 fe219da3755b0d2a0b9f727c33d578c0617e9eecac3aec7f20080084f2548a0c

See more details on using hashes here.

Provenance

The following attestation bundles were made for operant-0.3.2-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.2-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for operant-0.3.2-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 34183479854bb3c600380e7184c2f323e459ea5dce78c55c1bd72616fd4b3437
MD5 800568a0cfd333c7a5a1ad0d6bda20f8
BLAKE2b-256 9d44aec672435e34ea860620730188baf7b1115932f1daf8a694dd591695f877

See more details on using hashes here.

Provenance

The following attestation bundles were made for operant-0.3.2-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.2-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: operant-0.3.2-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 171.0 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.2-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 9e86db99cb610a6e269c954a893a0eb166311c706f288c1cadc017877919a6b5
MD5 348b2e3099642937f98ee9094f53f447
BLAKE2b-256 dc15d840064bc6342c5e2f16f0ab69fe226cdd2ab619c3eaf4773b3ab6abe2c4

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for operant-0.3.2-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ebc5913e5a43751b59772f2d3a6dafa2b16543fc10c2ecbf58b8f083ba0f4342
MD5 6a1448095fe987d952c779bc40988d2a
BLAKE2b-256 4dc0e12f52bb911bcee545de34e8515394f0f71836593469889ed3d5e1b87621

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: operant-0.3.2-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 171.1 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.2-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 bc3391a5cd7aab8aa61b69268f48c4d01a8861cdc2fda722663d1c0618a6a1a0
MD5 820b1eae868bb47a87a84bb693be5405
BLAKE2b-256 90430cf048ffb0c1ea71c07bd0e8d3c6858260d85f17ee2dd922ac04255c50a8

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for operant-0.3.2-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 da4b51aaaabd0496d517c54ff7f7473c85455b899dadba8bb5e561da8b0b67fc
MD5 8840a12d5d11dbd5c4898c79b9be8f9f
BLAKE2b-256 6279391816bdbf7c48b492d3f54c0d32ef06fc49237fcb284da8c547077d0b67

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: operant-0.3.2-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 172.9 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.2-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 c95f212e1a243bce23994f43bff829c40ce2350b2daf0c336e9ee08361880075
MD5 8508bb47023b3d348c394776f304c175
BLAKE2b-256 ef1bb02334938d94382b70fb4fa561318e5eef0d9e3493dabdd6329a6c94e8e5

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for operant-0.3.2-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f42990f29b54b28314eb582b13150ad96e41116a8b26b1ab07453acd581b519d
MD5 43ede49bbddbab0d1b083306af3b52b7
BLAKE2b-256 7844cbd83f6a19d61aca84e40e45f18443e78ff4294b295ba1a566c318684594

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: operant-0.3.2-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 172.6 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.2-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 f306085d3d8ac22a0e0fc5858d313236966e47a8c18183fccd7432c9f13e1f47
MD5 66ad0189ee8f5c69cb27a3a9f0c206d8
BLAKE2b-256 7a6b631b308dad23932a61cd4459af2ee88dd20864f1ec49c6473e012fa9a3c8

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for operant-0.3.2-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 42eb6bcfe66b8c712901c43db85fd6b511527b403811b3e65ee58fc7e126e521
MD5 800d578cbb971b8c2a21666601389f67
BLAKE2b-256 d285c7ea2d9e301281bc8be2141b4396fe081d1bcd60ff5e4b5fbd4ffa0a6732

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for operant-0.3.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ba14b45907bda12cdc19753a18e8a0ac7cb947a14bd27bd2ccbdefb9a003aee8
MD5 e44b4075dee59913e8165ff3245ddb94
BLAKE2b-256 ebaca1017ed02c28fe9d413d82159167d2238c159a2b16f3e8f38031dd12eb47

See more details on using hashes here.

Provenance

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