Skip to content

Commit e24c389

Browse files
committed
add GB, HGP, and LP unit tests from lit
1 parent 9c61033 commit e24c389

File tree

3 files changed

+517
-213
lines changed

3 files changed

+517
-213
lines changed

src/utils.jl

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -286,27 +286,11 @@ end
286286
_Flint_matrix_element_to_Julia_int(x::fpMatrix, i::Int, j::Int) = ccall((:nmod_mat_get_entry,
287287
Oscar.Nemo.libflint), Int, (Ref{fpMatrix}, Int, Int), x, i - 1 , j - 1)
288288

289-
_Flint_matrix_element_to_Julia_int(x::FqMatrix, i::Int, j::Int) = ccall((:nmod_mat_get_entry,
290-
Oscar.Nemo.libflint), Int, (Ref{FqMatrix}, Int, Int), x, i - 1 , j - 1)
291-
292289
_Flint_matrix_to_Julia_int_matrix(A) = [ _Flint_matrix_element_to_Julia_int(A, i, j) for i in
293290
1:nrows(A), j in 1:ncols(A)]
294291

295-
# function _Flint_matrix_to_Julia_int_vector(A)
296-
# # (nr == 1 || nc == 1) || throw(ArgumentError("Cannot cast matrix to vector"))
297-
# return _Flint_matrix_element_to_Julia_int(A, 1, 1)
298-
# end
299292
_Flint_matrix_to_Julia_int_vector(A) = vec(_Flint_matrix_to_Julia_int_matrix(A))
300293

301-
_Flint_matrix_element_to_Julia_int(x::fpMatrix, i::Int, j::Int) = ccall((:nmod_mat_get_entry,
302-
Oscar.Nemo.libflint), Int, (Ref{fpMatrix}, Int, Int), x, i - 1 , j - 1)
303-
304-
_Flint_matrix_element_to_Julia_int(x::FqMatrix, i::Int, j::Int) = ccall((:nmod_mat_get_entry,
305-
Oscar.Nemo.libflint), Int, (Ref{FqMatrix}, Int, Int), x, i - 1 , j - 1)
306-
307-
_Flint_matrix_to_Julia_int_matrix(A) = [ _Flint_matrix_element_to_Julia_int(A, i, j) for i in
308-
1:nrows(A), j in 1:ncols(A)]
309-
310294
function _Flint_matrix_to_Julia_bit_matrix(A::CTMatrixTypes)
311295
order(base_ring(A)) == 2 || throw(DomainError(A, "Only works for binary matrices"))
312296
BitMatrix(_Flint_matrix_to_Julia_int_matrix(A))
@@ -1148,6 +1132,24 @@ function load_alist(file::String)
11481132
return mat
11491133
end
11501134

1135+
# TODO polish this and add/export
1136+
# function save_mtx(h, path, info)
1137+
# m, n = size(h)
1138+
# num_nonzero = sum(count(!=(0), h, dims=2))
1139+
# open(path, "w") do io
1140+
# write(io, "%%MatrixMarket matrix coordinate integer general\n")
1141+
# write(io, "%%$(info)")
1142+
# write(io, "\n$m $n $(num_nonzero)\n")
1143+
# for i in 1:m
1144+
# for j in 1:n
1145+
# if h[i, j] == 1
1146+
# write(io, "$i $j 1\n")
1147+
# end
1148+
# end
1149+
# end
1150+
# end
1151+
# end
1152+
11511153
#############################
11521154
# Quantum Helper Functions
11531155
#############################

