Tanner Graph and Belief Propagation background
Decoding problem statement
A decoding problem is specified by:
a parity check matrix \(H \in \mathbb{F}_2^{M \times N}\)
an encoded logical action matrix \(A \in \mathbb{F}_2^{K \times N}\)
a prior error probability vector \(p = (p_0, \dots, p_{N-1})\) where error location \(j\) is assumed to fail independently with probability \(p_j\).
Let \(e \in \mathbb{F}_2^N\) denote unknown binary faults in the chosen model, and let \(\sigma \in \mathbb{F}_2^M\) be the observed syndrome:
The decoding task is to infer a correction \(\hat{e}\) that reproduces the syndrome and preserves the equivalence class of the encoded logical operator:
For a CSS code, one can decode the X-error component using Z-check detectors and the Z-error component using X-check detectors. The BB144 benchmark measures only the Z-check sector. Circuit-level physical errors can correlate the two components; evaluating one sector does not establish a combined XZ failure rate. In a circuit-level model, columns of \(H\) are fault signatures rather than data qubits.
From an assumed noise model, it is useful to construct independent binary variable priors \(0 < p_j < 1\) defined via \(\Pr(e_j=1)=p_j\). One can associate to each bit a log-likelihood weight \(\omega_j = \log \frac{1-p_j}{p_j}\). The decoding problem of interest is to find the bit-wise maximum a posteriori (MAP) estimate that satisfies the syndrome.
Bit-wise MAP decoding
The independent-fault prior distribution is
The probability of obtaining a candidate error \(\mathbf e\), is obtained by conditioning this probability distribution on the measured syndrome
Here, conditioning is formally represented using Iverson notation, \([P]\) is one if \(P\) is true and zero otherwise. \(H_i\) denotes row (stabilizer check) \(i\). Formally, \(Z(\mathbf \sigma)\) denotes the normalization of the posterior distribution, for a given syndrome \(\sigma\). To compute the probability of an error bit-wise using this posterior distribution, we need to compute bit marginal sums over the other \(N-1\) components. The probability that the \(j\)th error bit is \(b\) is obtained by summing all components of \(e\) except for \(j\):
To compute the bit-wise MAP estimate, this marginalization needs to be done for all \(N\) components of the error, and each probability maximized.
BP (Belief Propagation)
A direct evaluation of a single marginal requires a sum over \(2^{N-1}\) assignments. An efficient algorithm for marginalization is belief propagation, which is performed on the Tanner graph associated with \(H\). The Tanner graph \(G=(V,E)\) is a bipartite graph with the two types of nodes being the variable nodes which index columns of \(H\) and check nodes which index rows of \(H\). An edge exists whenever \(H_{ij}=1\).
Belief propagation involves iterative message passing between check and variable nodes where each round computes a marginalization of variable nodes based on the previous rounds priors. BP is particularly an important technique for real-time decoding as it lends itself to parallelization. In the maximally parallel (flooding schedule), all the message passing in a single iteration can be performed in just \(2\) clock cycles.
Local message passing and quantization
A Tanner graph exposes the local priors and parity constraints in (2), allowing information to pass along edges. Sum-product BP computes exact marginals on a tree and is generally approximate on a graph with loops [1]. chipsLDPC implements scaled, quantized min-sum, which approximates the sum-product check update. The log-likelihood ratio (LLR) convention is
Larger absolute values express stronger confidence. The hardware represents min-sum soft values as integers; hard decisions are computed via
Prior conversion. Logarithms are evaluated before the RTL. For each DEM
probability \(0<p_j<1/2\), the BB144 helper
quantize computes
Here \(\log\) is the natural logarithm. The conversion rounds to the nearest
integer, with half ties rounded up, then saturates.
The current Python constants set
\(c=2\) and \(w_m=4\), so priors lie in \([0,15]\).
StaticDecoderInput.prior
is unsigned and cannot carry a negative prior LLR.
Message representation.
Quantization(magnitudeBits, accumulatorBits)
sets \(w_m\) magnitude bits and \(w_a\) signed marginal bits, with \(w_a\geq w_m+1\).
SignMag adds a separate sign
bit: edge-message values range from \(-(2^{w_m}-1)\) to \(2^{w_m}-1\).
VariableLogic.apply
uses a wider working sum, clips the stored marginal to
\([-2^{w_a-1},2^{w_a-1}-1]\), and clips outgoing extrinsic magnitudes to
\(2^{w_m}-1\). Recipient subtraction and the strict-negative hard decision happen
before marginal clipping; zero selects no correction. Shift-based check scaling
in Arithmetic.scale
truncates each shifted term. See the RTL arithmetic contract
for the exact storage boundaries.
Selecting a format. Pass q = Quantization(magnitudeBits = ..., accumulatorBits = ...)
to VanillaBpConfig or
RelayBpConfig.
Their defaults are (4, 7) and (4, 5), respectively. Widths are fixed at
elaboration, so changing them requires rebuilding the RTL. Select scale
separately: overriding q does not change the default check-scaling policy.
For BB144, PRIOR_BITS and PRIOR_SCALE are source constants, not CLI options;
changing them requires regenerating the prepared priors and keeping the
Scala experiment profile, reported prior scale, and
prior-range validation
consistent with the selected settings.
A larger \(c\) gives finer LLR steps but reaches saturation sooner at fixed width; different noise priors, graph degrees, Relay memory, or FPGA area/timing budgets can therefore justify different scales and widths, checked against decoding failure rates and hardware cost.
Check \(i\) and variable \(j\) share an edge. The two arrows on that edge show opposite message directions. Other neighbors provide the inputs used when the recipient is excluded. This is an illustrative neighborhood, not a complete code graph.
In the figure, \(H_{ij}=1\) gives one Tanner edge carrying two directed messages. Check \(i\) sees variable \(j\) in its neighbourhood \(\mathcal N(i)\); variable \(j\) sees check \(i\) in \(\mathcal N(j)=\{i:H_{ij}=1\}\). \(i\) is a check and \(j\) is a variable. The superscript \(t\) counts completed iterations: \(t=0\) is initialization, and the first update has \(t=1\). A Tanner graph has a square check node per row of \(H\), a circular variable node per column. We outline below the quantaties necessary to define the message passing rules on a Tanner Graph that has been constructed from the parity check matrix coming from a stim Detector Error Model (DEM):
Symbol |
Meaning |
Implementation |
|---|---|---|
\(\mathbf \sigma\), \(\mathbf \sigma_i\) |
Measured syndrome vector and it’s \(i\)th check bit |
|
\(R_{i,j}^{(t)}\) |
Variable \(j\) to check \(i\) message at round \(t\) |
|
\(\sigma_{i,j}^{(t)}\) |
Signed check \(i\) to variable \(j\) message; distinct from the bold syndrome |
|
\(\Lambda_j\), \(\lambda_j\) |
Real prior Log-liklihood ratio (LLR), its quantized unsigned magnitude |
|
\(B_j^{(t)}\) |
Bias term applied during variable update |
|
\(M_j^{(t)}\) |
Min-sum soft value, called the marginal; saturated before storage in RTL |
|
\(T_j^{(t)}\) |
Full-width total before storage saturation |
Local |
\(g_t\) |
Scaling factor for check-magnitude |
|
\(\hat e_j^{(t)}\) |
Hard decision |
|
The graph and ports are derived by TannerGraph.fromRows and TannerNodeGraphs.from.
The resulting TannerNodeGraphs.connections supplies the check/variable port map used by StaticTannerCore.
BpDecoderResult distinguishes the selected correction from the final marginal (for RelayBP these can belong
to different legs, see result semantics).
TannerConnection
records these endpoints as checkId and variableId. Its checkPort and
variablePort are the positions of that edge in the two nodes’ local vectors.
For example, variableId selects a variable node, whereas variablePort selects
one of that node’s incident edges. The two port numbers need not be equal.
TannerNodeGraphs.connections
matches these local views using their common edgeId.
The connection loop in StaticTannerCore
then wires variable.result.extrinsic(edge.variablePort) to
check.input(edge.checkPort), carrying \(R_{i,j}\). In the other direction, it
connects the check’s shared minimum pair and that edge’s sign and useSecond
fields to variable.input(edge.variablePort).
VariableLogic.apply
selects a magnitude and interprets its sign to recover \(\sigma_{i,j}\).
The graph records are ordinary Scala elaboration data: the loop constructs
fixed Chisel wiring, and successive iterations update the messages over those
same connections.
The three min-sum updates
In the case of Belief Propagation (or vanilla BP), we initialize the messages \(R_{i,j}^{(0)}=\Lambda_j\).
StaticVariableStage initializes each hardware edge from the unsigned input \(\lambda_j\) with sign
zero. One flooding iteration updates all checks from the old variable messages, then updates all variables. In the following update rules,
\(g_t\) is the check-scaling policy and \(B_j^{(t)}\) is the bias. These equations expose message dependencies, the important task of
specifing their finite-width realization for Hardware is in BP architecture’s RTL arithmetic contract.
Check to variable: combine the syndrome bit and the other incoming signs, then take the smallest other magnitude.
CheckNode forms the sign from a shared XOR parity, selects a minimum from
TwoMinLogic.apply, and calls Arithmetic.scale.
Variable to check: add the bias and message from every check except the recipient.
VariableLogic.apply implements this by forming one full-width total and subtracting the recipient’s incoming message.
Marginal: include every adjacent check for the hard decision.
The same VariableLogic.applycalls Arithmetic.sum to compute this total.
Vanilla BP uses \(B_j^{(t)}=\Lambda_j\) in the ideal equations;
VanillaBpDecoder wires the
quantized stored prior to core.io.bias. RelayBpDecoder
instead calls RelayBias.apply
with the previous iteration’s stored marginal. The Relay architecture
describes its rounding and memory carried between legs. Both use the same
static BP datapath.
Roffe et al. discuss min-sum BP in the quantum LDPC decoding setting [2].
Consider the check-to-variable arrow \(i\to j\) in the figure. At iteration \(t\),
check \(i\) uses \(R_{i,j'}^{(t-1)}\) and \(R_{i,j''}^{(t-1)}\) from the other two
variables. Their signs, together with the syndrome bit \(\boldsymbol\sigma_i\),
set the outgoing sign. Min-sum takes the smaller of their magnitudes as the
check’s confidence, then applies \(g_t\) to obtain the outgoing magnitude.
A zero magnitude carries no preference between \(e_j=0\) and \(e_j=1\).
The shared parity, minimum pair and per-edge selectors in
CheckNode
implement this exclusion of the recipient’s own message.
For the reverse arrow \(j\to i\), variable \(j\) combines its bias \(B_j^{(t)}\) with
the current messages \(\sigma_{i',j}^{(t)}\) and \(\sigma_{i'',j}^{(t)}\).
Its full total also includes \(\sigma_{i,j}^{(t)}\), which contributes to the hard
decision. To send a message back to \(i\),
VariableLogic.apply
subtracts that check’s contribution from the full total before packing the
outgoing sign and magnitude. Excluding the recipient in both directions avoids
immediately returning its own evidence as new information; correlations can
still return through longer loops in the graph.
The scaling policy controls the magnitude of the check’s contribution relative
to the variable bias; the parity calculation determines its sign separately.
Arithmetic.scale
implements three choices for an unsigned magnitude \(a\):
NoScalepasses \(a\) through unchanged.VallsScale(r, s)addsa >> randa >> s, then clips the sum to the configured magnitude width. Each shift truncates separately.RampScale(k)computesa - (a >> u)for a supplied control \(0\leq u\leq k\), and passes \(a\) through for \(u>k\). With increasing \(u\), less is subtracted; the autonomous controllers start at \(u=1\).
For the shifted policies, truncation happens before addition or subtraction. Replacing these operations with a real-valued scaling followed by one rounding step can therefore change the outgoing message. The BP architecture gives the exact scaling schedule and the RTL arithmetic contract describes how the variable update stores and clips the resulting values.
References
F. R. Kschischang, B. J. Frey, and H.-A. Loeliger, Factor graphs and the sum-product algorithm, IEEE Transactions on Information Theory 47, 498–519 (2001).
J. Roffe, D. R. White, S. Burton, and E. Campbell, Decoding across the quantum low-density parity-check code landscape, Physical Review Research 2, 043423 (2020).