Skip to content

Commit 56acb6e

Browse files
Fe-r-ozKrastanov
andauthored
fix #191: too restrictive typeassert for MixedDestabilizer (#366)
Co-authored-by: Stefan Krastanov <[email protected]>
1 parent c3546cd commit 56acb6e

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/QuantumClifford.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -571,8 +571,8 @@ function MixedDestabilizer(stab::Stabilizer{T}; undoperm=true, reportperm=false)
571571
t[n+r+s+1:end] = sZ # The other logical set in the tableau
572572
end
573573
if undoperm
574-
t = t[:,invperm(permx[permz])]::T
575-
return MixedDestabilizer(t, r+s)::MixedDestabilizer{T}
574+
t = t[:,invperm(permx[permz])]
575+
return MixedDestabilizer(t, r+s)
576576
end
577577
if reportperm
578578
return (MixedDestabilizer(t, r+s)::MixedDestabilizer{T}, r, permx, permz)

test/test_stabs.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
@testitem "Stabilizers" begin
2+
using QuantumClifford
23
using QuantumClifford: stab_looks_good, destab_looks_good, mixed_stab_looks_good, mixed_destab_looks_good
34
test_sizes = [1,2,10,63,64,65,127,128,129] # Including sizes that would test off-by-one errors in the bit encoding.
45
@testset "Pure and Mixed state initialization" begin
@@ -107,4 +108,17 @@
107108
@test hcat(copy(tab(s1)), copy(tab(s2))) == T"-YZZY XXYX"
108109
@test hcat(copy(tab(s1)), copy(tab(s2)), copy(tab(s1)), copy(tab(s2))) == T"YZZYYZZY XXYXXXYX"
109110
end
111+
112+
@testset "MixedDestabilizer over subarrays (#191)" begin
113+
# Case 1: QuantumClifford.Tableau{Vector{UInt8}, Matrix{UInt64}}
114+
n = 6
115+
stab = random_stabilizer(n)
116+
regular_arr = MixedDestabilizer(stab; undoperm=true)
117+
@test isa(regular_arr, MixedDestabilizer)
118+
# Case 2: Tableau{SubArray{...}, SubArray{...}, Tuple{Base.Slice{...}}}
119+
stab = random_stabilizer(n)
120+
substab = @view stab[3:n]
121+
md_via_subarr = MixedDestabilizer(substab; undoperm=true)
122+
@test isa(md_via_subarr, MixedDestabilizer)
123+
end
110124
end

0 commit comments

Comments
 (0)