Expand description
Safe Rust bindings for the vendored PyMatching decoder.
The crate exposes the current Rust surface of the workspace’s
pymatching-cxx bridge, with explicit support types for graph construction,
decoding options, and optional ecosystem adapters.
§Quick start
use ndarray::array;
use pymatching::{CheckMatrixOptions, Matching};
let check_matrix = array![[1_u8, 1, 0], [0, 1, 1]];
let matching = Matching::from_check_matrix(
check_matrix.view(),
CheckMatrixOptions::new(),
)?;
let prediction = matching.decode(array![1_u8, 0].view())?;
assert_eq!(prediction.len(), 3);§Building graphs directly
use pymatching::{EdgeData, Matching};
let mut matching = Matching::default();
matching.add_edge(0, 1, EdgeData::new(vec![0]).with_weight(2.0))?;
matching.add_boundary_edge(1, EdgeData::new(vec![1]))?;
assert!(matching.has_edge(0, 1));
assert!(matching.has_boundary_edge(1));
assert_eq!(matching.num_edges(), 2);§Decoder modes
| Mode | Construction | Single syndrome | Batch |
|---|---|---|---|
| Raw matching | Any graph | Matching::decode | Matching::decode_batch |
| Correlated matching | Stim model with correlations enabled | Matching::decode_with_options | Matching::decode_batch_with_options |
| Raw GAP | Stim model, correlations disabled | Matching::decode_gap | Matching::decode_gap_batch |
| Correlated GAP | Stim model, correlations enabled | Matching::decode_gap | Matching::decode_gap_batch |
Native correlated hard decoding is selected with
DecodeOptions::with_enable_correlations. GAP follows the construction
setting automatically and remains basis agnostic: logical cuts are inferred
from graph fault ids.
§Stim interop
Stim-backed constructors accept the safe Rust stim::Circuit and
stim::DetectorErrorModel types directly. Their C++ representation stays
private to the FFI boundary.
Modules§
- bit_
packing - Little-endian bit packing used by batch decoding.
Structs§
- Batch
Decode Result - Predictions and optional matching weights for a batch of syndromes.
- Check
Matrix Options - Controls construction of a matching graph from a binary check matrix.
- Decode
Options - Options shared by single-shot and batch matching decoders.
- Decode
Result - Prediction and optional matching weight for one syndrome.
- Edge
Data - Attributes attached to an edge in a
Matchinggraph. - Edge
Record - An edge and its endpoints returned by
Matching::edges. - GapBatch
Prediction - GAP results for a batch of syndromes.
- GapPrediction
- GAP result for one syndrome.
- Matching
- A minimum-weight perfect matching decoder and its decoding graph.
- Noise
Sample - A sampled physical-fault vector and its resulting syndrome.
Enums§
- Matching
Error - Error returned by safe matching-graph and decoder operations.
- Merge
Strategy - Policy used when an edge already exists between two endpoints.
Functions§
- upstream_
commit - Returns the pinned upstream PyMatching Git commit used by the C++ bridge.
Type Aliases§
- Matched
Detectors - Detection-event matches keyed by detector index.
- Result
- Result type used by the safe
pymatchingAPI.