A Belief-Propagation Decoder in Rust

2026-08-25

To get started with qLDPC, we need a good decoder as a base. It should be simple and easily extendable. I have written many classical Belief-Propagation (BP) decoders in Matlab, C, and C++. For this task, we write a new one from scratch, and use the Rust programming language.

Rust is more than just a good programming language. It comes with its own philosophy, focusing on the ownership concept and bringing cargo, its own build system and dependency tracker. Our BP decoder is called ldpc_dec and can be found on GitHub. It has full functionality of a classical belief-propagation decoder and will be the basis for future extensions.

One particularly nice feature of the Rust programming language is the explicit declaration of mutability in function calls. The screenshot below is from node_math.rs, which implements normalized multiplication and the gallager product function. These are the math primitives used at variable nodes and check nodes, respectively. Note that all variables are passed to the function by reference, as we can see from the ampersand symbols. However, not all of them carry the qualifier mut, which signals mutability. The input values f0 are not mutable, while the to-be-calculated variable result is. In other words, Rust features immutability-by-default, and we need to actively declare mutability for each variable if we need it. The compiler supports this with compile-time checks. Immutability-by-default is part of Rust's bigger ownership and borrowing philosophy.

Screenshot of node_math.rs (GitHub)
Function call to gallager product in node_math.rs.

Feel free to pull ldpc_dec and try it for classical LDPC codes. For a quick simulation, a random LDPC code with variable-node degree 3 and check-node degree 6 is included, along with a channel model for AWGN. To build and run, invoke cargo run.