Skip to content

Commit

Permalink
Merge pull request #10 from QuantumSavory/cleanup0.1.1
Browse files Browse the repository at this point in the history
cleanup and removing dependencies used only in examples and documentation
  • Loading branch information
Krastanov authored Dec 16, 2023
2 parents c365e6d + e8d4cda commit 040ceaa
Show file tree
Hide file tree
Showing 13 changed files with 74 additions and 101 deletions.
12 changes: 2 additions & 10 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
name = "LDPCDecoders"
uuid = "3c486d74-64b9-4c60-8b1a-13a564e77efb"
authors = ["Krishna Praneet Gudipaty"]
version = "0.1.0"
version = "0.1.1"

[deps]
DelimitedFiles = "8bb1440f-4735-579b-a4ab-409b98df4dab"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
PyPlot = "d330b81b-6aea-500a-939a-2ce795aea3ee"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
RowEchelon = "af85af4c-bcd5-5d23-b03a-a909639aa875"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
Expand All @@ -15,14 +14,7 @@ SuiteSparseGraphBLAS = "c2e53296-7b14-11e9-1210-bddfa8111e1d"

[compat]
DelimitedFiles = "1"
PyPlot = "2"
RowEchelon = "0.2"
Statistics = "1"
SuiteSparseGraphBLAS = "0.10"
julia = "1.9"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test"]
julia = "1.9"
7 changes: 4 additions & 3 deletions src/experiments.jl → examples/experiments.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
using DelimitedFiles
using PyPlot
using LDPCDecoders

function simulate_bp(parity_check_matrix, physical_error_rates, max_trials, output_file_path)
outputs = []

