Skip to content
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

fix #191: too restrictive typeassert for MixedDestabilizer #366

Merged
merged 6 commits into from
Nov 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading