Skip to content

Commit 9e7879d

Browse files
authored
add a commutativity check to the LPCode constructor (#535)
* add a commutativity check to the LPCode constructor * update docstrings for failing codes
1 parent 191455b commit 9e7879d

File tree

3 files changed

+26
-21
lines changed

3 files changed

+26
-21
lines changed

ext/QuantumCliffordHeckeExt/lifted_product.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,17 @@ struct LPCode <: AbstractECC
104104

105105
function LPCode(A::GroupAlgebraElemMatrix, B::GroupAlgebraElemMatrix; GA::GroupAlgebra=parent(A[1,1]), repr::Function)
106106
all(elem.parent == GA for elem in A) && all(elem.parent == GA for elem in B) || error("The base rings of all elements in both matrices must be the same as the group algebra")
107-
new(A, B, GA, repr)
107+
code = new(A, B, GA, repr)
108+
QuantumClifford.check_allrowscommute(parity_checks(code)) || error("The Lifted Product Code just created is invalid -- its rows do not commute. This is either a bug in this library, or a non-commutative group algebra was used.")
109+
code
108110
end
109111

110112
function LPCode(c₁::LiftedCode, c₂::LiftedCode; GA::GroupAlgebra=c₁.GA, repr::Function=c₁.repr)
111113
# we are using the group algebra and the representation function of the first lifted code
112114
c₁.GA == GA && c₂.GA == GA || error("The base rings of both lifted codes must be the same as the group algebra")
113-
new(c₁.A, c₂.A, GA, repr)
115+
code = new(c₁.A, c₂.A, GA, repr)
116+
QuantumClifford.check_allrowscommute(parity_checks(code)) || error("The Lifted Product Code just created is invalid -- its rows do not commute. This is either a bug in this library, or a non-commutative group algebra was used.")
117+
code
114118
end
115119
end
116120

ext/QuantumCliffordOscarExt/group_presentation.jl

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ See also: [`two_block_group_algebra_codes`](@ref), [`twobga_from_direct_product`
3333
The [[96, 12, 10]] 2BGA code from Table I in [lin2024quantum](@cite) has the group presentation
3434
`⟨r, s | s⁶ = r⁸ = r⁻¹srs = 1⟩` (the group `C₂ × (C₃ ⋉ C₈)`).
3535
36+
Currently unsupported as it requires a non-commutative group algebra.
37+
3638
```jldoctest finitegrp
3739
julia> import Oscar: free_group, small_group_identification, describe, order
3840
@@ -55,15 +57,8 @@ julia> a = [one(G), r, s^3 * r^2, s^2 * r^3];
5557
julia> b = [one(G), r, s^4 * r^6, s^5 * r^3];
5658
5759
julia> c = twobga_from_fp_group(a, b, GA);
58-
59-
julia> order(G)
60-
48
61-
62-
julia> code_n(c), code_k(c)
63-
(96, 12)
64-
65-
julia> describe(G), small_group_identification(G)
66-
("C2 x (C3 : C8)", (48, 9))
60+
ERROR: The CSS code just created is invalid -- its rows do not commute. This is either a bug in this library, or an inconsistent parity check matrices were provided to the CSS constructor.
61+
[...]
6762
```
6863
6964
### Cyclic Groups
@@ -111,6 +106,8 @@ where the order is `2m`.
111106
The [[24, 8, 3]] 2BGA code from Appendix C, Table III in [lin2024quantum](@cite) is constructed
112107
by specifying a group presentation below (giving the group `D₆ = C₆ ⋉ C₂`).
113108
109+
Currently unsupported as it requires a non-commutative group algebra.
110+
114111
```jldoctest finitegrp
115112
julia> m = 6;
116113
@@ -129,15 +126,8 @@ julia> a = [one(G), r^4];
129126
julia> b = [one(G), s*r^4, r^3, r^4, s*r^2, r];
130127
131128
julia> c = twobga_from_fp_group(a, b, GA);
132-
133-
julia> order(G)
134-
12
135-
136-
julia> code_n(c), code_k(c)
137-
(24, 8)
138-
139-
julia> describe(G), small_group_identification(G)
140-
("D12", (12, 4))
129+
ERROR: The CSS code just created is invalid -- its rows do not commute. This is either a bug in this library, or an inconsistent parity check matrices were provided to the CSS constructor.
130+
[...]
141131
```
142132
143133
!!! note

lib/QECCore/src/codes/css.jl

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,21 @@ struct CSS <: AbstractCSSCode
1515
n = size(Hx, 2)
1616
if n != size(Hz, 2) error("When constructing a CSS quantum code, the two classical codes are required to have the same block size") end
1717
#if size(Hx,1)+size(Hz,1) >= n error("When constructing a CSS quantum code, the total number of checks (rows) in the parity checks of the two classical codes have to be lower than the block size (the number of columns).") end
18+
check_allrowscommute(Hx, Hz) || error("The CSS code just created is invalid -- its rows do not commute. This is either a bug in this library, or an inconsistent parity check matrices were provided to the CSS constructor.")
1819
new(Hx, Hz)
1920
end
2021
end
2122

23+
function check_allrowscommute(Hx, Hz)
24+
for rowx in eachrow(Hx)
25+
for rowz in eachrow(Hz)
26+
comm = sum(rowx .& rowz)
27+
isodd(comm) && return false
28+
end
29+
end
30+
return true
31+
end
32+
2233
function parity_matrix(c::CSS)
2334
extended_Hx = Matrix{Bool}(vcat(c.Hx, zeros(size(c.Hz))))
2435
extended_Hz = Matrix{Bool}(vcat(zeros(size(c.Hx)), c.Hz))
@@ -33,4 +44,4 @@ code_s(c::CSS) = size(c.Hx, 1) + size(c.Hz, 1)
3344

3445

3546
# Parity matrix for general CSS codes
36-
parity_matrix(c::AbstractCSSCode) = parity_matrix(CSS(parity_matrix_x(c), parity_matrix_z(c)))
47+
parity_matrix(c::AbstractCSSCode) = parity_matrix(CSS(parity_matrix_x(c), parity_matrix_z(c)))

0 commit comments

Comments
 (0)