-
Notifications
You must be signed in to change notification settings - Fork 94
Feature: Added SHGP and SHYPS Subsystem Quantum Codes #710
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
the-punisher-29
wants to merge
9
commits into
QuantumSavory:master
Choose a base branch
from
the-punisher-29:feature/subsystem-codes
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
5024b36
Implement Subsystem Hypergraph Product and Bravyi-Bacon-Shor Codes
the-punisher-29 d11cd53
wip: add simplex and subsystem shyps codes
the-punisher-29 d6adec3
Added subsystem code interface: gauge_generators, code_g, code_k over…
the-punisher-29 5bd7c86
Fix citation mix up in references.bib
the-punisher-29 93d8b07
Improved subsystem code docs, tests, and references
the-punisher-29 7d262e7
Removed BBS documentation reference
the-punisher-29 84110cc
Moved Simplex into QECCoreNemoExt using Nemo nullspace via _dual
the-punisher-29 5eba8f0
Optimized the simplex file
the-punisher-29 f3f7460
Export dual method from QECCore for reuse by other libraries
the-punisher-29 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| """ | ||
| $TYPEDEF | ||
|
|
||
| The `[2ʳ - 1, r, 2ʳ⁻¹]` simplex code family, dual to the binary Hamming codes. | ||
|
|
||
| `C(r)` is the dual of `Hamming(r)`. Its codewords are the rows of the Hamming | ||
| parity check matrix, and every nonzero codeword has weight `2ʳ⁻¹`. | ||
|
|
||
| Used as the seed code in the SHYPS construction [malcolm2025computing](@cite). | ||
| ECC Zoo: [Simplex code family](https://errorcorrectionzoo.org/c/simplex). | ||
|
|
||
| ### Fields | ||
| \$TYPEDFIELDS | ||
| """ | ||
| struct Simplex <: AbstractCECC | ||
| """Parameter `r` (must be ≥ 2). Determines code length `n = 2ʳ - 1`.""" | ||
| r::Int | ||
| function Simplex(r) | ||
| if r < 2 | ||
| throw(ArgumentError("Invalid parameters: `r` must be ≥ 2 to obtain a valid code.")) | ||
| end | ||
| new(r) | ||
| end | ||
| end | ||
|
|
||
| """ | ||
| dual(H) | ||
|
|
||
| Compute the dual code of a binary parity check matrix `H` using Nemo's nullspace. | ||
| Returns the parity check matrix of the dual code as a transposed nullspace matrix. | ||
|
|
||
| This is a general-purpose utility: for any binary matrix `H`, the dual code's | ||
| generator matrix `G` satisfies `H * Gᵀ = 0` over GF(2). | ||
| """ | ||
| function QECCore.dual(H) | ||
| H_nemo = matrix(GF(2), H) | ||
| null = Nemo.nullspace(H_nemo)[2] | ||
| @assert all(iszero, H_nemo * null) | ||
| return Nemo.transpose(null) | ||
| end | ||
|
|
||
| function QECCore.parity_matrix(c::Simplex) | ||
| r = c.r | ||
| n = 2^r - 1 | ||
| # Building the Hamming parity check matrix -- column j is the number j in r-bit binary | ||
| H_hamming = zeros(Int, r, n) | ||
| for j in 1:n, i in 1:r | ||
| H_hamming[i, j] = (j >> (r - i)) & 1 | ||
| end | ||
| # The dual of the Hamming code is the Simplex code | ||
| dual_mat = QECCore.dual(H_hamming) | ||
| # Converting Nemo matrix back to sparse Int matrix | ||
| nr, nc = size(dual_mat) | ||
| rows_idx = Int[] | ||
| cols_idx = Int[] | ||
| for i in 1:nr, j in 1:nc | ||
| if !iszero(dual_mat[i, j]) | ||
| push!(rows_idx, i) | ||
| push!(cols_idx, j) | ||
| end | ||
| end | ||
| return sparse(rows_idx, cols_idx, ones(Int, length(rows_idx)), nr, n) | ||
| end | ||
|
|
||
| QECCore.code_n(c::Simplex) = 2^c.r - 1 | ||
| QECCore.distance(c::Simplex) = 2^(c.r - 1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| """ | ||
| dual(H) | ||
|
|
||
| Compute the dual code of a binary parity check matrix `H`. | ||
| Returns the parity check matrix of the dual code. | ||
|
|
||
| Requires `Nemo` to be loaded. | ||
| """ | ||
| function dual end | ||
|
|
||
| """Simplex code, the dual of the Hamming code [malcolm2025computing](@cite).""" | ||
| function Simplex(args...; kwargs...) | ||
| ext = Base.get_extension(QECCore, :QECCoreNemoExt) | ||
| if isnothing(ext) | ||
| throw("The `Simplex` code depends on the package `Nemo` but you have not installed or imported it yet. Immediately after you import `Nemo`, the `Simplex` will be available.") | ||
| end | ||
| return ext.Simplex(args...; kwargs...) | ||
| end | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,135 @@ | ||
| """ | ||
| $TYPEDEF | ||
|
|
||
| A Subsystem Hypergraph Product (SHP) code built from two classical parity | ||
| check matrices `H1` (m₁ × n₁) and `H2` (m₂ × n₂). | ||
|
|
||
| Physical qubits: `n = n₁ · n₂`. Logical qubits: `k = nullity(H1) · nullity(H2)`. | ||
| X-type gauge generators are `H1 ⊗ I`; Z-type are `I ⊗ H2`. Stabilizers: | ||
| `S_X = H1 ⊗ ker(H2)` and `S_Z = ker(H1) ⊗ H2`. | ||
|
|
||
| Based on [li2020numerical](@cite). | ||
| ECC Zoo: [Subsystem product code family](https://errorcorrectionzoo.org/c/subsystem_product). | ||
|
|
||
| See also: [`SubsystemHypergraphProductSimplex`](@ref) | ||
|
|
||
| ### Fields | ||
| $TYPEDFIELDS | ||
| """ | ||
| struct SubsystemHypergraphProduct <: AbstractCSSCode | ||
| H1::Matrix{Int} | ||
| H2::Matrix{Int} | ||
| gauge_generators::Tableau | ||
| stabilizer::Stabilizer | ||
| end | ||
|
|
||
| function SubsystemHypergraphProduct(H1::AbstractMatrix, H2::AbstractMatrix) | ||
| m1, n1 = size(H1) | ||
| m2, n2 = size(H2) | ||
| N = n1 * n2 | ||
|
|
||
| gauge_ops = PauliOperator[] | ||
|
|
||
| # X gauge generators = H1 ⊗ I -- each row of H1 gives one X-type generator acting on n2 qubits | ||
| I_n2 = Matrix{Int}(I, n2, n2) | ||
| GX = kron(H1, I_n2) .% 2 | ||
| for r in 1:size(GX, 1) | ||
| p = PauliOperator(0x0, falses(N), falses(N)) | ||
| empty = true | ||
| for c in 1:N | ||
| if GX[r, c] == 1 | ||
| p[c] = (true, false) | ||
| empty = false | ||
| end | ||
| end | ||
| if !empty push!(gauge_ops, p) end | ||
| end | ||
|
|
||
| # Z gauge generators = I ⊗ H2 -- same idea, each row of H2 gives one Z-type generator | ||
| I_n1 = Matrix{Int}(I, n1, n1) | ||
| GZ = kron(I_n1, H2) .% 2 | ||
| for r in 1:size(GZ, 1) | ||
| p = PauliOperator(0x0, falses(N), falses(N)) | ||
| empty = true | ||
| for c in 1:N | ||
| if GZ[r, c] == 1 | ||
| p[c] = (false, true) | ||
| empty = false | ||
| end | ||
| end | ||
| if !empty push!(gauge_ops, p) end | ||
| end | ||
|
|
||
| gauge_generators = Tableau(gauge_ops) | ||
|
|
||
| F = GF(2) | ||
|
|
||
| # G1 = right nullspace of H1, i.e. vectors v where H1*v = 0 | ||
| # Nemo.kernel gives left kernel by default (K*M=0), so we transpose H1 to get what we want | ||
| K1 = Nemo.kernel(transpose(matrix(F, H1))) | ||
| G1 = zeros(Int, Nemo.nrows(K1), n1) | ||
| for i in 1:Nemo.nrows(K1), j in 1:n1 | ||
| G1[i,j] = K1[i,j] == F(1) ? 1 : 0 | ||
| end | ||
|
|
||
| # G2 = right nullspace of H2 -- same thing as above but for H2 | ||
| K2 = Nemo.kernel(transpose(matrix(F, H2))) | ||
| G2 = zeros(Int, Nemo.nrows(K2), n2) | ||
| for i in 1:Nemo.nrows(K2), j in 1:n2 | ||
| G2[i,j] = K2[i,j] == F(1) ? 1 : 0 | ||
| end | ||
|
|
||
| stabs = PauliOperator[] | ||
|
|
||
| # X stabilizers = H1 ⊗ G2 -- tensor each row of H1 with each row of G2 (nullspace of H2) | ||
| SX = kron(H1, G2) .% 2 | ||
| for r in 1:size(SX, 1) | ||
| p = PauliOperator(0x0, falses(N), falses(N)) | ||
| empty = true | ||
| for c in 1:N | ||
| if SX[r, c] == 1 | ||
| p[c] = (true, false) | ||
| empty = false | ||
| end | ||
| end | ||
| if !empty push!(stabs, p) end | ||
| end | ||
|
|
||
| # Z stabilizers = G1 ⊗ H2 -- same idea, tensor nullspace of H1 with each row of H2 | ||
| SZ = kron(G1, H2) .% 2 | ||
| for r in 1:size(SZ, 1) | ||
| p = PauliOperator(0x0, falses(N), falses(N)) | ||
| empty = true | ||
| for c in 1:N | ||
| if SZ[r, c] == 1 | ||
| p[c] = (false, true) | ||
| empty = false | ||
| end | ||
| end | ||
| if !empty push!(stabs, p) end | ||
| end | ||
|
|
||
| stabilizer = Stabilizer(stabs) | ||
|
|
||
| return SubsystemHypergraphProduct(Matrix{Int}(H1), Matrix{Int}(H2), gauge_generators, stabilizer) | ||
| end | ||
|
|
||
| parity_checks(c::SubsystemHypergraphProduct) = c.stabilizer | ||
|
|
||
| gauge_generators(c::SubsystemHypergraphProduct) = c.gauge_generators | ||
|
|
||
| function code_k(c::SubsystemHypergraphProduct) | ||
| F = GF(2) | ||
| n1 = size(c.H1, 2) | ||
| n2 = size(c.H2, 2) | ||
| r1 = Nemo.rank(matrix(F, c.H1)) | ||
| r2 = Nemo.rank(matrix(F, c.H2)) | ||
| return (n1 - r1) * (n2 - r2) | ||
| end | ||
|
|
||
| function code_g(c::SubsystemHypergraphProduct) | ||
| return code_n(c) - code_k(c) - _stabilizer_rank(c) | ||
| end | ||
|
|
||
| parity_matrix_x(c::SubsystemHypergraphProduct) = _stab_to_parity_x(c.stabilizer) | ||
| parity_matrix_z(c::SubsystemHypergraphProduct) = _stab_to_parity_z(c.stabilizer) | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.