Skip to main content

matrix-compute-sdk

Open In Colab — 01 Quickstart Open In Colab — 02 Partitioning Open In Colab — 03 Confidential TEE

Production-grade consumer Python library and orchestrator for distributed matrix multiplication over decentralized compute nodes.

Features

  • Matrix Tiling & Result Assembly: Partition arbitrary 2D matrices (FP32, FP16, BF16) into sub-matrix blocks matching worker VRAM constraints and reassemble dot product results accurately.
  • Worker Discovery & Matchmaking: Query Nostr discovery relays (Kind 30000 WORKER_ANNOUNCE events) with Pareto candidate ranking by price, reputation, and VRAM.
  • L402 Trustless Escrow: Coordinate with settlement services to manage Lightning HODL invoice lifecycles (preimage generation, hold verification, conditional settlement on verification pass, refund on dispute).
  • P2P gRPC Task Dispatch: Stream chunked tensor blocks to compute workers over gRPC (MatrixComputeService).
  • Mathematical Verification: Randomized $O(n^2)$ Freivalds verification ($ABr = Cr$) using Higham's dynamic scale-aware error bound ($\gamma_K |A|\infty |B|\infty$).
  • Fraud Proof Construction: Automated generation of cryptographically signed FreivaldsFraudProof payloads for worker bond slashing upon detecting malicious or perturbed outputs.
  • Hermetic Test Doubles: High-fidelity in-memory doubles (MockNostrRelay, MockSettlementService, MockWorkerNode) for 100% offline, deterministic testing.

Installation

pip install -e .

Quickstart

1. High-Level Distributed Matrix Multiplication

import numpy as np
from matrix_compute import MatrixComputeClient, distributed_matmul

# Generate random input matrices
A = np.random.randn(1024, 1024).astype(np.float32)
B = np.random.randn(1024, 1024).astype(np.float32)

# Using context manager with hermetic test doubles (offline mode)
with MatrixComputeClient.for_testing() as client:
    C = client.matmul(A, B, dtype="fp32")
    assert np.allclose(C, A @ B, atol=1e-4)

# Or using top-level convenience function
C = distributed_matmul(A, B)

2. Manual Configuration

from matrix_compute.config import ClientConfig
from matrix_compute.client import MatrixComputeClient

config = ClientConfig(
    relay_urls=["wss://relay.damus.io"],
    settlement_url="https://settlement.matrix.network",
    min_vram_mb=8192,
    max_price_sats_per_gflop=0.001,
    freivalds_rounds=5,
)

client = MatrixComputeClient(config=config)
C = client.matmul(A, B)

Architecture & Modules

src/matrix_compute/
├── __init__.py          # Public API exports & version
├── client.py            # High-level MatrixComputeClient and distributed_matmul
├── config.py            # ClientConfig & environment resolution
├── exceptions.py        # MatrixComputeError domain hierarchy
├── crypto/              # Secp256k1 key generation, BIP-62 low-S ECDSA, SHA-256 digests
├── test_doubles/        # MockNostrRelay, MockSettlementService, MockWorkerNode
├── tiling/              # 3D grid partitioning, BF16 emulation, and result assembly
├── verification/        # Dynamic Freivalds verification and FreivaldsFraudProof builder
├── discovery/           # Nostr Kind 30000 relay client and Pareto worker matchmaker
├── payment/             # L402 challenge parsing and HODL invoice escrow coordinator
├── p2p/                 # P2P gRPC streaming dispatcher and channel pool
└── orchestrator/        # Parallel task scheduler and compute coordinator

Testing

The SDK contains a comprehensive test suite (590 tests) covering unit, component, opaque-box E2E, and Tier 5 adversarial stress tests:

# Run all unit and component tests (415 tests)
pytest tests/unit -v

# Run all E2E opaque-box acceptance tests (142 tests)
pytest tests/e2e/test_opaque_acceptance.py tests/e2e/test_distributed_matmul.py tests/e2e/test_fraud_slashing.py -v

# Run Tier 5 adversarial hardening suite (33 tests)
pytest tests/e2e/test_adversarial_hardening.py -v

# Run the complete test suite (590 tests)
pytest tests/ -v

Metadata

Release files for matrix-compute-sdk 0.1.0

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

Source distribution (sdist)

Source distribution for matrix-compute-sdk 0.1.0
File Size Uploaded Provenance Actions
matrix_compute_sdk-0.1.0.tar.gz 181.1 kB Without provenance Details for matrix_compute_sdk-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for matrix-compute-sdk 0.1.0
File Interpreter ABI Platform Actions
matrix_compute_sdk-0.1.0-py3-none-any.whl Python 3 none any Details for matrix_compute_sdk-0.1.0-py3-none-any.whl

Total release size: 382.4 kB

Release files / matrix_compute_sdk-0.1.0.tar.gz

Download URL matrix_compute_sdk-0.1.0.tar.gz
Size 181.1 kB
Tags Source
SHA-256 checksum
How to use checksums
3284149aff26770f264039ce8e64a03f5de6d12b47e155dd94d8e552bc8b936f
BLAKE2b-256 checksum
How to use checksums
2a63873b7839c797dec9fbefd5d1f34a526a2d612c54353ce27cb9f28219e07a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.8.10

Release files / matrix_compute_sdk-0.1.0-py3-none-any.whl

Download URL matrix_compute_sdk-0.1.0-py3-none-any.whl
Size 201.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e20c295631ffe5e834d146d79afb571847093e7488d8a5ce455f537bed967bfe
BLAKE2b-256 checksum
How to use checksums
d72daa2336e415cd045689612bca6fa4c6d75c934d717dfeb4b7193737bd99f5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.8.10

Security for matrix-compute-sdk 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

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