for per in physical_error_rates
@info "Simulation for per: $per"
ler = syndrome_simulate(parity_check_matrix, per, max_trials)
Expand All @@ -16,7 +17,7 @@ function simulate_bp(parity_check_matrix, physical_error_rates, max_trials, out
end

function plot_per_vs_ler(file_path)

# Read data from file
data = readdlm(file_path)

Expand All @@ -35,4 +36,4 @@ function plot_per_vs_ler(file_path)
plt.ylabel("Logical error rate")
plt.show()

end
end
3 changes: 2 additions & 1 deletion src/experiments_it.jl → examples/experiments_it.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
using DelimitedFiles
using PyPlot
using LDPCDecoders

function simulate_it(parity_check_matrix, physical_error_rates, max_trials, output_file_path)
outputs = []

for per in physical_error_rates
@info "Simulation for per: $per"
ler = syndrome_it_simulate(parity_check_matrix, per, max_trials)
Expand Down
13 changes: 9 additions & 4 deletions src/LDPCDecoders.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
module LDPCDecoders

using DelimitedFiles
using LinearAlgebra
using Random
using SparseArrays
using Statistics

using RowEchelon


# Write your package code here.
export parity_to_generator
include("generator.jl")
Expand All @@ -21,10 +30,6 @@ export syndrome_simulate
include("syndrome_simulator.jl")
export syndrome_it_decode
include("syndrome_it_decoder.jl")
export simulate_bp, plot_per_vs_ler
include("experiments.jl")
export syndrome_it_simulate
include("syndrome_it_simulate.jl")
export simulate_it
include("experiments_it.jl")
end
31 changes: 14 additions & 17 deletions src/bp_decoder.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
using LinearAlgebra


# Bi-Symmetric Channel LLR (Bit flip)
function llr(bit, error_rate)
return ((-1) ^ bit) * log((1-error_rate)/error_rate)
Expand All @@ -21,7 +18,7 @@ function estimate(message_c2v, num_vs, num_cs, vllr, parity_check_matrix)
estimate[v] += message_c2v[c, v]
end
end
end
end
return estimate
end

Expand All @@ -30,28 +27,28 @@ function send_variable_message!(parity_check_matrix, message_c2v, message_v2c, n
for v in 1:num_vs
if parity_check_matrix[check, v] == 1
sum = 0

for c in 1:num_cs
if c != check && parity_check_matrix[c, v] == 1
sum += message_c2v[c, v]
sum += message_c2v[c, v]
end
end

message_v2c[check, v] = sum + vllr[v]
message_v2c[check, v] = sum + vllr[v]
end
end
end
end
end

function send_check_message!(parity_check_matrix, message_c2v, message_v2c, num_cs, num_vs)
for variable in 1:num_vs
for variable in 1:num_vs
for c in 1:num_cs
if parity_check_matrix[c, variable] == 1
if parity_check_matrix[c, variable] == 1

sum = 0
sgn = 1
for v in 1:num_vs
if parity_check_matrix[c, v] == 1 && v != variable
for v in 1:num_vs
if parity_check_matrix[c, v] == 1 && v != variable
sgn *= sign(message_v2c[c, v])
sum += phi(abs(message_v2c[c,v]))
end
Expand All @@ -67,7 +64,7 @@ function initialise_checks!(pcm, message_c2v, syndrome, num_vs, num_cs)
msg = syndrome[check]
for variable in 1:num_vs
if pcm[check, variable] == 1
message_c2v = msg
message_c2v = msg
end
end
end
Expand All @@ -76,12 +73,12 @@ end

# Belief Propagation Decoder
function bp_decode(parity_check_matrix, received_message, error_rate, max_iterations=100)

num_checks, num_bits = size(parity_check_matrix)
num_edges = sum(parity_check_matrix)

num_cs, num_vs = size(parity_check_matrix)

# Initialize messages
message_v2c = zeros(num_checks, num_bits)

Expand All @@ -90,7 +87,7 @@ function bp_decode(parity_check_matrix, received_message, error_rate, max_iterat
initialise_checks!(parity_check_matrix, message_c2v, syndrome, num_vs, num_cs)

# Intialize llr for variable nodes
vllr = llr.(received_message, error_rate)
vllr = llr.(received_message, error_rate)

# Send message from variable to check nodes
send_variable_message!(parity_check_matrix, message_c2v, message_v2c, num_checks, num_bits, vllr)
Expand All @@ -99,7 +96,7 @@ function bp_decode(parity_check_matrix, received_message, error_rate, max_iterat
local syndrome

for iter in 1:max_iterations

# Send Message from check to variable nodes
send_check_message!(parity_check_matrix, message_c2v, message_v2c, num_checks, num_bits)

Expand Down
18 changes: 7 additions & 11 deletions src/bp_simulator.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
using LinearAlgebra
using Random

function bp_simulate(parity_check_matrix, generator_matrix, error_rate, max_trials)

# Get size of parity check matrix
Expand All @@ -12,7 +9,7 @@ function bp_simulate(parity_check_matrix, generator_matrix, error_rate, max_tria
success = 0
for i in 1:max_trials
println("******************* Iteration number : ", i)

# Generate error based on error rate
message = bitrand(message_size)
println("message = ", message)
Expand All @@ -30,12 +27,12 @@ function bp_simulate(parity_check_matrix, generator_matrix, error_rate, max_tria
else
error[j] = 0
end
end
end


error = Int.(error)
println("error = ", error)
received_message = vec(code) .⊻ error
received_message = vec(code) .⊻ error
println("received message2 = ", received_message)
display(received_message)

Expand All @@ -60,13 +57,12 @@ function bp_simulate(parity_check_matrix, generator_matrix, error_rate, max_tria
# if correct
# success += 1
# end





end
println("The success rate of the decoder is ")
println(success/max_trials)


end

15 changes: 6 additions & 9 deletions src/generator.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
using LinearAlgebra
using RowEchelon

# function parity_to_generator(H::Matrix{Int})
# rank, n = size(H)
# n = size(H, 2)
Expand All @@ -19,21 +16,21 @@ function gaussjordan(X)

m, n = size(X)
P = Matrix(I, m, m)

pivot_old = 0
for j in 1:n
filter_down = X[pivot_old+1:m, j]
pivot = argmax(filter_down) + pivot_old
println("Argmax ", argmax(filter_down))


if pivot <= m && X[pivot, j] == 1
pivot_old += 1
if pivot_old != pivot
aux = X[pivot, :]
X[pivot, :] = X[pivot_old, :]
X[pivot_old, :] = aux
X[pivot_old, :] = aux

temp = P[pivot_old, :]
P[pivot, :] = P[pivot_old, :]
P[pivot_old, :] = temp
Expand All @@ -46,7 +43,7 @@ function gaussjordan(X)
end
end
end

if pivot_old == m
break
end
Expand Down Expand Up @@ -74,4 +71,4 @@ function parity_to_generator(H)
G = tQ * Y
return G

end
end
6 changes: 2 additions & 4 deletions src/parity.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using LinearAlgebra

function hamming_to_parity(rank)
num_rows = 2^rank - 1

Expand All @@ -21,8 +19,8 @@ function repetition_to_parity(distance)

for i in range(1, distance - 1)
parity[i, i] = 1
parity[i, i + 1] = 1
parity[i, i + 1] = 1
end

return parity
end
end
11 changes: 4 additions & 7 deletions src/parity_generator.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
using Random
using DelimitedFiles

"""
parity_check_matrix(n, wr, wc)
Expand All @@ -21,16 +18,16 @@ julia> H = parity_check_matrix(1000, 10, 9)
```
"""
function parity_check_matrix(n::Int, wr::Int, wc::Int)

# For a regular LDPC matrix
## wr = wc * (n / n-k)
@assert n % wr == 0

n_equations = (n * wc) ÷ wr
block_size = n_equations ÷ wc

block = zeros(Bool, block_size, n)

for i in 1:block_size
for j in ((i-1)*wr + 1):((i)*wr)
block[i,j] = 1
Expand All @@ -40,7 +37,7 @@ function parity_check_matrix(n::Int, wr::Int, wc::Int)
H = block

for i in 1:wc - 1
H = [H; block[:, shuffle(1:end)]]
H = [H; block[:, shuffle(1:end)]]
end

return H
Expand Down
10 changes: 4 additions & 6 deletions src/syndrome_decoder.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using SparseArrays

function syndrome_decode(pcm, pcmT, syndrome, max_iters, channel_probs, b2c, c2b, log_probabs, error)

# Get size of Parity check matrix
m, n = size(pcm)
rows = rowvals(pcm)
Expand Down Expand Up @@ -71,7 +69,7 @@ function syndrome_decode(pcm, pcmT, syndrome, max_iters, channel_probs, b2c, c2b
log_probabs[j] = log(1 / temp)
if temp >= 1
error[j] = 1
else
else
error[j] = 0
end

Expand All @@ -96,7 +94,7 @@ function syndrome_decode(pcm, pcmT, syndrome, max_iters, channel_probs, b2c, c2b
return error, converged
end
end

return Bool.(error), converged

end
end
Loading

2 comments on commit 040ceaa

@Krastanov
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/97229

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.1.1 -m "<description of version>" 040ceaa669a852bc2dfa0e2b1a749f0ae4c7a6f3
git push origin v0.1.1

Please sign in to comment.