Skip to content

Commit 84d687b

Browse files
authored
Merge branch 'dev' into dev
2 parents df90763 + 292450c commit 84d687b

File tree

4 files changed

+640
-214
lines changed

4 files changed

+640
-214
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
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
# misc codes from the literature
2+
@testitem "Quantum/misc_lit_codes.jl" begin
3+
using Oscar
4+
using CodingTheory
5+
6+
@testset "Misc Codes From Literature" begin
7+
# TODO codes from "LRESC" paper, make tests (long range _ surface code?)
8+
# # the dual of any [3, 2, 2] code is a [3, 1, 3] repetition code
9+
# # but we'll build this the GAP way anyway
10+
# C_GAP = GAP.Globals.BestKnownLinearCode(3, 2, GAP.Globals.GF(2));
11+
# G = GAP.Globals.GeneratorMat(C_GAP);
12+
# y = [GAP.Globals.Int(G[i, j]) for i in 1:2, j in 1:3];
13+
# C32 = LinearCode(y, 2);
14+
# R4 = RepetitionCode(2, 4);
15+
# seed1 = concatenate(C32, R4)
16+
# LRESC1 = HypergraphProductCode(parity_check_matrix(seed1), parity_check_matrix(seed1))
17+
18+
# # unclear as to which [6, 2, 4] code they used here
19+
# C_GAP = GAP.Globals.BestKnownLinearCode(6, 2, GAP.Globals.GF(2));
20+
# G = GAP.Globals.GeneratorMat(C_GAP);
21+
# y = [GAP.Globals.Int(G[i, j]) for i in 1:2, j in 1:6];
22+
# C62 = LinearCode(y, 2)
23+
# R2 = RepetitionCode(2, 2);
24+
# seed2 = concatenate(C62, R2)
25+
# LRESC2 = HypergraphProductCode(parity_check_matrix(seed2), parity_check_matrix(seed2))
26+
27+
# # they either could have used this code or the extended Hamming code below
28+
# C_GAP = GAP.Globals.BestKnownLinearCode(8, 4, GAP.Globals.GF(2));
29+
# G = GAP.Globals.GeneratorMat(C_GAP);
30+
# y = [GAP.Globals.Int(G[i, j]) for i in 1:4, j in 1:8];
31+
# C84 = LinearCode(y, 2)
32+
# R3 = RepetitionCode(2, 3);
33+
# seed3 = concatenate(C84, R3)
34+
# LRESC3 = HypergraphProductCode(parity_check_matrix(seed3), parity_check_matrix(seed3))
35+
36+
# ext_Ham = extend(HammingCode(2, 3))
37+
# seed3_alt = concatenate(ext_Ham, R3)
38+
# LRESC3_alt = HypergraphProductCode(parity_check_matrix(seed3_alt), parity_check_matrix(seed3_alt))
39+
40+
# julia> are_permutation_equivalent(C84, ext_Ham)
41+
# (false, missing)
42+
43+
44+
45+
46+
47+
# radial codes
48+
# using StatsBase, Graphs, Oscar, CodingTheory
49+
# F = Oscar.Nemo.Native.GF(2)
50+
# S, x = polynomial_ring(F, :x)
51+
# l = 5
52+
# R, _ = residue_ring(S, x^l - 1)
53+
# A1 = matrix(R, 3, 3,
54+
# [x^3, x^2, x,
55+
# x^4, x^1, x^4,
56+
# x, x^2, x^3])
57+
# A2 = matrix(R, 3, 3,
58+
# [x^3, x^3, 1,
59+
# x, 1, x,
60+
# x^4, x^2, 1])
61+
# code = LiftedProductCode(A1, A2)
62+
# # [[90, 8]]_2 CSS stabilizer code
63+
# # julia> check_weights(code)
64+
# # (w_X, q_X, w_Z, q_Z) = (6, 3, 6, 3)
65+
# L_X = LDPCCode(code.X_stabs);
66+
# G_X, _, _ = Tanner_graph(L_X);
67+
# D_X = DiGraph(G_X);
68+
# L_X_cycles = CodingTheory._modified_hawick_james(D_X, 12);
69+
# countmap(length.(L_X_cycles))
70+
# # Dict{Int64, Int64} with 3 entries:
71+
# # 6 => 48
72+
# # 10 => 4842
73+
# # 8 => 777
74+
# L_Z = LDPCCode(code.Z_stabs);
75+
# G_Z, _, _ = Tanner_graph(L_Z);
76+
# D_Z = DiGraph(G_Z);
77+
# L_Z_cycles = CodingTheory._modified_hawick_james(D_Z, 12);
78+
# countmap(length.(L_Z_cycles))
79+
# # Dict{Int64, Int64} with 3 entries:
80+
# # 6 => 20
81+
# # 10 => 4074
82+
# # 8 => 678
83+
84+
# l = 11
85+
# R, _ = residue_ring(S, x^l - 1)
86+
# A1 = matrix(R, 4, 4,
87+
# [x^10, x^10, x, x^6,
88+
# x^4, x^7, x^5, x^2,
89+
# x^8, x^10, x^6, x^9,
90+
# x, x^6, 1, x^6])
91+
# A2 = matrix(R, 4, 4,
92+
# [x^9, x^5, x^8, x^3,
93+
# x^5, x^4, x, 1,
94+
# 1, x^4, x^6, x^10,
95+
# x^2, x^8, x^4, x^2])
96+
# code = LiftedProductCode(A1, A2)
97+
# # [[352, 18]]_2 CSS stabilizer code
98+
# # julia> check_weights(code)
99+
# # (w_X, q_X, w_Z, q_Z) = (8, 4, 8, 4)
100+
# L_X = LDPCCode(code.X_stabs);
101+
# G_X, _, _ = Tanner_graph(L_X);
102+
# D_X = DiGraph(G_X);
103+
# L_X_cycles = CodingTheory._modified_hawick_james(D_X, 12);
104+
# countmap(length.(L_X_cycles))
105+
# # Dict{Int64, Int64} with 3 entries:
106+
# # 6 => 96
107+
# # 10 => 61668
108+
# # 8 => 3970
109+
# L_Z = LDPCCode(code.Z_stabs);
110+
# G_Z, _, _ = Tanner_graph(L_Z);
111+
# D_Z = DiGraph(G_Z);
112+
# L_Z_cycles = CodingTheory._modified_hawick_james(D_Z, 12);
113+
# countmap(length.(L_Z_cycles))
114+
# # Dict{Int64, Int64} with 3 entries:
115+
# # 6 => 72
116+
# # 10 => 60787
117+
# # 8 => 3954
118+
end
119+
end

0 commit comments

Comments
 (0)