-
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 2 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 |
|---|---|---|
|
|
@@ -30,6 +30,91 @@ struct BitFlipDecoder <: AbstractSyndromeDecoder # TODO all these decoders have | |
| bfdecoderz | ||
| end | ||
|
|
||
| struct BPOTSDecoder <: AbstractSyndromeDecoder | ||
| 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) | ||
| # Get stabilizer matrices | ||
| Hx_raw = parity_checks_x(c) | ||
| Hz_raw = parity_checks_z(c) | ||
| H_raw = parity_checks(c) | ||
|
|
||
| # Convert to proper matrices | ||
| if H_raw isa Stabilizer | ||
| H_gf2 = stab_to_gf2(H_raw) | ||
| H = sparse(Bool.(H_gf2)) | ||
| else | ||
| H = sparse(Bool.(H_raw)) | ||
| end | ||
|
|
||
| # Convert X and Z matrices | ||
| 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 | ||
|
|
||
| # Get dimensions | ||
| s, n = size(H) | ||
|
|
||
| # For quantum codes, determine k | ||
| if c isa Toric || c isa Surface | ||
| k = c isa Toric ? 2 : 1 | ||
| else | ||
| k = n - s | ||
| end | ||
|
||
|
|
||
| cx = size(Hx, 1) | ||
| cz = size(Hz, 1) | ||
|
|
||
| # Create fault matrix | ||
| fm = BitMatrix(ones(Bool, s, 2*n)) | ||
|
|
||
| # Create decoders | ||
| 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) | ||
|
|
||
| # Pass the original code object as the first parameter | ||
| return BPOTSDecoder(c, H, fm, n, s, k, cx, cz, bpots_x, bpots_z) | ||
| end | ||
|
|
||
| function decode(d::BPOTSDecoder, syndrome_sample::AbstractVector{Bool}) | ||
| # Validate input size | ||
|
||
| length(syndrome_sample) == d.cx + d.cz || | ||
| throw(DimensionMismatch("Syndrome length ($(length(syndrome_sample))) does not match expected size ($(d.cx + d.cz))")) | ||
|
|
||
| # Split syndrome | ||
| row_x = @view syndrome_sample[1:d.cx] | ||
| row_z = @view syndrome_sample[d.cx+1:d.cx+d.cz] | ||
|
|
||
| # Decode both parts | ||
| 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 combined X and Z errors | ||
| return vcat(guess_x, guess_z) | ||
| end | ||
|
|
||
| function parity_checks(d::BPOTSDecoder) | ||
| return d.H | ||
| 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_checks_x(c) | ||
| Hz = parity_checks_z(c) | ||
|
|
@@ -64,7 +149,6 @@ 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) | ||
|
|
||
| return BitFlipDecoder(H, fm, n, s, k, cx, cz, bfx, bfz) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.