Skip to main content

TwisteRL

TwisteRL

A minimalistic, high-performance Reinforcement Learning framework implemented in Rust.

The current version is a Proof of Concept, stay tuned for future releases!

Install

pip install .

Use

Training

python -m twisterl.train --config examples/ppo_puzzle8_v1.json

This example trains a model to play the popular "8 puzzle":

|8|7|5|
|3|2| |
|4|6|1|

where numbers have to be shifted around through the empty slot until they are in order.

This model can be trained on a single CPU in under 1 minute (no GPU required!). A larger version (4x4) is available: examples/ppo_puzzle15_v1.json.

Inference

Check the notebook example here!

Creating your own environment

The examples/grid_world custom environment example here shows how to implement an environment in Rust and expose it to Python with PyO3. You can use it as a template:

  1. Create a new crate

    cargo new --lib examples/my_env
    
  2. Add dependencies in examples/my_env/Cargo.toml:

    [package]
    name = "my_env"
    version = "0.1.0"
    edition = "2021"
    
    [lib]
    name = "my_env"
    crate-type = ["cdylib"]
    
    [dependencies]
    pyo3 = { version = "0.20", features = ["extension-module"] }
    twisterl = { path = "path/to/twisterl/rust", features = ["python_bindings"] }
    # Or using the official crate:
    # twisterl = { version = "a.b.c", features = ["python_bindings"] }
    
  3. Implement the environment by defining a struct and implementing twisterl::rl::env::Env for it. Provide logic for reset, step, observe, reward, etc.

In inference, twisterRL algorithms track the actions applied to the environment externally. If you need the environment itself to track them, implement the track_solution and solution methods in the Env trait.

  1. Expose it to Python using PyBaseEnv:

    use pyo3::prelude::*;
    use twisterl::python_interface::env::PyBaseEnv;
    
    #[pyclass(name = "MyEnv", extends = PyBaseEnv)]
    struct PyMyEnv;
    
    #[pymethods]
    impl PyMyEnv {
        #[new]
        fn new(...) -> (Self, PyBaseEnv) {
            let env = MyEnv::new(...);
            (PyMyEnv, PyBaseEnv { env: Box::new(env) })
        }
    }
    
  2. Add a pyproject.toml describing the Python package so maturin can build a wheel.

  3. Build and install the module:

    pip install .
    
  4. Use it from Python:

    import my_env
    env = my_env.MyEnv(...)
    obs = env.reset()
    

Refer to grid_world for a complete working example.

Checkpoint Format

TwisteRL uses safetensors as the default checkpoint format for model weights. Safetensors provides:

  • Security: No arbitrary code execution (unlike pickle-based .pt files)
  • Speed: Zero-copy loading for faster model initialization
  • HuggingFace compatibility: Standard format for Hub models

Legacy .pt checkpoints are still supported for backward compatibility but will log a warning. To convert existing checkpoints:

from twisterl.utils import convert_pt_to_safetensors

convert_pt_to_safetensors("model.pt")  # Creates model.safetensors

Documentation

🚀 Key Features

  • High-Performance Core: RL episode loop implemented in Rust for faster training and inference
  • Inference-Ready: Easy compilation and bundling of models with environments into portable binaries for inference
  • Modular Design: Support for multiple algorithms (PPO, AlphaZero) with interchangeable training and inference
  • Language Interoperability: Core in Rust with Python interface
  • Symmetry-Aware Training via Twists: Environments can expose observation/action permutations (“twists”) so policies automatically exploit device or puzzle symmetries for faster learning.

🏗️ Current State (PoC)

  • Hybrid rust-python implementation:
    • Data collection and inference in Rust
    • Training in Python (PyTorch)
  • Supported algorithms:
    • PPO (Proximal Policy Optimization)
    • AlphaZero
  • Focus on discrete observation and action spaces
  • Support for native Rust environments and for Python environments through a wrapper

🚧 Roadmap

Upcoming Features (Alpha Version)

  • Full training in Rust
  • Extended support for:
    • Continuous observation spaces
    • Continuous action spaces
    • Custom policy architectures
  • Native WebAssembly environment support
  • Streamlined policy+environment bundle export to WebAssembly
  • Comprehensive Python interface
  • Enhanced documentation and test coverage

💎 Future Possibilities

  • WebAssembly environment repository
  • Browser-based environment and agent visualization
  • Interactive web demonstrations
  • Serverless distributed training

🎮 Use Cases

Currently used in:

