Skip to main content

Minimal RL in Rust

Project description

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.

  4. 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) })
        }
    }
    
  5. Add a pyproject.toml describing the Python package so maturin can build a wheel.

  6. Build and install the module:

    pip install .
    
  7. Use it from Python:

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

Refer to grid_world for a complete working example.

🚀 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

🏗️ 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

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.

twisterl-0.2.0-cp312-cp312-win_amd64.whl (304.9 kB view details)

Uploaded CPython 3.12Windows x86-64

twisterl-0.2.0-cp312-cp312-manylinux_2_34_x86_64.whl (450.2 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

twisterl-0.2.0-cp312-cp312-macosx_11_0_arm64.whl (397.1 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

twisterl-0.2.0-cp312-cp312-macosx_10_12_x86_64.whl (416.9 kB view details)

Uploaded CPython 3.12macOS 10.12+ x86-64

twisterl-0.2.0-cp311-cp311-win_amd64.whl (303.3 kB view details)

Uploaded CPython 3.11Windows x86-64

twisterl-0.2.0-cp311-cp311-manylinux_2_34_x86_64.whl (449.8 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ x86-64

twisterl-0.2.0-cp311-cp311-macosx_11_0_arm64.whl (400.3 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

twisterl-0.2.0-cp311-cp311-macosx_10_12_x86_64.whl (420.9 kB view details)

Uploaded CPython 3.11macOS 10.12+ x86-64

twisterl-0.2.0-cp310-cp310-win_amd64.whl (303.6 kB view details)

Uploaded CPython 3.10Windows x86-64

twisterl-0.2.0-cp310-cp310-manylinux_2_34_x86_64.whl (449.9 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ x86-64

twisterl-0.2.0-cp310-cp310-macosx_11_0_arm64.whl (399.3 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

twisterl-0.2.0-cp310-cp310-macosx_10_12_x86_64.whl (420.8 kB view details)

Uploaded CPython 3.10macOS 10.12+ x86-64

twisterl-0.2.0-cp39-cp39-win_amd64.whl (305.5 kB view details)

Uploaded CPython 3.9Windows x86-64

twisterl-0.2.0-cp39-cp39-manylinux_2_34_x86_64.whl (446.7 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.34+ x86-64

twisterl-0.2.0-cp39-cp39-macosx_11_0_arm64.whl (400.4 kB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

twisterl-0.2.0-cp39-cp39-macosx_10_12_x86_64.whl (422.4 kB view details)

Uploaded CPython 3.9macOS 10.12+ x86-64

File details

Details for the file twisterl-0.2.0-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: twisterl-0.2.0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 304.9 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for twisterl-0.2.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 0f750a58ccc36f41a29cf30535364c035406d7931cb43a068a73c4dae422c915
MD5 de5bdef445ba118fab2927bb8d2bdae8
BLAKE2b-256 bf376fee4e8f62813d573d803ba95fd84fbeb0bbf59ea6cc5f519e4d50f273bf

See more details on using hashes here.

File details

Details for the file twisterl-0.2.0-cp312-cp312-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for twisterl-0.2.0-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 196c2cdaa84ec94bcc4e1f94f390e4497624fedd55d83157df00a674af9b160e
MD5 a86e01bed7a34043ac2e80433896425b
BLAKE2b-256 64e25049979babd087cb212ff342f0f3e64cb8e388577b90050818da5d968584

See more details on using hashes here.

File details

Details for the file twisterl-0.2.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for twisterl-0.2.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 700f2f7f50c5b7fa63387a2c980572c04e03d29e2cdaaae557cd84c5ed63edd4
MD5 dbe7ea1bd45bfa6701420c4683614f82
BLAKE2b-256 4200913f721fac47a5aebd22cec1c12cbd4b1478d2bcc725cf40ee0c527ebeab

See more details on using hashes here.

File details

Details for the file twisterl-0.2.0-cp312-cp312-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for twisterl-0.2.0-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 018bb6df39443cf58191305395f0c3f3d2ba4d0d2ea4ebd478eeaab70b9294df
MD5 898ac2ac8ffe37cb65e0776ca8773b04
BLAKE2b-256 91096bd291659d18de261f821e0895fb8d7095822a4acac16697238ad668d140

See more details on using hashes here.

File details

Details for the file twisterl-0.2.0-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: twisterl-0.2.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 303.3 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for twisterl-0.2.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 bdb1716ad3fecf46775722dd0338befb6aff4db4a25e3366f4f2ee02c1f3d34d
MD5 61554467cc38a4bc6e8ff3c494681425
BLAKE2b-256 4b986e1003a991d02b000d262c387bc838d71c60508e438c1abbedd0631c5ed3

See more details on using hashes here.

File details

Details for the file twisterl-0.2.0-cp311-cp311-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for twisterl-0.2.0-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 84cb89f1c2d733440d16bd9b5e360ae992a8e2c6ab565ca7b7cd2377d1405450
MD5 7687c2f141b25d87b15fcc43e7cc06cc
BLAKE2b-256 e5eb6a59cc5c447aace68cb52aaddd2ec001fd33f0f8beacb59d36db36b12b73

See more details on using hashes here.

File details

Details for the file twisterl-0.2.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for twisterl-0.2.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 452350007c5c1fd9bd03f494585a96ebd1fb70d9cc15b9a616194913e65d1f29
MD5 4002e2799b87717252dd137673f783fc
BLAKE2b-256 163dce0e702af47b9b36196a987acc583ad793dbe0fb144d793cc1f4704eb87c

See more details on using hashes here.

File details

Details for the file twisterl-0.2.0-cp311-cp311-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for twisterl-0.2.0-cp311-cp311-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 81c08073f4d476a6640a560be2fb83a32f702713b7b7d78d977c69b2b91b8fb9
MD5 82d939c0877839d0487b3838809e289d
BLAKE2b-256 413dddeb8e3ebb6fd697cf52f04401001245080f5f8dc81913369f7ff16b72b1

See more details on using hashes here.

File details

Details for the file twisterl-0.2.0-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: twisterl-0.2.0-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 303.6 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.11

File hashes

Hashes for twisterl-0.2.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 963d23a51774737734ae722908c7a0490404a097dd8c78b7fc3117786e10a540
MD5 a5017678dd62dc8f3051e0b37f6fe9ef
BLAKE2b-256 9838f947a3f4c092f43c8d329effc151ea5603bbacae158f5b37699c72614197

See more details on using hashes here.

File details

Details for the file twisterl-0.2.0-cp310-cp310-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for twisterl-0.2.0-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 0d0510ed915d5280c19dd19c6b5a62d12227dfad2ca4c0029754828e662e461e
MD5 5559ac81349ae5e09a661e6b54a262ca
BLAKE2b-256 6e15e92572c0fc9dcae691fc4e079b1552441e61547ee046904498d0bba6b60f

See more details on using hashes here.

File details

Details for the file twisterl-0.2.0-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for twisterl-0.2.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5c0cdb65e1152072d3847170ef188e9dee73c7831519c0e5b6cdf51689308171
MD5 cd3ab17c4eba6c0f38fc84d2b1dc0a99
BLAKE2b-256 34b5dff27f1d910eda14c7051b2e7132274023cefb51b0ee20305c4b0fe0f820

See more details on using hashes here.

File details

Details for the file twisterl-0.2.0-cp310-cp310-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for twisterl-0.2.0-cp310-cp310-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 97b93ef9769402ed10d466a190b55e01eec8f91d079537b8b77dff356f95d856
MD5 05e77487fcd0fd8db60913ccbb512429
BLAKE2b-256 5f91e8fce3efd57d9594f6befcec832e73a6edb10f4a566d8e612eef33ef53c4

See more details on using hashes here.

File details

Details for the file twisterl-0.2.0-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: twisterl-0.2.0-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 305.5 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.13

File hashes

Hashes for twisterl-0.2.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 1adaaee632dd5210dcb089252349b419f44c00e8423874b8fe6713543b7e0aae
MD5 fd50239e8f094a76644c5720324ec48d
BLAKE2b-256 93f89560849b4e9574ad650ada91f733bf4262fd8c7cdd726def06de07354858

See more details on using hashes here.

File details

Details for the file twisterl-0.2.0-cp39-cp39-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for twisterl-0.2.0-cp39-cp39-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 f2a077ccd106c796764b490f44573d35154892e15636c63b7f76170d72ffb107
MD5 cfa36e8ee1587de51817b9b76887336d
BLAKE2b-256 769c9845b57c8ecca990e0814c5c8144ef227217c582b73d9d8e56c8bd9837c0

See more details on using hashes here.

File details

Details for the file twisterl-0.2.0-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for twisterl-0.2.0-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2ca8b33d543473c0411f7c2b0624d1c3c461e73f0b56071fa081d8c47a9e5131
MD5 7d7c96f92209cafc6a4655033d57c7dd
BLAKE2b-256 e6f7dc0a53335a5cc4e4eabf0614f1e595dc5ca7f656357c86ef7fa7c2aec453

See more details on using hashes here.

File details

Details for the file twisterl-0.2.0-cp39-cp39-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for twisterl-0.2.0-cp39-cp39-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 7331ec0bc9a111c11133fb1f70f818d6eb680161c3fa461eb4f095fb0e43dd61
MD5 83ed9c5be318ece2ed3fad149d197b34
BLAKE2b-256 1ecd5d97f839c1de8e2e58d82d730e68b97e1378805f7986c526e4ada50eee95

See more details on using hashes here.

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