Skip to content

Commit

Permalink
fix #191: too restrictive typeassert for MixedDestabilizer (#366)
Browse files Browse the repository at this point in the history
Co-authored-by: Stefan Krastanov <[email protected]>
  • Loading branch information
Fe-r-oz and Krastanov authored Nov 3, 2024
1 parent c3546cd commit 56acb6e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/QuantumClifford.jl
Original file line number Diff line number Diff line change
Expand Up @@ -571,8 +571,8 @@ function MixedDestabilizer(stab::Stabilizer{T}; undoperm=true, reportperm=false)
t[n+r+s+1:end] = sZ # The other logical set in the tableau
end
if undoperm
t = t[:,invperm(permx[permz])]::T
return MixedDestabilizer(t, r+s)::MixedDestabilizer{T}
t = t[:,invperm(permx[permz])]
return MixedDestabilizer(t, r+s)
end
if reportperm
return (MixedDestabilizer(t, r+s)::MixedDestabilizer{T}, r, permx, permz)
Expand Down
14 changes: 14 additions & 0 deletions test/test_stabs.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@testitem "Stabilizers" begin
using QuantumClifford
using QuantumClifford: stab_looks_good, destab_looks_good, mixed_stab_looks_good, mixed_destab_looks_good
test_sizes = [1,2,10,63,64,65,127,128,129] # Including sizes that would test off-by-one errors in the bit encoding.
@testset "Pure and Mixed state initialization" begin
Expand Down Expand Up @@ -107,4 +108,17 @@
@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

@testset "MixedDestabilizer over subarrays (#191)" begin
# Case 1: QuantumClifford.Tableau{Vector{UInt8}, Matrix{UInt64}}
n = 6
stab = random_stabilizer(n)
regular_arr = MixedDestabilizer(stab; undoperm=true)
@test isa(regular_arr, MixedDestabilizer)
# Case 2: Tableau{SubArray{...}, SubArray{...}, Tuple{Base.Slice{...}}}
stab = random_stabilizer(n)
substab = @view stab[3:n]
md_via_subarr = MixedDestabilizer(substab; undoperm=true)
@test isa(md_via_subarr, MixedDestabilizer)
end
end

0 comments on commit 56acb6e

Please sign in to comment.