Perfect for:

  • Puzzle-like optimization problems
  • Any scenario requiring fast, production performance RL inference

🔧 Current Limitations

  • Limited to discrete observation and action spaces
  • Python environments may create performance bottlenecks
  • Documentation and testing coverage is currently minimal
  • WebAssembly support is in development

🤝 Contributing

We're in early development stages and welcome contributions! Stay tuned for more detailed contribution guidelines.

📄 Note

This project is currently in PoC stage. While functional, it's under active development and the API may change significantly.

📜 License

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0

Metadata

Release files for twisterl 0.5.1

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

Built distributions (wheels)

Table of built distributions (wheels) for twisterl 0.5.1
File
twisterl-0.5.1-cp314-cp314-win_amd64.whl CPython 3.14 CPython 3.14 Windows x86-64 Details
twisterl-0.5.1-cp314-cp314-manylinux_2_34_x86_64.whl CPython 3.14 CPython 3.14 Linux glibc 2.34+ x86-64 Details
twisterl-0.5.1-cp314-cp314-macosx_11_0_arm64.whl CPython 3.14 CPython 3.14 macOS 11.0+ ARM64 Details
twisterl-0.5.1-cp313-cp313-win_amd64.whl CPython 3.13 CPython 3.13 Windows x86-64 Details
twisterl-0.5.1-cp313-cp313-manylinux_2_34_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.34+ x86-64 Details
twisterl-0.5.1-cp313-cp313-macosx_11_0_arm64.whl CPython 3.13 CPython 3.13 macOS 11.0+ ARM64 Details
twisterl-0.5.1-cp312-cp312-win_amd64.whl CPython 3.12 CPython 3.12 Windows x86-64 Details
twisterl-0.5.1-cp312-cp312-manylinux_2_34_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.34+ x86-64 Details
twisterl-0.5.1-cp312-cp312-macosx_11_0_arm64.whl CPython 3.12 CPython 3.12 macOS 11.0+ ARM64 Details
twisterl-0.5.1-cp312-cp312-macosx_10_12_x86_64.whl CPython 3.12 CPython 3.12 macOS 10.12+ x86-64 Details
twisterl-0.5.1-cp311-cp311-win_amd64.whl CPython 3.11 CPython 3.11 Windows x86-64 Details
twisterl-0.5.1-cp311-cp311-manylinux_2_34_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.34+ x86-64 Details
twisterl-0.5.1-cp311-cp311-macosx_11_0_arm64.whl CPython 3.11 CPython 3.11 macOS 11.0+ ARM64 Details
twisterl-0.5.1-cp311-cp311-macosx_10_12_x86_64.whl CPython 3.11 CPython 3.11 macOS 10.12+ x86-64 Details
twisterl-0.5.1-cp310-cp310-win_amd64.whl CPython 3.10 CPython 3.10 Windows x86-64 Details
twisterl-0.5.1-cp310-cp310-manylinux_2_34_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.34+ x86-64 Details
twisterl-0.5.1-cp310-cp310-macosx_11_0_arm64.whl CPython 3.10 CPython 3.10 macOS 11.0+ ARM64 Details
twisterl-0.5.1-cp310-cp310-macosx_10_12_x86_64.whl CPython 3.10 CPython 3.10 macOS 10.12+ x86-64 Details

Total release size: 7.2 MB

Release files / twisterl-0.5.1-cp314-cp314-win_amd64.whl

Download URL twisterl-0.5.1-cp314-cp314-win_amd64.whl
Size 317.9 kB
Tags CPython 3.14 Windows x86-64
SHA-256 checksum
How to use checksums
e6d6014b1f4865ced40d6b3c02b61b26c84bfd31e3b0a5c08686c3b08cd40f9d
BLAKE2b-256 checksum
How to use checksums
c606e264c04acb0590f289903207624b71e66002173881c62d896069fdd50b35
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.2

Release files / twisterl-0.5.1-cp314-cp314-manylinux_2_34_x86_64.whl

Download URL twisterl-0.5.1-cp314-cp314-manylinux_2_34_x86_64.whl
Size 455.5 kB
Tags CPython 3.14 Linux glibc 2.34+ x86-64
SHA-256 checksum
How to use checksums
c8b93afd0ec343f41d30e0a19981e18221e0a82c718254530d72cf600ad685bf
BLAKE2b-256 checksum
How to use checksums
94e69440622e1f6a7a3e0914f80d6b3b0784ffc435b34079d362848841ea197b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.2

Release files / twisterl-0.5.1-cp314-cp314-macosx_11_0_arm64.whl

