Skip to main content

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.

PyPI Python 3.8+ License


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_std compatible 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") -> bytes
    • usage_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 node
  • SwarmConfig(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:

  1. 01_basic_compression.py - Core API usage
  2. 02_multimodal_taaf.py - Multimodal fusion (v20.0)
  3. 03_swarm_node.py - P2P gossip protocol
  4. 04_byzantine_defense.py - Cartel detection (v20.0.1)
  5. 05_regime_transitions.py - Entropy-driven state machine
  6. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

qres_raas-21.0.0.tar.gz (520.8 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

qres_raas-21.0.0-cp38-abi3-win_amd64.whl (164.0 kB view details)

Uploaded CPython 3.8+Windows x86-64

qres_raas-21.0.0-cp38-abi3-manylinux_2_34_x86_64.whl (559.0 kB view details)

Uploaded CPython 3.8+manylinux: glibc 2.34+ x86-64

qres_raas-21.0.0-cp38-abi3-macosx_11_0_arm64.whl (256.1 kB view details)

Uploaded CPython 3.8+macOS 11.0+ ARM64

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

Hashes for qres_raas-21.0.0.tar.gz
Algorithm Hash digest
SHA256 395fa60de8d03978bffa18258e816b57475063715b05fe74742245ee19844743
MD5 8cca27383460c31b31a8a9db9de80c00
BLAKE2b-256 8c1436ec8f2fb8c08dfbfc7c4ad53bfe41950815239940522bca98a6dbbee165

See more details on using hashes here.

Provenance

The following attestation bundles were made for qres_raas-21.0.0.tar.gz:

Publisher: pypi-publish.yml on CavinKrenik/QRES_RaaS

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for qres_raas-21.0.0-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 56c293e423587f3973144473fbed51a5527842cb2184b8a3265f7ffaeb669378
MD5 ab6ba6929eed6eacf3d14b9739abdccc
BLAKE2b-256 d16e8afe549b8e6bc241bcccae7045d1dbbae04956ae2966128832061b04807c

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file qres_raas-21.0.0-cp38-abi3-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for qres_raas-21.0.0-cp38-abi3-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 db30ed60d6e4bebf1eec27e8f33d0b5e40f07a6efd0a726958fd9773e657d71b
MD5 27fbd06d6227a2751daf4addeb4a407b
BLAKE2b-256 ed8de7a297dced9ac38e8f932740bdcd34a35eac4135113b979f2e1eb4674a5a

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file qres_raas-21.0.0-cp38-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for qres_raas-21.0.0-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3be395db9d739dbb29bccd5c39661591c76b498d8fdca08148548f84282c24a5
MD5 a34b804c2283c19ee1f25a53d828449a
BLAKE2b-256 31afacc4eabb89546fb04e218b590ac82cd3ceb076c678c25c954f11166cd95b

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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