Skip to main content

High-performance Union Find decoder for quantum error correction

Project description

prav

PyPI version Python versions License

High-performance Union Find decoder for quantum error correction.

Installation

pip install prav

Quick Start

import prav
import numpy as np

# Create a decoder for a 17x17 square lattice
decoder = prav.Decoder(17, 17, topology="square")

# Create syndrome data (bitpacked u64 array)
syndromes = np.zeros(8, dtype=np.uint64)
syndromes[0] = 0b11  # Two adjacent defects at nodes 0 and 1

# Decode and get corrections
corrections = decoder.decode(syndromes)
# corrections is a flat array [u0, v0, u1, v1, ...]

Supported Topologies

Topology Description Use Case
square 4-neighbor square lattice Surface codes
triangular 6-neighbor triangular lattice Color codes
honeycomb 3-neighbor honeycomb lattice Kitaev model
3d 6-neighbor 3D cubic lattice 3D codes

API Reference

prav.Decoder(width, height, topology="square", depth=1)

Create a new decoder instance.

Parameters:

  • width (int): Grid width in nodes (must be > 0)
  • height (int): Grid height in nodes (must be > 0)
  • topology (str): Grid topology (default: "square")
  • depth (int): Grid depth for 3D codes (default: 1, must be > 0)

Raises:

  • ValueError: If width, height, or depth is 0, or if topology is invalid

decoder.decode(syndromes) -> np.ndarray[np.uint32]

Decode syndromes and return edge corrections.

Parameters:

  • syndromes (np.ndarray[np.uint64]): Dense bitpacked syndrome array

Returns:

  • Flat correction array [u0, v0, u1, v1, ...] where (u, v) are edge endpoints. v=0xFFFFFFFF indicates a boundary correction.

decoder.reset()

Reset decoder state for next decoding cycle.

prav.required_buffer_size(width, height, depth=1) -> int

Calculate required buffer size for a decoder in bytes.

Parameters:

  • width (int): Grid width in nodes (must be > 0)
  • height (int): Grid height in nodes (must be > 0)
  • depth (int): Grid depth for 3D codes (default: 1, must be > 0)

Raises:

  • ValueError: If width, height, or depth is 0

Properties

  • decoder.width: Grid width in nodes
  • decoder.height: Grid height in nodes
  • decoder.depth: Grid depth (1 for 2D codes)
  • decoder.topology: Grid topology type

Performance

prav is built on prav-core, a zero-allocation Rust implementation optimized for real-time QEC decoding. Key features:

  • No heap allocations: Uses arena allocator from user-provided buffer
  • Deterministic timing: No garbage collection, fixed memory layout
  • Cache-optimized: 64-byte aligned blocks, Morton encoding for spatial locality
  • SWAR bit operations: Parallel bitwise operations for syndrome processing

Development

# Install development dependencies
pip install -e ".[dev]"

# Build the Rust extension
maturin develop

# Run tests
pytest tests/ -v

# Run linting
ruff check .
mypy python/prav

License

MIT OR Apache-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 Distribution

prav-0.0.1.tar.gz (210.7 kB view details)

Uploaded Source

Built Distribution

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

prav-0.0.1-cp310-cp310-manylinux_2_34_x86_64.whl (729.5 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ x86-64

File details

Details for the file prav-0.0.1.tar.gz.

File metadata

  • Download URL: prav-0.0.1.tar.gz
  • Upload date:
  • Size: 210.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.10.2

File hashes

Hashes for prav-0.0.1.tar.gz
Algorithm Hash digest
SHA256 14d01261cbf8a93a6fbb285b07a0d01c7fe146449582a42dd757c12e9850b296
MD5 d88650e876ae2fe7787509bf0bb90f68
BLAKE2b-256 f84440ce77d14299e18ef8ff25417422d3f7cecfe83ed23a76d7c8763c1830ec

See more details on using hashes here.

File details

Details for the file prav-0.0.1-cp310-cp310-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for prav-0.0.1-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 e1926381791eaab01ea6b90bfb9cc24d12c4aab6913b217ff185f2274c21b8d4
MD5 14a20ebf0f4bc801981bb4acf2440bc4
BLAKE2b-256 209256f4a0f06002d5c2f09786bfae372128d44a768eec35ac0d4e5ac42bb859

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