Download URL twisterl-0.5.1-cp314-cp314-macosx_11_0_arm64.whl
Size 412.4 kB
Tags CPython 3.14 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
1517cf089d7214bf73e3c88f4fac5c52c0e99cbddf78fc5577a0c94f00453a79
BLAKE2b-256 checksum
How to use checksums
1cf1ca13e971cac1ccafbdbecfab1bd006de4f4ab4fe9c1e9142b73b5b3c9b65
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.2

Release files / twisterl-0.5.1-cp313-cp313-win_amd64.whl

Download URL twisterl-0.5.1-cp313-cp313-win_amd64.whl
Size 320.3 kB
Tags CPython 3.13 Windows x86-64
SHA-256 checksum
How to use checksums
3ca81767eadc492480d5ce1202f9020bce204db4512eb84335b50a387a1f5318
BLAKE2b-256 checksum
How to use checksums
6d948bab31443bdccf5fd5b4932846a31c2763004eeecc1c3c49f609ae0bd549
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.11

Release files / twisterl-0.5.1-cp313-cp313-manylinux_2_34_x86_64.whl

Download URL twisterl-0.5.1-cp313-cp313-manylinux_2_34_x86_64.whl
Size 459.4 kB
Tags CPython 3.13 Linux glibc 2.34+ x86-64
SHA-256 checksum
How to use checksums
f91a5558e5bd3a2806b79baf7ddadf42bb833fd7a59f6966131019298985f7fd
BLAKE2b-256 checksum
How to use checksums
408992c6962be9f31876c5f0c48767c9490da0cf7a87a61675afa4925702db0b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.11

Release files / twisterl-0.5.1-cp313-cp313-macosx_11_0_arm64.whl

Download URL twisterl-0.5.1-cp313-cp313-macosx_11_0_arm64.whl
Size 417.3 kB
Tags CPython 3.13 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
fa7c3f66858aabed02c22f064556e83fe15dd725fe2d231a11e6bdf153273a4c
BLAKE2b-256 checksum
How to use checksums
f7fa1957aab3afdd7ae2047244c6cee8e96c0ed386523c0435bf0e14fbd5b4cc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.11

Release files / twisterl-0.5.1-cp312-cp312-win_amd64.whl

Download URL twisterl-0.5.1-cp312-cp312-win_amd64.whl
Size 320.5 kB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
5506b263f0bee9d2b7f9a600f301f0a5caf5030c2c2ad163dc56866d14b9366a
BLAKE2b-256 checksum
How to use checksums
05a160bf2f1eef5376a4e16570aa60ba694796a90b58fa8abcc38f68b2fc63c3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.10

Release files / twisterl-0.5.1-cp312-cp312-manylinux_2_34_x86_64.whl

Download URL twisterl-0.5.1-cp312-cp312-manylinux_2_34_x86_64.whl
Size 459.4 kB
Tags CPython 3.12 Linux glibc 2.34+ x86-64
SHA-256 checksum
How to use checksums
3a504cad5394cc3f4781be8488e696fb7053a816e1741e46ea9d257cf70dc7b4
BLAKE2b-256 checksum
How to use checksums
8bc5a94f8dc86c3e3c737e7f2de904fea25feb5a68a3ed6444d8697b37c925ac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.12

Release files / twisterl-0.5.1-cp312-cp312-macosx_11_0_arm64.whl

Download URL twisterl-0.5.1-cp312-cp312-macosx_11_0_arm64.whl
Size 417.1 kB
Tags CPython 3.12 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
9933f850472f4ba67418c9a4fcb3ac38bb6f139b226664d47d8723e4aaa988b8
BLAKE2b-256 checksum
How to use checksums
48d0737de29d302c7d4ba36de997ee8c8f37a24d96f165d81f9281656933b26c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.10

Release files / twisterl-0.5.1-cp312-cp312-macosx_10_12_x86_64.whl

Download URL twisterl-0.5.1-cp312-cp312-macosx_10_12_x86_64.whl
Size 433.4 kB
Tags CPython 3.12 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
41ba0fe7ab1a08ec5484cd1eccdec53051d7c8aab6045adced533cbf0d85cb0f
BLAKE2b-256 checksum
How to use checksums
ffa3e88456d3d9d2e07ebc9db7161d182c3883314e8540996851f4ab31b4c0bc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.10

Release files / twisterl-0.5.1-cp311-cp311-win_amd64.whl