test/Classical/quasi-cyclic_code_test.jl

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,86 @@
1313
v = [matrix(F, 1, 4, [1, 0, 1, 1]), matrix(F, 1, 4, [0, 0, 0, 1]), matrix(F, 1, 4, [1, 1, 1, 1]), matrix(F, 1, 4, [0, 0, 0, 0])]
1414
C2 = QuasiCyclicCode(v, 2, true)
1515
@test are_equivalent(C, C2)
16+
17+
# Quantum LDPC Codes with Almost Linear Minimum Distance
18+
# Example 1
19+
F = Oscar.Nemo.Native.GF(2)
20+
S, x = polynomial_ring(F, :x)
21+
l = 31
22+
R = ResidueRing(S, x^l - 1)
23+
A = matrix(R, 3, 5,
24+
[x, x^2, x^4, x^8, x^16,
25+
x^5, x^10, x^20, x^9, x^18,
26+
x^25, x^19, x^7, x^14, x^28])
27+
C = QuasiCyclicCode(A, true)
28+
@test length(C) == 155
29+
@test dimension(C) == 64
30+
@test index(C) == 5
31+
32+
# TODO I have the following code for something, check the papers and make tests out of them
33+
# A_tr = CodingTheory._CT_adjoint(A)
34+
# LiftedProductCode(A, A_tr)
35+
36+
37+
# Bias-Tailored Quantum LDPC Codes
38+
# Example 2.2
39+
# l = 3
40+
# R = ResidueRing(S, x^l - 1)
41+
# A = matrix(R, 2, 3, [x + x^2, 1, 0, 0, 1 + x^2, x^2])
42+
# lift(A)
43+
# weightmatrix(A)
44+
45+
# # julia> lift(A)
46+
# # [0 1 1 1 0 0 0 0 0]
47+
# # [1 0 1 0 1 0 0 0 0]
48+
# # [1 1 0 0 0 1 0 0 0]
49+
# # [0 0 0 1 1 0 0 1 0]
50+
# # [0 0 0 0 1 1 0 0 1]
51+
# # [0 0 0 1 0 1 1 0 0]
52+
# #
53+
# # julia> weightmatrix(A)
54+
# # 2×3 Matrix{Int64}:
55+
# # 2 1 0
56+
# # 0 2 1
57+
58+
# # Example 3.3
59+
# l = 13
60+
# R = ResidueRing(S, x^l - 1)
61+
# A = matrix(R, 4, 4,
62+
# [1, x^2, x^6, x,
63+
# x^12, x^5, x^12, x^5,
64+
# x^2, 1, x^9, x^5,
65+
# x^7, x^11, x^9, x])
66+
# A_tr = CodingTheory._CT_adjoint(A)
67+
# code = LiftedQuasiCyclicLiftedProductCode(A, A_tr)
68+
69+
# # TODO should remove from classical but put where?
70+
# # TODO this example was never finished because of the original paper? or is wrong?
71+
# # Quasi-cyclic constructions of quantum codes
72+
# # Example 1
73+
# n = 151
74+
# q = 2
75+
# deg = ord(n, q)
76+
# E = GF(2, 15, :α)
77+
# S, x = polynomial_ring(E, :x)
78+
# β = α^(div(q^deg - 1, n))
79+
# def_set_f = cyclotomic_coset(2, q, n)
80+
# f = CodingTheory._generator_polynomial(S, β, def_set_f)
81+
# def_set_g = [def_set_f; cyclotomic_coset(10, q, n)]
82+
# g = CodingTheory._generator_polynomial(S, β, def_set_g)
83+
# h = x + 1
84+
# R, _ = residue_ring(S, x^n - 1)
85+
# G1 = CodingTheory._generator_matrix(E, n, n - length(def_set_f), f);
86+
# G3 = CodingTheory._generator_matrix(E, n, n - length(def_set_f) - 1, f * h);
87+
# G2 = CodingTheory._generator_matrix(E, n, n - length(def_set_g), g);
88+
# # G1 = polytocircmatrix(R(f));
89+
# # G3 = polytocircmatrix(R(f * h));
90+
# # G2 = polytocircmatrix(R(g));
91+
# # cannot concatenate G1 and G3, although in the paper G1 and G2 are defined
92+
# # but G3 is never actually specified
93+
# stabs = vcat(hcat(G1, G3), hcat(zero(G2), G2))
94+
# Q = QuantumCode(change_base_ring(F, stabs), true)
95+
# # @test length(Q) ==
96+
# # @test dimension(Q) ==
1697
end
1798
end

0 commit comments

Comments
 (0)