Skip to content

Commit

Permalink
adding codereview suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
Fe-r-oz committed Sep 1, 2024
1 parent bcb30dc commit 2cc1542
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
25 changes: 17 additions & 8 deletions src/QuantumClifford.jl
Original file line number Diff line number Diff line change
Expand Up @@ -926,15 +926,24 @@ end
Base.vcat(stabs::Stabilizer...) = Stabilizer(vcat((tab(s) for s in stabs)...))

function Base.hcat(tabs::Tableau...)
# Ensure all Tableaus have the same number of rows
nqubits = tabs[1].nqubits
if !all(t -> t.nqubits == nqubits, tabs)
throw(ArgumentError("All Tableaus must have the same number of qubits for horizontal concatenation."))
rows = size(tabs[1], 1)
cols = sum(map(tab -> size(tab, 2), tabs))
newtab = zero(Tableau, rows, cols)
cols_idx = 1
for tab in tabs
rows_tab, cols_tab = size(tab)
if rows_tab != rows
throw(ArgumentError("All input Tableaux/Stabilizers must have the same number of rows."))
end
for i in 1:rows
newtab.phases[i] |= tab.phases[i]
for j in 1:cols_tab
newtab[i, cols_idx+j-1] = tab[i, j]
end
end
cols_idx += cols_tab
end
Tableau(
tabs[1].phases, #does not make sense, better method needed for phases concatenation
sum(s.nqubits for s in tabs),
hcat((s.xzs for s in tabs)...))
return newtab
end

Base.hcat(stabs::Stabilizer...) = Stabilizer(hcat((tab(s) for s in stabs)...))
Expand Down
11 changes: 11 additions & 0 deletions test/test_stabs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,15 @@
@test stab_to_gf2(s2a) == stab_to_gf2(s2b)
end
end

@testset "horizontal concatenation" begin
@test hcat(ghz(2), ghz(2)) == S"XXXX ZZZZ"
s1 = S"YZ -XX"
s2 = S"-ZY -YX"
@test hcat(copy(s1), copy(s2)) == S"-YZZY -XXYX"
@test hcat(copy(s1), copy(s2), copy(s1), copy(s2)) == S"-YZZYYZZY -XXYXXXYX"
@test_throws ArgumentError hcat(copy(s1), random_stabilizer(3))
@test hcat(copy(tab(s1)), copy(tab(s2))) == T"-YZZY -XXYX"
@test hcat(copy(tab(s1)), copy(tab(s2)), copy(tab(s1)), copy(tab(s2))) == T"-YZZYYZZY -XXYXXXYX"
end
end

0 comments on commit 2cc1542

Please sign in to comment.