Skip to content

Commit

Permalink
bump LDPCDecoders
Browse files Browse the repository at this point in the history
  • Loading branch information
Krastanov committed Mar 6, 2024
1 parent 47d204b commit 5b725d5
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 56 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

# News

## v0.8.21 - 2024-03-05

- Bump the `LDPCDecoders` dependency.

## v0.8.20 - 2024-01-22

- Significant additions to the `ECC` submodule, with constructors for a few new codes (`Toric` and generic `CSS`); incorporating many syndrome decoding algorithms (thanks to the `PyQDecoders.jl` and `LDPCDecoders.jl` packages); and providing a convenient API for evaluating code performance in different settings through the new `evaluate_decoder` function.
Expand Down
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "QuantumClifford"
uuid = "0525e862-1e90-11e9-3e4d-1b39d7109de1"
authors = ["Stefan Krastanov <[email protected]>"]
version = "0.8.20"
version = "0.8.21"

[deps]
Combinatorics = "861a8166-3701-5b0c-9a16-15d98fcdc6aa"
Expand Down Expand Up @@ -49,7 +49,7 @@ Graphs = "1.9"
HostCPUFeatures = "0.1.6"
ILog2 = "0.2.3"
InteractiveUtils = "1.9"
LDPCDecoders = "0.1.1"
LDPCDecoders = "0.3"
LinearAlgebra = "1.9"
MacroTools = "0.5.9"
Makie = "0.20"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,34 +17,14 @@ struct BeliefPropDecoder <: AbstractSyndromeDecoder
s
"""The number of encoded qubits"""
k
"""Empty array to hold temporary values in belief decoding"""
log_probabs
"""Error probabilities of each channel"""
channel_probs
"""Number of X checks, used to get the syndrome corresponding to the X checks"""
numchecks_X
"""Empty matrix used to hold error probabilities for the X channels"""
b2c_X
"""Empty matrix used to temporary belief propagation values"""
c2b_X
"""Number of X checks, used to get the syndrome corresponding to the X checks"""
numchecks_Z
"""Empty matrix used to hold error probabilities for the Z channels"""
b2c_Z
"""Empty matrix used to temporary belief propagation values"""
c2b_Z
"""The measured error syndrome"""
err
"""Sparse array of Cx matrix"""
sparse_Cx
"""Sparse array of the transpose of the Cx matrix"""
sparse_CxT
"""Sparse array of Cz matrix"""
sparse_Cz
"""Sparse array of the transpose of the Cx matrix"""
sparse_CzT
"""Maximum number of iterations before giving up"""
max_iters
"""Number of X checks"""
cx
"""Number of X checks"""
cz
"""The classical BP decoder for Hx"""
bpdecoderx
"""The classical BP decoder for Hz"""
bpdecoderz
end

function BeliefPropDecoder(c, p_init=0, max_iters=10)
Expand All @@ -54,35 +34,28 @@ function BeliefPropDecoder(c, p_init=0, max_iters=10)
s, n = size(H)
_, _, r = canonicalize!(Base.copy(H), ranks=true)
k = n - r
cx = size(Hx, 1)
cz = size(Hx, 1)
fm = faults_matrix(H)
log_probabs = zeros(n)
channel_probs = fill(p_init, n)

numchecks_X = size(Hx, 1)
b2c_X = zeros(numchecks_X, n)
c2b_X = zeros(numchecks_X, n)
bpx = LDPCDecoders.BeliefPropagationDecoder(Hx, p_init, max_iters)
bpz = LDPCDecoders.BeliefPropagationDecoder(Hz, p_init, max_iters)

numchecks_Z = size(Hz, 1)
b2c_Z = zeros(numchecks_Z, n)
c2b_Z = zeros(numchecks_Z, n)
err = zeros(n)

sparse_Cx = sparse(Hx)
sparse_CxT = sparse(Hx')
sparse_Cz = sparse(Hz)
sparse_CzT = sparse(Hz')
return BeliefPropDecoder(H, fm, n, s, k, log_probabs, channel_probs, numchecks_X, b2c_X, c2b_X, numchecks_Z, b2c_Z, c2b_Z, err, sparse_Cx, sparse_CxT, sparse_Cz, sparse_CzT, max_iters)
return BeliefPropDecoder(H, fm, n, s, k, cx, cz, bpx, bpz)
end

parity_checks(d::BeliefPropDecoder) = d.H

function decode(d::BeliefPropDecoder, syndrome_sample)
row_x = syndrome_sample[1:d.numchecks_X]
row_z = syndrome_sample[d.numchecks_X+1:d.numchecks_X+d.numchecks_Z]
row_x = syndrome_sample[1:d.cx]
row_z = syndrome_sample[d.cx+1:d.cx+d.cz]

guess_x = falses(d.n)
guess_z = falses(d.n)

KguessX, success = LDPCDecoders.syndrome_decode(d.sparse_Cx, d.sparse_CxT, row_x, d.max_iters, d.channel_probs, d.b2c_X, d.c2b_X, d.log_probabs, Base.copy(d.err))
KguessZ, success = LDPCDecoders.syndrome_decode(d.sparse_Cz, d.sparse_CzT, row_z, d.max_iters, d.channel_probs, d.b2c_Z, d.c2b_Z, d.log_probabs, Base.copy(d.err))
guess = vcat(KguessZ, KguessX)
success = LDPCDecoders.decode!(d.bpx, row_x, guess_x)
success = LDPCDecoders.decode!(d.bpz, row_z, guess_z)
return vcat(guess_z, guess_x)
end

end
1 change: 0 additions & 1 deletion test/.env

This file was deleted.

1 change: 0 additions & 1 deletion test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ Combinatorics = "861a8166-3701-5b0c-9a16-15d98fcdc6aa"
Conda = "8f4d0f93-b110-5947-807f-2305c1781a2d"
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
DotEnv = "4dc1fcf4-5e3b-5448-94ab-0c38ec0385c1"
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
HostCPUFeatures = "3e5b6fbb-0976-4d2c-9146-d79de83f2fb0"
ILog2 = "2cd5bd5f-40a1-5050-9e10-fc8cdb6109f5"
Expand Down
5 changes: 1 addition & 4 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
using SafeTestsets
using QuantumClifford
using DotEnv

DotEnv.config(path = ".env")

function doset(descr)
if length(ARGS) == 0
Expand Down Expand Up @@ -30,7 +27,7 @@ println("Starting tests with $(Threads.nthreads()) threads out of `Sys.CPU_THREA
println("ENV[\"PYTHON\"] = \"$(get(ENV,"PYTHON",nothing))\"")

# in order to run the gpu tests automatically set GPU_TESTS to true in the .env file
if ENV["GPU_TESTS"] == "true"
if get(ENV, "GPU_TESTS", "") == "true"
@doset "gpu"
else
println("skipping gpu tests (set GPU_TESTS=true to test gpu)")
Expand Down

0 comments on commit 5b725d5

Please sign in to comment.