Skip to main content

High-performance SIMD-optimized RL environments in Rust

Project description

Operant

PyPI version Crates.io 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

Python (PyPI)

pip install operant

Rust (crates.io)

cargo add 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

Python

CartPole (Discrete Actions)

import numpy as np
from operant.envs import CartPoleVecEnv

# Create 4096 parallel environments
num_envs = 4096
env = CartPoleVecEnv(num_envs)
obs, info = 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, info = env.step(actions)

Multi-threaded Execution

For heavier environments or large batch sizes, enable parallel execution:

# Use 4 worker threads for parallel step execution
env = CartPoleVecEnv(num_envs=8192, workers=4)

MountainCar (Discrete Actions)

from operant.envs import MountainCarVecEnv

num_envs = 4096
env = MountainCarVecEnv(num_envs)
obs, info = 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, info = env.step(actions)

Pendulum (Continuous Actions)

from operant.envs import PendulumVecEnv

num_envs = 4096
env = PendulumVecEnv(num_envs)
obs, info = 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, info = env.step(actions)

Rust

use operant::{CartPole, VecEnv};

fn main() {
    // Create 1024 parallel environments
    let mut env = CartPole::new(1024);

    // Reset all environments
    let obs = env.reset();

    // Step with actions
    let actions = vec![0; 1024];
    let (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.3-cp314-cp314-win_amd64.whl (525.6 kB view details)

Uploaded CPython 3.14Windows x86-64

operant-0.3.3-cp314-cp314-macosx_11_0_arm64.whl (660.8 kB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

operant-0.3.3-cp313-cp313-win_amd64.whl (525.5 kB view details)

Uploaded CPython 3.13Windows x86-64

operant-0.3.3-cp313-cp313-macosx_11_0_arm64.whl (661.0 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

operant-0.3.3-cp312-cp312-win_amd64.whl (525.7 kB view details)

Uploaded CPython 3.12Windows x86-64

operant-0.3.3-cp312-cp312-macosx_11_0_arm64.whl (661.0 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

operant-0.3.3-cp311-cp311-win_amd64.whl (527.8 kB view details)

Uploaded CPython 3.11Windows x86-64

operant-0.3.3-cp311-cp311-macosx_11_0_arm64.whl (664.4 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

operant-0.3.3-cp310-cp310-win_amd64.whl (527.8 kB view details)

Uploaded CPython 3.10Windows x86-64

operant-0.3.3-cp310-cp310-macosx_11_0_arm64.whl (663.8 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

operant-0.3.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (823.7 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

File details

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

File metadata

  • Download URL: operant-0.3.3-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 525.6 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.3-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 811e605751040bd7f3abc52ee579ff53e37d229752db2843b116bfecd4382f5a
MD5 cfeb846850201e048c1d876634f00be7
BLAKE2b-256 fa80a72d25b3d34614ff086e71e94d788143f96e72c6c64b1b660efb386e0f3b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for operant-0.3.3-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 605db5051bed1eff2ec728e3f19946791b59c039dd3b1fb4cd39d1b6b67b9859
MD5 86033fd42ce17669ee3eb3cfa84561ce
BLAKE2b-256 5e7799af4a795b4e23505039c33385989d2a5b964c9f3a7bf7902fcefb7b12c5

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: operant-0.3.3-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 525.5 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.3-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 4951a14b1a54164a1646249053a32b9d9f1e3ce381e3e6875eba5265e15a8394
MD5 8d1f6d1f135fc638bde923affcc67668
BLAKE2b-256 1fd6dfd960a22f4450f38d94ec08754a49801dc2a54822574116c311015306d7

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for operant-0.3.3-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a9cab8cab9e99e5531326cf74d5455bde46f130e9c4e7e47ab08363f1ac25f1c
MD5 d850345871a2b3a28aebb4a4daaa04ac
BLAKE2b-256 eb18f78ce8cd5c3f256d10a7e95fe3bdfa85733ebfba0158f03b96f02cacf8e9

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: operant-0.3.3-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 525.7 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.3-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 2edc5ed6b23017f1ec0f68614448b5a9c7b37aa6eb67c0627018531f587402e1
MD5 2d3bcbb6039351aae032863bc53419dd
BLAKE2b-256 56522bc3b60aacfbc9fe6507dfd61391e75451424781ba88cf8437e4fbca9ab1

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for operant-0.3.3-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6102c4b863dc6ae9208ffdba526ec5aece7f5595c7da231fc563c416873f1aca
MD5 47283d71ebea52d42680c1dd7c920079
BLAKE2b-256 d1c82ea52eb6be24e772da055a040d3118be31249c9ed56626b536bda9ddbf7a

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: operant-0.3.3-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 527.8 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.3-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 1d829b36191aecf843ec1bcba11d2bfcad234e9b3fa2c2964ad61fd973bf5f6e
MD5 1747ece0148e872a5bf0beb5a70fb513
BLAKE2b-256 2f992fdea4a5a66dab50db42b2bf2ead87598002ae2d5537aff5d3e589dc8373

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for operant-0.3.3-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3b98f4cb66bc9b9477396c5f7d1d9efe7e4f882d788ce1f714041c87b751deb8
MD5 4fd9dee0ea01166f4ae752610d14511b
BLAKE2b-256 078e5b7d00e7af5f30a2811b42858051f8a6fbe2bfadd2270a8e67216b3244ee

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: operant-0.3.3-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 527.8 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.3-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 671bafba12d979145c5d9bf378c9136f83d2a6e16dc70a91c1310222a859a015
MD5 fdfd59902e53238faa637efe0d4b7a3b
BLAKE2b-256 476a8f5699afef59f9c4713a0343a4962b67fd32587c9d125a044b151c9e62b9

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for operant-0.3.3-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 525788efc443b002e1890294aa380e622a1936431750432019b5a331ab49c3ae
MD5 5b8cab39102024899ec2178c28d03fa6
BLAKE2b-256 9d94ceb49b7aad98c15c72d9e5e3a2f3be8971035dd7ba308810c756e7f74e70

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for operant-0.3.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 806be8ac6d7be98909319159c0e085b1e139165106970d66efa21e230f29c60c
MD5 346a4d74ff28bc78a857bf6456222ae3
BLAKE2b-256 e411a741adcedbf78eba5a52185761909197f3d1c76b95881091a2bfbf95cdd9

See more details on using hashes here.

Provenance

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