Resource-Aware Decentralized Node Mesh: Byzantine-tolerant compression and P2P gossip for edge computing
Project description
QRES Python Bindings
Resource-Aware Decentralized Node Mesh for Edge Computing
High-performance Python bindings to qres_core (Rust) enabling deterministic Byzantine-tolerant compression, multimodal fusion, and P2P gossip for IoT and edge AI applications.
Features
- ✅ Deterministic Compression: Q16.16 fixed-point math (no floating-point non-determinism)
- ✅ Byzantine Tolerance: Coordinate-wise trimmed mean, reputation system (tolerates 30% attackers)
- ✅ Multimodal Fusion: TAAF (Temporal Attention-Guided Adaptive Fusion) with sparse spiking
- ✅ Energy Efficiency: TWT scheduling, regime-aware silence (82% radio sleep time)
- ✅ No Heap Allocations:
no_stdcompatible core, <1 KB per-node overhead - ✅ Cross-Platform: x86_64, ARM64, ARM32, RISC-V, WASM
Performance:
- 4.98x–31.8x compression vs. federated learning (dataset-dependent)
- ~99% bandwidth reduction (8 KB/day vs. 2.3 GB/day typical FL baseline)
- <30 epochs to consensus (100-node swarms, verified)
Installation
From PyPI (Recommended)
pip install qres-raas
From Source (Development)
Requires Rust 1.75+ and maturin:
# Clone repository
git clone https://github.com/CavinKrenik/QRES_RaaS.git
cd QRES_RaaS/bindings/python
# Install maturin
pip install maturin
# Build and install (development mode)
maturin develop --release
# Or build wheel for distribution
maturin build --release
Dependencies
Core (always required):
pip install numpy scipy
Optional (for specific features):
# Lightweight features (CI testing)
pip install networkx gymnasium
# Full ML stack (local experimentation)
pip install torch sentence-transformers stable-baselines3 pandas matplotlib
Or install extras:
pip install qres-raas[ci] # Lightweight
pip install qres-raas[ml] # Full ML stack
Quick Start
Basic Compression
from qres import QRES_API
# Initialize API
api = QRES_API(mode="hybrid") # "hybrid" = adaptive regime detection
# Compress data
data = b"Sensor readings: temperature=23.5C, humidity=65%"
compressed = api.compress(data, usage_hint="iot")
# Decompress (deterministic)
decompressed = api.decompress(compressed)
assert data == decompressed
print(f"Compression ratio: {len(data) / len(compressed):.2f}x")
Multimodal TAAF Fusion
from qres.multimodal import TAAFPredictor, observe_multimodal
import numpy as np
# Initialize predictor
predictor = TAAFPredictor(
num_modalities=3,
fusion_mode="attention",
spike_threshold=2.0
)
# Observe sensor streams (temperature, humidity, pressure)
modality_values = [23.5, 65.0, 1013.0]
prediction, attention_weights = observe_multimodal(predictor, modality_values)
print(f"Prediction: {prediction:.2f}")
print(f"Attention: {attention_weights}")
Swarm Node Participation
from qres.swarm_cli import SwarmNode, SwarmConfig
# Configure node
config = SwarmConfig(
node_id="sensor_42",
listen_address="/ip4/0.0.0.0/tcp/0",
bootstrap_peers=["/ip4/192.168.1.10/tcp/4001"],
reputation_initial=0.8,
regime="Calm"
)
# Launch node
node = SwarmNode(config)
print(f"PeerID: {node.peer_id}")
print(f"DID: did:qres:{node.did_suffix}")
# Participate in gossip
# ... (see examples/python/03_swarm_node.py)
node.shutdown()
API Overview
qres.QRES_API
Main compression interface.
Methods:
compress(data: bytes, usage_hint: str = "auto") -> bytesusage_hint:"auto","iot","text","binary","semantic"
decompress(compressed: bytes) -> bytes
Modes:
"hybrid": Adaptive regime detection"fixed": Fixed predictor"multimodal": TAAF fusion
qres.multimodal
Multimodal fusion and TAAF predictors.
Classes:
TAAFPredictor(num_modalities, fusion_mode, spike_threshold)- Temporal Attention-Guided Adaptive Fusion
LSTMPredictor(input_size, hidden_size, num_layers)- LSTM-based compression model
Functions:
observe_multimodal(predictor, modality_values) -> (prediction, attention_weights)
qres.swarm_cli
P2P swarm node management.
Classes:
SwarmNode(config)- libp2p-based gossip nodeSwarmConfig(node_id, listen_address, bootstrap_peers, ...)
qres.persistent
Model persistence and serialization.
Classes:
ModelPersistence- Trait for storage backends (disk, cloud, IPFS)
Functions:
save_model(model, path: str)load_model(path: str) -> model
Note: GeneStorage is deprecated (v21.0), use ModelPersistence instead.
Configuration
Feature Flags
When building from source, you can enable/disable features:
# Minimal (no ML dependencies)
maturin develop --release --no-default-features --features python
# Full (all features)
maturin develop --release --features python,ml
Environment Variables
QRES_LOG_LEVEL:DEBUG,INFO,WARN,ERROR(default:INFO)QRES_DATA_DIR: Data directory for model checkpoints (default:~/.qres)
Examples
See examples/python/ for comprehensive examples:
- 01_basic_compression.py - Core API usage
- 02_multimodal_taaf.py - Multimodal fusion (v20.0)
- 03_swarm_node.py - P2P gossip protocol
- 04_byzantine_defense.py - Cartel detection (v20.0.1)
- 05_regime_transitions.py - Entropy-driven state machine
- 06_persistent_state.py - Non-volatile recovery (v18.0.0)
Run all:
cd ../../examples/python
python 01_basic_compression.py
# ... etc
Performance & Benchmarks
Compression Ratios (Verified v20.0)
| Dataset | Ratio vs. FL | Bandwidth Saved |
|---|---|---|
| SmoothSine | 31.8x | 96.9% |
| Wafer | 4.98x | 79.9% |
| ECG5000 | 4.98x | 79.9% |
Throughput (x86_64, i7-10700K)
| Operation | Time | Throughput |
|---|---|---|
compress() |
100ns | 10M ops/sec |
decompress() |
80ns | 12M ops/sec |
TAAF observe_multimodal() |
500ns | 2M obs/sec |
Memory
- Per-node overhead: <1 KB (Q16.16 fixed-point state)
- Python bindings: ~25 MB (includes maturin runtime)
Troubleshooting
Import Errors
ImportError: No module named 'qres'
Solution: Install or rebuild bindings:
cd bindings/python
maturin develop --release
Rust Compilation Errors
error: failed to compile `qres_core`
Solution: Update Rust toolchain:
rustup update stable
rustup default stable
Missing Dependencies
ModuleNotFoundError: No module named 'torch'
Solution: Install optional dependencies:
pip install qres-raas[ml]
Or skip ML features:
pip install qres-raas[ci] # Lightweight
Development
Running Tests
Requires pytest:
pip install pytest pytest-cov
pytest tests/ -v
Type Checking
Requires mypy and type stubs:
pip install mypy
mypy bindings/python/qres
Building Documentation
pip install sphinx sphinx-rtd-theme
cd docs
make html
Versioning
This package follows the core QRES version.
- v21.0.0 (Current): Documentation restructure, INV-7 liveness
- v20.0.1: Adaptive defense, regime hysteresis
- v20.0.0: TAAF multimodal fusion, adaptive reputation exponent
- v19.1.0: TWT integration, power management
See CHANGELOG.md for full history.
Contributing
Contributions welcome! See CONTRIBUTING.md.
Areas needing help:
- Additional predictor implementations (Transformer, GRU)
- Cloud storage backends (S3, Azure Blob)
- Hardware-accelerated inference (ONNX Runtime, TensorRT)
- Jupyter notebook tutorials
Citation
@software{qres2026,
author = {Krenik, Cavin},
title = {QRES: Resource-Aware Agentic Swarm},
url = {https://github.com/CavinKrenik/QRES_RaaS},
doi = {10.5281/zenodo.18474976},
year = {2026}
}
Paper: RaaS: Resource-Aware Agentic Swarm
License
Dual-licensed under MIT or Apache-2.0, at your option.
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 qres_raas-21.0.0.tar.gz.
File metadata
- Download URL: qres_raas-21.0.0.tar.gz
- Upload date:
- Size: 520.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
395fa60de8d03978bffa18258e816b57475063715b05fe74742245ee19844743
|
|
| MD5 |
8cca27383460c31b31a8a9db9de80c00
|
|
| BLAKE2b-256 |
8c1436ec8f2fb8c08dfbfc7c4ad53bfe41950815239940522bca98a6dbbee165
|
Provenance
The following attestation bundles were made for qres_raas-21.0.0.tar.gz:
Publisher:
pypi-publish.yml on CavinKrenik/QRES_RaaS
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
qres_raas-21.0.0.tar.gz -
Subject digest:
395fa60de8d03978bffa18258e816b57475063715b05fe74742245ee19844743 - Sigstore transparency entry: 925392491
- Sigstore integration time:
-
Permalink:
CavinKrenik/QRES_RaaS@f7b673c5cfe6040d85df78ead2c78273b7f8d723 -
Branch / Tag:
refs/tags/v21.0.0 - Owner: https://github.com/CavinKrenik
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-publish.yml@f7b673c5cfe6040d85df78ead2c78273b7f8d723 -
Trigger Event:
push
-
Statement type:
File details
Details for the file qres_raas-21.0.0-cp38-abi3-win_amd64.whl.
File metadata
- Download URL: qres_raas-21.0.0-cp38-abi3-win_amd64.whl
- Upload date:
- Size: 164.0 kB
- Tags: CPython 3.8+, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
56c293e423587f3973144473fbed51a5527842cb2184b8a3265f7ffaeb669378
|
|
| MD5 |
ab6ba6929eed6eacf3d14b9739abdccc
|
|
| BLAKE2b-256 |
d16e8afe549b8e6bc241bcccae7045d1dbbae04956ae2966128832061b04807c
|
Provenance
The following attestation bundles were made for qres_raas-21.0.0-cp38-abi3-win_amd64.whl:
Publisher:
pypi-publish.yml on CavinKrenik/QRES_RaaS
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
qres_raas-21.0.0-cp38-abi3-win_amd64.whl -
Subject digest:
56c293e423587f3973144473fbed51a5527842cb2184b8a3265f7ffaeb669378 - Sigstore transparency entry: 925392604
- Sigstore integration time:
-
Permalink:
CavinKrenik/QRES_RaaS@f7b673c5cfe6040d85df78ead2c78273b7f8d723 -
Branch / Tag:
refs/tags/v21.0.0 - Owner: https://github.com/CavinKrenik
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-publish.yml@f7b673c5cfe6040d85df78ead2c78273b7f8d723 -
Trigger Event:
push
-
Statement type:
File details
Details for the file qres_raas-21.0.0-cp38-abi3-manylinux_2_34_x86_64.whl.
File metadata
- Download URL: qres_raas-21.0.0-cp38-abi3-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 559.0 kB
- Tags: CPython 3.8+, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
db30ed60d6e4bebf1eec27e8f33d0b5e40f07a6efd0a726958fd9773e657d71b
|
|
| MD5 |
27fbd06d6227a2751daf4addeb4a407b
|
|
| BLAKE2b-256 |
ed8de7a297dced9ac38e8f932740bdcd34a35eac4135113b979f2e1eb4674a5a
|
Provenance
The following attestation bundles were made for qres_raas-21.0.0-cp38-abi3-manylinux_2_34_x86_64.whl:
Publisher:
pypi-publish.yml on CavinKrenik/QRES_RaaS
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
qres_raas-21.0.0-cp38-abi3-manylinux_2_34_x86_64.whl -
Subject digest:
db30ed60d6e4bebf1eec27e8f33d0b5e40f07a6efd0a726958fd9773e657d71b - Sigstore transparency entry: 925392539
- Sigstore integration time:
-
Permalink:
CavinKrenik/QRES_RaaS@f7b673c5cfe6040d85df78ead2c78273b7f8d723 -
Branch / Tag:
refs/tags/v21.0.0 - Owner: https://github.com/CavinKrenik
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-publish.yml@f7b673c5cfe6040d85df78ead2c78273b7f8d723 -
Trigger Event:
push
-
Statement type:
File details
Details for the file qres_raas-21.0.0-cp38-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: qres_raas-21.0.0-cp38-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 256.1 kB
- Tags: CPython 3.8+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3be395db9d739dbb29bccd5c39661591c76b498d8fdca08148548f84282c24a5
|
|
| MD5 |
a34b804c2283c19ee1f25a53d828449a
|
|
| BLAKE2b-256 |
31afacc4eabb89546fb04e218b590ac82cd3ceb076c678c25c954f11166cd95b
|
Provenance
The following attestation bundles were made for qres_raas-21.0.0-cp38-abi3-macosx_11_0_arm64.whl:
Publisher:
pypi-publish.yml on CavinKrenik/QRES_RaaS
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
qres_raas-21.0.0-cp38-abi3-macosx_11_0_arm64.whl -
Subject digest:
3be395db9d739dbb29bccd5c39661591c76b498d8fdca08148548f84282c24a5 - Sigstore transparency entry: 925392654
- Sigstore integration time:
-
Permalink:
CavinKrenik/QRES_RaaS@f7b673c5cfe6040d85df78ead2c78273b7f8d723 -
Branch / Tag:
refs/tags/v21.0.0 - Owner: https://github.com/CavinKrenik
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-publish.yml@f7b673c5cfe6040d85df78ead2c78273b7f8d723 -
Trigger Event:
push
-
Statement type: