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

MixedDestabilizer constructor has too restrictive typeassert making it break on subarray input #191

Open
Krastanov opened this issue Sep 27, 2023 · 0 comments
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@Krastanov
Copy link
Member

julia> random_destabilizer(5,6) |> stabilizerview |> MixedDestabilizer
ERROR: TypeError: in typeassert, expected QuantumClifford.Tableau{SubArray{UInt8, 1, Vector{UInt8}, Tuple{UnitRange{Int64}}, true}, SubArray{UInt64, 2, Matrix{UInt64}, Tuple{Base.Slice{Base.OneTo{Int64}}, UnitRange{Int64}}, true}}, got a value of type QuantumClifford.Tableau{Vector{UInt8}, Matrix{UInt64}}
Stacktrace:
 [1] MixedDestabilizer(stab::Stabilizer{QuantumClifford.Tableau{SubArray{UInt8, 1, Vector{UInt8}, Tuple{UnitRange{Int64}}, true}, SubArray{UInt64, 2, Matrix{UInt64}, Tuple{Base.Slice{Base.OneTo{Int64}}, UnitRange{Int64}}, true}}}; undoperm::Bool, reportperm::Bool)
   @ QuantumClifford ~/Documents/ScratchSpace/quantumjulia/QuantumClifford.jl/src/QuantumClifford.jl:558


julia> random_destabilizer(5,6) |> stabilizerview |> copy |> MixedDestabilizer
# works fine

This is due to the following line:

t = t[:,invperm(permx[permz])]::T

where that t is not always of type T due to

t = zero(T, n*2, n)
vstab = @view tab(stab)[1:r+s] # this view is necessary for cases of tableaux with redundant rows

If T involves subarray views, then zero just makes a new tableau directly using arrays, not subarrays (as it should!):

julia> typeof(@view rand(5)[1:4])
SubArray{Float64, 1, Vector{Float64}, Tuple{UnitRange{Int64}}, true}

julia> typeof(zero(@view rand(5)[1:4]))
Vector{Float64} (alias for Array{Float64, 1})

The type assert is there to help JET, so any fix should be checked for whether it causes inference issues detected by JET (that happens automatically thanks to our CI running test/test_jet.jl).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant