Skip to main content

Animated reinfors logo

High-throughput reinforcement-learning search and sampling in Rust, with caller-owned Python networks and training.

Reinfors runs game dynamics, search, episode orchestration, and batch assembly in a parallel Rust backend. Your inference callback is the boundary: it receives pooled NumPy observations and returns model outputs, so the network, framework, optimizer, replay, hardware placement, and distributed topology remain yours.

Game semantics cover single- and multi-agent, zero-sum, cooperative, and general-sum tasks, with turn-taking or simultaneous decisions, explicit chance, and perfect or imperfect information. Algorithms span policy-driven value learning, search-guided learning, and standalone game-theoretic solving.

import numpy as np
import reinfors as rf

game = rf.games.Connect4()
engine = rf.Engine(
    game=game,
    reward=rf.Reward(win=1.0, loss=-1.0),
    policy=rf.policies.Minimax(depth=4),
    learner=rf.learners.TreeStrap(),
    n_games=32,  # parallel episode slots
    seed=0,
)

actions = game.action_space().n

def infer(obs: np.ndarray) -> np.ndarray:
    # The network is the search's evaluation function: it scores every frontier leaf,
    # pooled across games. Replace with PyTorch, JAX, an accelerator service, or any
    # other backend; TreeStrap's targets train it toward its own deeper search results.
    return np.zeros((len(obs), 1, actions), dtype=np.float32)

batch = engine.collect(n_records=1024, infer=infer)
print(batch.obs.shape, batch.targets.shape, batch.telemetry)

Performance

Reinfors' native backend makes it much more performant than Python-loop RL libraries such as Gymnasium. Benchmarking reinfors' car_racing port against Gymnasium's CarRacing-v3 — separate implementations of the same design, with matched action space and 96x96 RGB observation content, stepped in single-threaded loops — reinfors runs ~20x more environment steps per second (medians of three 30s trials):

Steps/s, single-threaded Apple M1 Max AMD EPYC 7R32 (g5.2xlarge, SMT off, pinned)
reinfors car_racing 3,850 2,069
Gymnasium CarRacing-v3 195 148
speedup 19.7x 14.0x

Reproduce with scripts/bench_carracing_throughput.py, which reports medians, ranges, and machine provenance.

Parallelising multiplies this further, and in reinfors it is trivial — set n_threads — while collect_stream overlaps collection with training as the normal operating mode:

One Gymnasium car completes a single lap while reinfors completes 20

Benchmarked against OpenSpiel's all-C++ libtorch AlphaZero on a matched chess training workload — two-hour rounds at each stack's best measured configuration, then head-to-head play between the resulting models — reinfors sustained 9.9% higher training throughput, and its trained networks scored 0.605 ± 0.020 against OpenSpiel's over 300 paired games (+74 Elo). Protocol, evidence, and full results: reinfors-benchmarks.

Reinfors is not designed to maximize throughput at any cost or to outperform a bespoke, fully fused JAX/XLA pipeline on the fixed workload it specializes for. It targets a practical balance: native simulation, search, and batching, while games, algorithms, networks, and deployment remain modular enough for broad experimentation.

Install

pip install reinfors

Optional adapters and training dependencies are separate:

pip install "reinfors[gym]"   # Gymnasium and PettingZoo adapters
pip install "reinfors[train]" # PyTorch examples

Contributing or building from source? Start with the contributing guide and the development setup guide.

Where next?

Stability

reinfors is pre-1.0: any 0.x release may change any API, behavior, or serialized format (including snapshot and config layouts) without deprecation. Pin an exact version (reinfors==0.x.y) and read release notes when upgrading. What does hold at every version: constructors validate their inputs, and no public Python input reaches a Rust panic — both enforced by adversarial test sweeps in CI.

Citation

If you use reinfors in your research, cite it via the repository's CITATION.cff (GitHub's "Cite this repository" button renders it as BibTeX/APA). What reinfors itself builds on is catalogued in References.

