High-performance, scalable Reservoir Computing framework in C++ with Python bindings.
Project description
rclib: Reservoir Computing Library
rclib is a high-performance, scalable, and general-purpose reservoir computing framework implemented in C++ with Python bindings. It is designed to handle both small-scale networks and medium-to-large scale architectures, supporting deep (stacked) and parallel reservoir configurations.
Project Goals
- Performance: Core logic in C++17 using Eigen for linear algebra.
- Scalability: Efficient handling of sparse reservoirs and complex architectures.
- Flexibility: Modular design separating Reservoirs and Readouts.
- Ease of Use: Pythonic interface via
pybind11andscikit-learnstyle API. - Reproducibility: Deterministic results via explicit seeding of random reservoirs.
Getting Started
Prerequisites
- C++ Compiler: GCC, Clang, or MSVC supporting C++17.
- CMake: Version 3.15 or higher.
- Python: Version 3.10 or higher (for Python bindings).
- Build Tool:
uvis recommended for managing the Python environment, but standardpipworks too. - OpenMP: Required for parallelization.
- Ubuntu/Debian:
sudo apt install libomp-dev
- Ubuntu/Debian:
Building from Source
-
Clone the repository:
git clone --recursive https://github.com/hrshtst/rclib.git cd rclib
Note: The
--recursiveflag is crucial to fetch dependencies (Eigen, Catch2, pybind11) located incpp_core/third_party. If you cloned without--recursive, run:git submodule update --init --recursive
-
Build C++ Core and Examples:
# Build with examples enabled (defaults: Release type, Export Compile Commands ON) cmake -S . -B build -DBUILD_EXAMPLES=ON cmake --build build --config Release -j $(nproc)
-
Run a C++ Example:
# Run the Mackey-Glass time series prediction example (if built with -DBUILD_EXAMPLES=ON) ./build/examples/cpp/mackey_glass
Using the Python Interface
This project provides Python bindings for the core C++ code, leveraging uv, scikit-build-core, and pybind11.
To enable fast incremental builds and automatic rebuilding when C++ source files change (see astral-sh/uv#13998), use the following two-step installation process:
# 1. Install build dependencies without installing the project
uv sync --no-install-project --only-group build
# 2. Install the project and remaining dependencies
uv sync
# Run the quick start example
uv run python examples/python/quick_start.py
With this configuration, any changes to the C++ source code in cpp_core will automatically trigger a rebuild of the Python extension module upon the next import, ensuring your Python environment always uses the latest C++ logic without manual recompilation.
Integrating rclib_core into Your C++ Project (CMake)
If you wish to use rclib_core as a static library in your own C++ project, the recommended approach is to add it as a Git submodule.
-
Add
rclibas a Git Submodule: Navigate to your project's root directory and addrclibas a submodule:git submodule add https://github.com/hrshtst/rclib.git third_party/rclib git submodule update --init --recursive third_party/rclib
(Adjust
third_party/rclibto your desired path.) -
Integrate with Your
CMakeLists.txt: In your project'sCMakeLists.txtfile, addrclibas a subdirectory and link against itsrclib_coretarget. Ensure you propagate relevant build options like OpenMP if needed.# Add rclib as a subdirectory add_subdirectory(third_party/rclib) # Example of how to link rclib_core to your target executable or library add_executable(my_rc_app main.cpp) target_link_libraries(my_rc_app PRIVATE rclib_core) # Note: rclib_core internally handles its Eigen dependency. # If your project directly uses Eigen, ensure it's properly configured in your CMakeLists.txt.
-
Configure Parallelization (Optional): If your project also uses OpenMP or needs to control
rclib's parallelization, you can set theRCLIB_USE_OPENMPandRCLIB_ENABLE_EIGEN_PARALLELIZATIONCMake options before callingadd_subdirectory(third_party/rclib).set(RCLIB_USE_OPENMP ON CACHE BOOL "Enable OpenMP support in rclib_core") set(RCLIB_ENABLE_EIGEN_PARALLELIZATION OFF CACHE BOOL "Enable Eigen's internal parallelization in rclib_core") add_subdirectory(third_party/rclib) # ... rest of your project's CMakeLists.txt
Running Tests
Using Nox (Recommended)
nox automates environment setup and execution for both Python and C++.
# Run all default sessions (Lint, Type Check, Python Tests)
uv run nox
# Run Python tests only
uv run nox -s tests
# Run C++ tests only
uv run nox -s tests_cpp
Manual Execution (Step-by-Step)
If you prefer to run tests manually without nox:
C++ Tests
# 1. Configure and build
cmake -S . -B build -DBUILD_TESTING=ON
cmake --build build --config Release -j $(nproc)
# 2. Run tests
ctest --test-dir build --output-on-failure
Python Tests
# 1. Build and install the C++ extension in the current environment
cmake -S . -B build
cmake --build build --config Release -j $(nproc) --target _rclib
# 2. Run pytest
uv run pytest
Documentation
The project documentation is built using mkdocs and the Material theme. It includes theoretical background, user guides, and API references.
Using Nox (Recommended)
# Build the documentation
uv run nox -s docs
Manual Execution
If you prefer to run mkdocs directly:
# 1. Install documentation dependencies
uv sync --group docs
# 2. Build the documentation
uv run mkdocs build
# 3. Serve the documentation locally with live-reloading
uv run mkdocs serve
The documentation is automatically deployed to https://hrshtst.github.io/rclib/ on every push to the main branch.
Parallelization Configuration
rclib provides flexible options to control parallelization strategies, allowing you to optimize for your specific workload and hardware. This is managed via CMake options.
Options
| Option | Default | Description |
|---|---|---|
RCLIB_USE_OPENMP |
ON |
Enables OpenMP support. Required for any multi-threading. |
RCLIB_ENABLE_EIGEN_PARALLELIZATION |
ON |
Enables Eigen's internal parallelization (using OpenMP). |
Recommended Configurations
1. Default (Balanced Performance)
Best for: Most workloads, from small to large reservoirs.
-
rclibautomatically parallelizes large reservoir updates (N > 1000). -
Eigen parallelizes dense matrix operations (beneficial for Ridge regression training).
-
Configuration:
cmake -S . -B build -DRCLIB_USE_OPENMP=ON -DRCLIB_ENABLE_EIGEN_PARALLELIZATION=ON
2. User-Level Parallelism Only (Hybrid)
Best for: Specific cases with many small reservoirs where Eigen's threading overhead might be excessive.
- Configuration:
cmake -S . -B build -DRCLIB_USE_OPENMP=ON -DRCLIB_ENABLE_EIGEN_PARALLELIZATION=OFF
3. Serial (Single-Threaded)
Best for: Debugging or systems without OpenMP.
- Configuration:
cmake -S . -B build -DRCLIB_USE_OPENMP=OFF
Performance Benchmarking
The benchmarks/ directory contains scripts to evaluate performance across different thread counts and parallelization modes.
-
Run the Benchmark Suite:
./benchmarks/benchmark_parallel_comparison.sh
This script compiles the project in different modes (Serial, User OMP, Eigen OMP) and runs the
performance_benchmarkexecutable multiple times. -
Visualize Results:
uv run python benchmarks/plot_parallel_comparison.py
This generates plots comparing execution time and MSE for different methods and configurations.
Development
Code Quality Tools
The project uses several tools to ensure code quality, all of which are integrated into pre-commit and nox:
- Ruff: For Python linting and formatting.
- Basedpyright: For static type checking.
- clang-format: For C++ formatting (LLVM style).
- shellcheck: For shell script linting.
- cmake-format / cmake-lint: For CMake formatting and linting.
- pre-commit: To enforce checks before committing.
Automation with Nox
nox is used to automate various development tasks:
uv run nox -s lint: Run linters.uv run nox -s type_check: Run type checkers.uv run nox -s tests: Run Python tests.uv run nox -s tests_cpp: Run C++ tests.uv run nox -s docs: Build documentation.
Setting up pre-commit
To ensure all code follows the project's style and quality standards, it is recommended to set up pre-commit:
uv run pre-commit install
AI Assistance & Development Workflow
This project is developed with the assistance of an AI coding agent using the Gemini CLI tool. The AI is also used to generate commit messages and parts of the documentation, including API and theoretical reference sections.
Workflow:
- Context & Theory (Human): The maintainer, Hiroshi Atsuta, establishes the project roadmap in
GEMINI.mdand writes the theoretical background implemented as documentation in docs/theory/. - Implementation (AI): The AI assistant uses these documents and the constraints defined in
GEMINI.mdto implement code scaffolding, core logic, tests, and documentation. - Review & Revision (Human): The maintainer reviews, tests, and revises the generated code to ensure quality and correctness. This iterative cycle ensures high standards while leveraging AI efficiency.
Responsibility: All responsibilities for the code hosted in this repository lie with the maintainer. The AI serves strictly as an implementation assistant; final architectural decisions and code quality are human-led.
Feedback: If you identify problems, or find code that appears to be unoriginal or rights-protected, please notify the maintainer immediately by filing an issue.
Contributor Policy: External contributors are welcome to use AI tools for assistance, provided they adhere to the same standard of review and responsibility. If you use AI to generate code for a Pull Request, please disclose it in the PR description and ensure you have thoroughly reviewed and tested the code.
Acknowledgments
This project is supported by the MITOU Target Program (Reservoir Computing field) of the Information-technology Promotion Agency, Japan (IPA). Details of the supported project can be found in the official summary (Japanese).
License
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file rclib-0.0.5.tar.gz.
File metadata
- Download URL: rclib-0.0.5.tar.gz
- Upload date:
- Size: 4.7 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4f2563394674776df61ec3bdf94cfe3bc8cc5ecc5aa100c824ad8858da8df316
|
|
| MD5 |
db16be098d4930de60fc95fca4838d36
|
|
| BLAKE2b-256 |
351e0da66a810ce788f787318acaadbdc458ac8491eb05eec19a474d19893f19
|
Provenance
The following attestation bundles were made for rclib-0.0.5.tar.gz:
Publisher:
release.yml on hrshtst/rclib
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
rclib-0.0.5.tar.gz -
Subject digest:
4f2563394674776df61ec3bdf94cfe3bc8cc5ecc5aa100c824ad8858da8df316 - Sigstore transparency entry: 952172822
- Sigstore integration time:
-
Permalink:
hrshtst/rclib@9590ccaf51c52b49e394099793254207d031e06b -
Branch / Tag:
refs/tags/v0.0.5 - Owner: https://github.com/hrshtst
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@9590ccaf51c52b49e394099793254207d031e06b -
Trigger Event:
release
-
Statement type:
File details
Details for the file rclib-0.0.5-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: rclib-0.0.5-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 2.3 MB
- Tags: CPython 3.13, manylinux: glibc 2.27+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d255a7e2abbb0d2fa76778575ff15188b416a39f1d63cb83c0188c178ba827ab
|
|
| MD5 |
5604294be8d9ed23d37d551c3ae62c64
|
|
| BLAKE2b-256 |
b5f0d4fb854160d764fdfa0560f57cdbbbcc8ce453b9d38ec7474deafb01226a
|
Provenance
The following attestation bundles were made for rclib-0.0.5-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:
Publisher:
release.yml on hrshtst/rclib
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
rclib-0.0.5-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl -
Subject digest:
d255a7e2abbb0d2fa76778575ff15188b416a39f1d63cb83c0188c178ba827ab - Sigstore transparency entry: 952172840
- Sigstore integration time:
-
Permalink:
hrshtst/rclib@9590ccaf51c52b49e394099793254207d031e06b -
Branch / Tag:
refs/tags/v0.0.5 - Owner: https://github.com/hrshtst
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@9590ccaf51c52b49e394099793254207d031e06b -
Trigger Event:
release
-
Statement type:
File details
Details for the file rclib-0.0.5-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: rclib-0.0.5-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 2.3 MB
- Tags: CPython 3.12, manylinux: glibc 2.27+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
02482cde513b206035e2fbc53486f1407455f8300b77180d9bcb8dcd1fb767c6
|
|
| MD5 |
f9679302c7c61f92ad39cc7ab2b20023
|
|
| BLAKE2b-256 |
030fc5507e69ce6d9215a5ff70d150ab6bc81f910c415169a9a755352ccb796a
|
Provenance
The following attestation bundles were made for rclib-0.0.5-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:
Publisher:
release.yml on hrshtst/rclib
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
rclib-0.0.5-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl -
Subject digest:
02482cde513b206035e2fbc53486f1407455f8300b77180d9bcb8dcd1fb767c6 - Sigstore transparency entry: 952172890
- Sigstore integration time:
-
Permalink:
hrshtst/rclib@9590ccaf51c52b49e394099793254207d031e06b -
Branch / Tag:
refs/tags/v0.0.5 - Owner: https://github.com/hrshtst
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@9590ccaf51c52b49e394099793254207d031e06b -
Trigger Event:
release
-
Statement type:
File details
Details for the file rclib-0.0.5-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: rclib-0.0.5-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 2.3 MB
- Tags: CPython 3.11, manylinux: glibc 2.27+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1b7a1d1b72c32507b9725911cb9976fbe23735eb8a5391e91340ffae0c21b057
|
|
| MD5 |
0ff3754a5d53a9b12ae044e7cadc0104
|
|
| BLAKE2b-256 |
1a83c20e290e07043f4ecb5e22d6970a71ed1b042df2a5d25305f45e5cad3285
|
Provenance
The following attestation bundles were made for rclib-0.0.5-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:
Publisher:
release.yml on hrshtst/rclib
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
rclib-0.0.5-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl -
Subject digest:
1b7a1d1b72c32507b9725911cb9976fbe23735eb8a5391e91340ffae0c21b057 - Sigstore transparency entry: 952172862
- Sigstore integration time:
-
Permalink:
hrshtst/rclib@9590ccaf51c52b49e394099793254207d031e06b -
Branch / Tag:
refs/tags/v0.0.5 - Owner: https://github.com/hrshtst
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@9590ccaf51c52b49e394099793254207d031e06b -
Trigger Event:
release
-
Statement type: