-
Notifications
You must be signed in to change notification settings - Fork 68
Added BP-OTS decoder implementation in LDPCDecodersExt file #489
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 11 commits
723553b
dc22784
22ce711
0edd129
6921b45
b6b3be4
65303da
faa92f4
8627fc4
98f0c61
9f1baac
7c0fda2
0f3bea1
f1ffec7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,6 +31,89 @@ struct BitFlipDecoder <: AbstractSyndromeDecoder # TODO all these decoders have | |
| bfdecoderz | ||
| end | ||
|
|
||
| """ | ||
| BPOTSDecoder(code; errorrate=nothing, maxiter=nothing, T=9, C=2.0) | ||
|
|
||
| BP-OTS (Belief Propagation with Oscillating Trapping Sets) decoder for quantum LDPC codes. | ||
| This decoder uses oscillation tracking and biasing to escape trapping sets. | ||
|
|
||
| # Arguments | ||
| - `code`: A quantum code (e.g., Toric, Surface) | ||
| - `errorrate`: Physical error rate (depolarizing probability) | ||
| - `maxiter`: Maximum number of iterations (default: 200) | ||
| - `T`: Biasing period (default: 9) | ||
| - `C`: Bias constant (default: 2.0) | ||
|
|
||
| # Reference | ||
| Chytas et al., "Enhanced Message-Passing Decoding of Degenerate Quantum Codes | ||
| Utilizing Trapping Set Dynamics", IEEE Communications Letters, 2024 | ||
| """ | ||
|
|
||
|
||
| struct BPOTSDecoder <: AbstractSyndromeDecoder | ||
Krastanov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| original_code | ||
| H::SparseMatrixCSC{Bool,Int} | ||
| faults_matrix::Matrix{Bool} | ||
| n::Int | ||
| s::Int | ||
| k::Int | ||
| cx::Int | ||
| cz::Int | ||
| bpots_x::LDPCDecoders.BPOTSDecoder | ||
| bpots_z::LDPCDecoders.BPOTSDecoder | ||
| end | ||
|
|
||
| function BPOTSDecoder(c; errorrate=nothing, maxiter=nothing, T=9, C=2.0) | ||
|
|
||
| Hx_raw = parity_checks_x(c) | ||
| Hz_raw = parity_checks_z(c) | ||
| H_raw = parity_checks(c) | ||
|
|
||
| if H_raw isa Stabilizer | ||
| H_gf2 = stab_to_gf2(H_raw) | ||
| H = sparse(Bool.(H_gf2)) | ||
| else | ||
| H = sparse(Bool.(H_raw)) | ||
| end | ||
|
|
||
| if Hx_raw isa Stabilizer | ||
| Hx_gf2 = stab_to_gf2(Hx_raw) | ||
| Hz_gf2 = stab_to_gf2(Hz_raw) | ||
| Hx = sparse(Bool.(Hx_gf2)) | ||
| Hz = sparse(Bool.(Hz_gf2)) | ||
| else | ||
| Hx = sparse(Bool.(Hx_raw)) | ||
| Hz = sparse(Bool.(Hz_raw)) | ||
| end | ||
|
|
||
| s, n = size(H) | ||
| k = code_k(c) | ||
|
|
||
| cx = size(Hx, 1) | ||
| cz = size(Hz, 1) | ||
|
|
||
| fm = BitMatrix(ones(Bool, s, 2*n)) | ||
|
|
||
| errorrate = something(errorrate, 0.0) | ||
| maxiter = something(maxiter, 200) | ||
| bpots_x = LDPCDecoders.BPOTSDecoder(Hx, errorrate, maxiter; T=T, C=C) | ||
| bpots_z = LDPCDecoders.BPOTSDecoder(Hz, errorrate, maxiter; T=T, C=C) | ||
|
|
||
| return BPOTSDecoder(c, H, fm, n, s, k, cx, cz, bpots_x, bpots_z) | ||
| end | ||
|
|
||
| function decode(d::BPOTSDecoder, syndrome_sample::AbstractVector{Bool}) | ||
| length(syndrome_sample) == d.cx + d.cz || | ||
| throw(DimensionMismatch("Syndrome length ($(length(syndrome_sample))) does not match expected size ($(d.cx + d.cz))")) | ||
|
|
||
| row_x = @view syndrome_sample[1:d.cx] | ||
| row_z = @view syndrome_sample[d.cx+1:d.cx+d.cz] | ||
|
|
||
| guess_z, conv_z = LDPCDecoders.decode!(d.bpots_x, Vector(row_x)) | ||
| guess_x, conv_x = LDPCDecoders.decode!(d.bpots_z, Vector(row_z)) | ||
|
|
||
| return vcat(guess_x, guess_z) | ||
| end | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. repeated
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. removed this repetition |
||
|
|
||
| function BeliefPropDecoder(c; errorrate=nothing, maxiter=nothing) | ||
| Hx = parity_matrix_x(c) | ||
| Hz = parity_matrix_z(c) | ||
|
|
@@ -65,14 +148,15 @@ function BitFlipDecoder(c; errorrate=nothing, maxiter=nothing) | |
| isnothing(errorrate) || 0≤errorrate≤1 || error(lazy"BitFlipDecoder got an invalid error rate argument. `errorrate` must be in the range [0, 1].") | ||
| errorrate = isnothing(errorrate) ? 0.0 : errorrate | ||
| maxiter = isnothing(maxiter) ? n : maxiter | ||
| bfx = LDPCDecoders.BitFlipDecoder(Hx, errorrate, maxiter) | ||
Krastanov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| bfz = LDPCDecoders.BitFlipDecoder(Hz, errorrate, maxiter) | ||
| bfx = LDPCDecoders.BitFlipDecoder(Hx, errorrate, maxiter) | ||
|
Comment on lines
68
to
150
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. undo the permutation |
||
|
|
||
| return BitFlipDecoder(H, fm, n, s, k, cx, cz, bfx, bfz) | ||
| end | ||
|
|
||
| parity_checks(d::BeliefPropDecoder) = d.H | ||
| parity_checks(d::BitFlipDecoder) = d.H | ||
| parity_checks(d::BPOTSDecoder) = d.H | ||
|
|
||
| function decode(d::BeliefPropDecoder, syndrome_sample) | ||
| row_x = @view syndrome_sample[1:d.cx] | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this needs to be moved back to a weak dependency