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:
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?
- Get started
- Understand sampling and injectable training
- Choose a game, algorithm, or built-in composition
- Run the examples
- Evaluate searched agents with Arena
- Add a Rust game or algorithm
- Read the complete documentation
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.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| reinfors-0.3.0.tar.gz | 358.7 kB | Details |
Built distributions (wheels)
| File | Reset | |||
|---|---|---|---|---|
| reinfors-0.3.0-cp310-abi3-win_amd64.whl | CPython 3.10 | abi3 | Windows x86-64 | Details |
| reinfors-0.3.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.3.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl | CPython 3.10 | abi3 | Linux glibc 2.17+ ARM64 | Details |
| reinfors-0.3.0-cp310-abi3-macosx_11_0_arm64.whl | CPython 3.10 | abi3 | macOS 11.0+ ARM64 | Details |
| reinfors-0.3.0-cp310-abi3-macosx_10_12_x86_64.whl | CPython 3.10 | abi3 | macOS 10.12+ x86-64 | Details |
Total release size: 21.6 MB
Release files / reinfors-0.3.0.tar.gz
| Download URL | reinfors-0.3.0.tar.gz |
|---|---|
| Size | 358.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0f03da729abc0418c44f9337c944ff8b8e7ce2cdbe5b449364288cfb48becbea
|
|
BLAKE2b-256 checksum How to use checksums |
77ee09e9cf9a0d83c8ecf431c4ee10ffac8d2c9f5f6f2e3e41036d410dcccb8f
|
| 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 24, 2026.
Transparency logRelease files / reinfors-0.3.0-cp310-abi3-win_amd64.whl
| Download URL | reinfors-0.3.0-cp310-abi3-win_amd64.whl |
|---|---|
| Size | 4.2 MB |
| Tags | CPython 3.10 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
8c8c7291a739c894990dee61e18a2f7a79dcb6d74b13ee1a95587e470f5b2577
|
|
BLAKE2b-256 checksum How to use checksums |
d39d5a0b6d4508e75af8f20cec7f4d17bb712f695b85429c72f5ced2205edec5
|
| 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 24, 2026.
Transparency logRelease files / reinfors-0.3.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | reinfors-0.3.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 4.5 MB |
| Tags | CPython 3.10 Linux glibc 2.17+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
d1797cce3681402ad2b290bdf8a3225f6aa2f7d29c7ecaf951cdf312e487c522
|
|
BLAKE2b-256 checksum How to use checksums |
dd1a25ad1a412028d0d51f688e74b6605f20a5778052ded14e4d6dcd90035381
|
| 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 24, 2026.
Transparency logRelease files / reinfors-0.3.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
| Download URL | reinfors-0.3.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
|---|---|
| Size | 4.3 MB |
| Tags | CPython 3.10 Linux glibc 2.17+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
999637dc91d1d7f44d43161c226a3b8ecd757e3169f2addaae71750b72c6c74a
|
|
BLAKE2b-256 checksum How to use checksums |
722d7e7ed4da9edba53e42eceb1de26f8e32ee197df718f656e0ceba48a908ad
|
| 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 24, 2026.
Transparency logRelease files / reinfors-0.3.0-cp310-abi3-macosx_11_0_arm64.whl
| Download URL | reinfors-0.3.0-cp310-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 4.0 MB |
| Tags | CPython 3.10 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
ce8c684e89f5beb9034c0d756aa12904d454a78f6b23c2ed21be79044208f8fa
|
|
BLAKE2b-256 checksum How to use checksums |
f54e6dd9309caba1c58c0a2cca4debbce4fc0475756e508eff22a83887f566d9
|
| 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 24, 2026.
Transparency logRelease files / reinfors-0.3.0-cp310-abi3-macosx_10_12_x86_64.whl
| Download URL | reinfors-0.3.0-cp310-abi3-macosx_10_12_x86_64.whl |
|---|---|
| Size | 4.3 MB |
| Tags | CPython 3.10 abi3 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
8cdd3f3ca5b709efab0e7bc8fe01e6eebd52f5da9bac08523f81c7a6aeca01d2
|
|
BLAKE2b-256 checksum How to use checksums |
55e76645dfc2418e47cfc78a8a382bfc149a9b9701abbc521e262f84612ff6e1
|
| 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 24, 2026.
Transparency log