Download URL twisterl-0.5.1-cp311-cp311-win_amd64.whl
Size 316.8 kB
Tags CPython 3.11 Windows x86-64
SHA-256 checksum
How to use checksums
c72b3d692e5213376916fbe12ba1853d3756a4d17f5455a49da65b63e1e48a04
BLAKE2b-256 checksum
How to use checksums
f54142706adb8214d1ca344df0ddb76802a0d06f25a25cc8a2aeec42fea41bd4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.9

Release files / twisterl-0.5.1-cp311-cp311-manylinux_2_34_x86_64.whl

Download URL twisterl-0.5.1-cp311-cp311-manylinux_2_34_x86_64.whl
Size 455.9 kB
Tags CPython 3.11 Linux glibc 2.34+ x86-64
SHA-256 checksum
How to use checksums
b947b18835a1fc6bcb60c8cd6790c04a1824c416143eb12ba78982b8b8a23555
BLAKE2b-256 checksum
How to use checksums
19fd636312f1b8fa038c01ed72a07d8d387e065b7289a5cb917c9f42e2a1595c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.14

Release files / twisterl-0.5.1-cp311-cp311-macosx_11_0_arm64.whl

Download URL twisterl-0.5.1-cp311-cp311-macosx_11_0_arm64.whl
Size 413.3 kB
Tags CPython 3.11 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
af08560447ec0e9b6915ec9dfc8f404b0c7ce18d0aac0dcc4f66c9d5db84feca
BLAKE2b-256 checksum
How to use checksums
2c98f1b7cda575a135889fdab0e843a2c6c8de2f793cf54444df32d5e092569d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.9

Release files / twisterl-0.5.1-cp311-cp311-macosx_10_12_x86_64.whl

Download URL twisterl-0.5.1-cp311-cp311-macosx_10_12_x86_64.whl
Size 428.0 kB
Tags CPython 3.11 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
54fe58fac3f012a754762bfb001868499cd20e4892d46b497d51fda1bc0ea2bf
BLAKE2b-256 checksum
How to use checksums
cd3537ca853d218173be0969132b7ad8b08455916126df934972712ff4585aad
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.9

Release files / twisterl-0.5.1-cp310-cp310-win_amd64.whl

Download URL twisterl-0.5.1-cp310-cp310-win_amd64.whl
Size 315.8 kB
Tags CPython 3.10 Windows x86-64
SHA-256 checksum
How to use checksums
4f4c0dde9ae1038c3b62d8e65bb0679e31e98d281148e4852ef5f31d1292ffa3
BLAKE2b-256 checksum
How to use checksums
c1106f411fcd9ff64be9b08b12a696f6570a6f2d6e48b5027a2d0c5492aee1ed
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.11

Release files / twisterl-0.5.1-cp310-cp310-manylinux_2_34_x86_64.whl

Download URL twisterl-0.5.1-cp310-cp310-manylinux_2_34_x86_64.whl
Size 455.0 kB
Tags CPython 3.10 Linux glibc 2.34+ x86-64
SHA-256 checksum
How to use checksums
bb82d9e9a54ac85db611a4ec2c6f17a1645a83c14605646de555fc0009982839
BLAKE2b-256 checksum
How to use checksums
9f2ff82fe29e24745cc9d2eae4ff783a96b5ad61261999e889aebb8feeb1249a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.19

Release files / twisterl-0.5.1-cp310-cp310-macosx_11_0_arm64.whl

Download URL twisterl-0.5.1-cp310-cp310-macosx_11_0_arm64.whl
Size 413.1 kB
Tags CPython 3.10 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
c1b1d213938e3ff8ae9f93168b3be10cf5f222c3d79809eb7826d39919201ba4
BLAKE2b-256 checksum
How to use checksums
945fce16a6eba8a19f8ce97a3ff5420c9b7c655e6b58da500671e70ad477be53
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.11

Release files / twisterl-0.5.1-cp310-cp310-macosx_10_12_x86_64.whl

Download URL twisterl-0.5.1-cp310-cp310-macosx_10_12_x86_64.whl
Size 428.0 kB
Tags CPython 3.10 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
e9ac89abaa3a5289899159f139167e1da042000dc2022086c34f0901f92ded1a
BLAKE2b-256 checksum
How to use checksums
928d243962b1ef50c3600cdbf02ab49919963d35c7de75305f66801a9fb65e14
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.19

Release history Release notifications | RSS feed

This release

0.5.1 This release

18 release files

0.4.1

19 release files

0.4.0

12 release files

0.1.0

16 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