License

Licensed under either of MIT or Apache-2.0, at your option. Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this work shall be dual-licensed as above, without any additional terms or conditions.

Metadata

Release files for reinfors 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for reinfors 0.4.0
File Size Uploaded
reinfors-0.4.0.tar.gz 386.5 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for reinfors 0.4.0
File
reinfors-0.4.0-cp310-abi3-win_amd64.whl CPython 3.10 abi3 Windows x86-64 Details
reinfors-0.4.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.10 abi3 Linux glibc 2.17+ x86-64 Details
reinfors-0.4.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.10 abi3 Linux glibc 2.17+ ARM64 Details
reinfors-0.4.0-cp310-abi3-macosx_11_0_arm64.whl CPython 3.10 abi3 macOS 11.0+ ARM64 Details
reinfors-0.4.0-cp310-abi3-macosx_10_12_x86_64.whl CPython 3.10 abi3 macOS 10.12+ x86-64 Details

Total release size: 47.1 MB

Release files / reinfors-0.4.0.tar.gz

Download URL reinfors-0.4.0.tar.gz
Size 386.5 kB
Tags Source
SHA-256 checksum
How to use checksums
01ef3994c286fb3800cf34bff16bf02599feab974a238b76044935768a1a1c54
BLAKE2b-256 checksum
How to use checksums
b518907bbd0c834cd62381bf65addad4c32b1764622bf10de181146dda3f2321
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 26, 2026.

Transparency log

Release files / reinfors-0.4.0-cp310-abi3-win_amd64.whl

Download URL reinfors-0.4.0-cp310-abi3-win_amd64.whl
Size 9.7 MB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
d159826120d5aa4c1c775d19bac4d3a6bdeda0a71087870f451c476d93d14fac
BLAKE2b-256 checksum
How to use checksums
02151350c3d02b027f843c230f07619a152e9579f203b22e86a0328ba6ba1aeb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 26, 2026.

Transparency log

Release files / reinfors-0.4.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL reinfors-0.4.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 9.9 MB
Tags CPython 3.10 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
85d786412e8823d5d55d53a10e4a59196e23e0f95e8ece1b8ae7ac181339a168
BLAKE2b-256 checksum
How to use checksums
d935d8a66a2525d1ff579bda6082ede696b5692dd8fcc5af8272813694f74392
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 26, 2026.

Transparency log

Release files / reinfors-0.4.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL reinfors-0.4.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 9.1 MB
Tags CPython 3.10 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
3e2e5aba8ccda37f52fa69db63f1aacd562773ba7d9096cd5bdde5c2419cd261
BLAKE2b-256 checksum
How to use checksums
f24575d55cba7a96b696712667343c28f8ce8471552dd18065d94eb1e36cf0be
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 26, 2026.

Transparency log

Release files / reinfors-0.4.0-cp310-abi3-macosx_11_0_arm64.whl

Download URL reinfors-0.4.0-cp310-abi3-macosx_11_0_arm64.whl
Size 8.6 MB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
962a97ffea577244e1f70b7b59a9967e0b8395f5e0eeb1f8258bcaedb721473c
BLAKE2b-256 checksum
How to use checksums
84008356ed49a408dce9de4e3e5f7329da655d1a183bcd1829413da1e4a0ca9b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 26, 2026.

Transparency log

Release files / reinfors-0.4.0-cp310-abi3-macosx_10_12_x86_64.whl

Download URL reinfors-0.4.0-cp310-abi3-macosx_10_12_x86_64.whl
Size 9.4 MB
Tags CPython 3.10 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
a1863999aa635ec99e498dc1f6bc030c9df5aacfbce4673b1ed2cd72b238fc3f
BLAKE2b-256 checksum
How to use checksums
bad70bbd2500d6503646e4222ea03389732086533081e7138a7da8b7ad61fd32
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 26, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.4.0 This release

6 release files

0.3.0

6 release files

0.2.0

6 release files

0.1.0

6 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page