diff --git a/.gitignore b/.gitignore index 8bf2daafc..a61e78b68 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ LocalPreferences.toml */.*swp scratch/ *.cov -.vscode \ No newline at end of file +.vscode +test/.CondaPkg/ diff --git a/src/QuantumClifford.jl b/src/QuantumClifford.jl index 60e020440..32ca34a06 100644 --- a/src/QuantumClifford.jl +++ b/src/QuantumClifford.jl @@ -26,7 +26,7 @@ export nqubits, stabilizerview, destabilizerview, logicalxview, logicalzview, phases, fastcolumn, fastrow, - bitview, quantumstate, tab, + bitview, quantumstate, tab, rank, BadDataStructure, affectedqubits, #TODO move to QuantumInterface? # GF2 @@ -173,7 +173,7 @@ Tableau(xzs::AbstractMatrix{Bool}) = Tableau(zeros(UInt8, size(xzs,1)), xzs[:,1: Tableau(t::Tableau) = t -function _T_str(a) # TODO this can be optimized by not creating intermediary PauliOperator objects +function _T_str(a::Union{String,SubString{String}}) # TODO this can be optimized by not creating intermediary PauliOperator objects paulis = [_P_str(strip(s.match)) for s in eachmatch(r"[+-]?\h*[i]?\h*[XYZI_]+", a)] Tableau(paulis) end @@ -229,18 +229,18 @@ end Base.firstindex(tab::Tableau) = 1 -Base.lastindex(tab::Tableau) = length(tab.phases) +Base.lastindex(tab::Tableau) = length(tab.phases)::Int Base.lastindex(tab::Tableau, i) = size(tab)[i] -Base.eachindex(tab::Tableau) = Base.OneTo(lastindex(tab.phases)) +Base.eachindex(tab::Tableau) = Base.OneTo(lastindex(tab.phases)::Int) Base.axes(tab::Tableau) = (Base.OneTo(lastindex(tab)), Base.OneTo(nqubits(tab))) Base.axes(tab::Tableau,i) = axes(tab)[i] -Base.size(tab::Tableau) = (length(tab.phases),nqubits(tab)) +Base.size(tab::Tableau) = (length(tab.phases)::Int, nqubits(tab)) Base.size(tab::Tableau,i) = size(tab)[i] -Base.length(tab::Tableau) = length(tab.phases) +Base.length(tab::Tableau) = length(tab.phases)::Int Base.:(==)(l::Tableau, r::Tableau) = r.nqubits==l.nqubits && r.phases==l.phases && r.xzs==l.xzs @@ -378,7 +378,7 @@ macro S_str(a) quote Stabilizer(_T_str($a)) end end Base.getindex(stab::Stabilizer, i::Int) = tab(stab)[i] -Base.getindex(stab::Stabilizer, i) = Stabilizer(tab(stab)[i]) +Base.getindex(stab::Stabilizer, i) = Stabilizer(tab(stab)[i]::Tableau) @inline Base.getindex(stab::Stabilizer, r::Int, c) = tab(stab)[r,c] Base.getindex(stab::Stabilizer, r, c) = Stabilizer(tab(stab)[r,c]) Base.view(stab::Stabilizer, r) = Stabilizer(view(tab(stab),r)) @@ -497,11 +497,11 @@ function MixedStabilizer(s::Stabilizer{T}) where {T} MixedStabilizer(spadded,zr) end -MixedStabilizer(s::Stabilizer,rank::Int) = MixedStabilizer(tab(s),rank) +MixedStabilizer(s::Stabilizer,rank::Int) = MixedStabilizer(tab(s), rank) -Base.length(d::MixedStabilizer) = length(d.tab) +Base.length(d::MixedStabilizer) = length(tab(d)) -Base.copy(ms::MixedStabilizer) = MixedStabilizer(copy(ms.tab),ms.rank) +Base.copy(ms::MixedStabilizer) = MixedStabilizer(copy(tab(ms)), rank(ms)) ############################## # Mixed Destabilizer states @@ -580,7 +580,7 @@ function MixedDestabilizer(stab::Stabilizer{T}; undoperm=true, reportperm=false) end function MixedDestabilizer(d::Destabilizer, r::Int) - l,n = size(d.tab) + l,n = size(tab(d)) if l==2n MixedDestabilizer(tab(d), r) else @@ -588,7 +588,7 @@ function MixedDestabilizer(d::Destabilizer, r::Int) end end function MixedDestabilizer(d::Destabilizer) - l,n = size(d.tab) + l,n = size(tab(d)) if l==2n MixedDestabilizer(d, nqubits(d)) else @@ -599,9 +599,9 @@ end MixedDestabilizer(d::MixedStabilizer) = MixedDestabilizer(stabilizerview(d)) MixedDestabilizer(d::MixedDestabilizer) = d -Base.length(d::MixedDestabilizer) = length(d.tab)÷2 +Base.length(d::MixedDestabilizer) = length(tab(d))÷2 -Base.copy(d::MixedDestabilizer) = MixedDestabilizer(copy(d.tab),d.rank) +Base.copy(d::MixedDestabilizer) = MixedDestabilizer(copy(tab(d)),rank(d)) ############################## # Subtableau views @@ -610,17 +610,17 @@ Base.copy(d::MixedDestabilizer) = MixedDestabilizer(copy(d.tab),d.rank) """A view of the subtableau corresponding to the stabilizer. See also [`tab`](@ref), [`destabilizerview`](@ref), [`logicalxview`](@ref), [`logicalzview`](@ref)""" @inline stabilizerview(s::Stabilizer) = s @inline stabilizerview(s::Destabilizer) = Stabilizer(@view tab(s)[end÷2+1:end]) -@inline stabilizerview(s::MixedStabilizer) = Stabilizer(@view tab(s)[1:s.rank]) -@inline stabilizerview(s::MixedDestabilizer) = Stabilizer(@view tab(s)[end÷2+1:end÷2+s.rank]) +@inline stabilizerview(s::MixedStabilizer) = Stabilizer(@view tab(s)[1:rank(s)]) +@inline stabilizerview(s::MixedDestabilizer) = Stabilizer(@view tab(s)[end÷2+1:end÷2+rank(s)]) """A view of the subtableau corresponding to the destabilizer. See also [`tab`](@ref), [`stabilizerview`](@ref), [`logicalxview`](@ref), [`logicalzview`](@ref)""" @inline destabilizerview(s::Destabilizer) = Stabilizer(@view tab(s)[1:end÷2]) -@inline destabilizerview(s::MixedDestabilizer) = Stabilizer(@view tab(s)[1:s.rank]) +@inline destabilizerview(s::MixedDestabilizer) = Stabilizer(@view tab(s)[1:rank(s)]) """A view of the subtableau corresponding to the logical X operators. See also [`tab`](@ref), [`stabilizerview`](@ref), [`destabilizerview`](@ref), [`logicalzview`](@ref)""" -@inline logicalxview(s::MixedDestabilizer) = Stabilizer(@view tab(s)[s.rank+1:end÷2]) +@inline logicalxview(s::MixedDestabilizer) = Stabilizer(@view tab(s)[rank(s)+1:end÷2]) """A view of the subtableau corresponding to the logical Z operators. See also [`tab`](@ref), [`stabilizerview`](@ref), [`destabilizerview`](@ref), [`logicalxview`](@ref)""" -@inline logicalzview(s::MixedDestabilizer) = Stabilizer(@view tab(s)[end÷2+s.rank+1:end]) +@inline logicalzview(s::MixedDestabilizer) = Stabilizer(@view tab(s)[end÷2+rank(s)+1:end]) """The number of qubits of a given state.""" @inline nqubits(s::AbstractStabilizer) = nqubits(tab(s)) diff --git a/src/dense_cliffords.jl b/src/dense_cliffords.jl index baec10f6e..e4113e0e2 100644 --- a/src/dense_cliffords.jl +++ b/src/dense_cliffords.jl @@ -62,7 +62,7 @@ CliffordOperator(op::CliffordOperator) = op CliffordOperator(paulis::AbstractVector{<:PauliOperator}) = CliffordOperator(Tableau(paulis)) CliffordOperator(destab::Destabilizer) = CliffordOperator(tab(destab)) -Base.:(==)(l::CliffordOperator, r::CliffordOperator) = l.tab == r.tab +Base.:(==)(l::CliffordOperator, r::CliffordOperator) = tab(l) == tab(r) Base.hash(c::T, h::UInt) where {T<:CliffordOperator} = hash(T, hash(tab(c), h)) Base.getindex(c::CliffordOperator, args...) = getindex(tab(c), args...) @@ -85,16 +85,16 @@ digits_subchars = collect("₀₁₂₃₄₅₆₇₈₉") digits_substr(n::Int,nwidth::Int) = join(([digits_subchars[d+1] for d in reverse(digits(n, pad=nwidth))])) function Base.copy(c::CliffordOperator) - CliffordOperator(copy(c.tab)) + CliffordOperator(copy(tab(c))) end -@inline nqubits(c::CliffordOperator) = nqubits(c.tab) +@inline nqubits(c::CliffordOperator) = nqubits(tab(c)) -Base.zero(c::CliffordOperator) = CliffordOperator(zero(c.tab)) +Base.zero(c::CliffordOperator) = CliffordOperator(zero(tab(c))) Base.zero(::Type{<:CliffordOperator}, n) = CliffordOperator(zero(Tableau, 2n, n)) function Base.:(*)(l::AbstractCliffordOperator, r::CliffordOperator) - tab = copy(r.tab) + tab = copy(QuantumClifford.tab(r)) apply!(Stabilizer(tab),l) # TODO maybe not the most elegant way to perform apply!(::Tableau, gate) CliffordOperator(tab) end @@ -106,7 +106,7 @@ end # TODO create Base.permute! and getindex(..., permutation_array) function permute(c::CliffordOperator,p) # TODO this is a slow stupid implementation - CliffordOperator(Tableau([c.tab[i][p] for i in 1:2*nqubits(c)][vcat(p,p.+nqubits(c))])) + CliffordOperator(Tableau([tab(c)[i][p] for i in 1:2*nqubits(c)][vcat(p,p.+nqubits(c))])) end """Nonvectorized version of `apply!` used for unit tests.""" diff --git a/src/ecc/circuits.jl b/src/ecc/circuits.jl index 45aabf1a7..72b3f338c 100644 --- a/src/ecc/circuits.jl +++ b/src/ecc/circuits.jl @@ -74,6 +74,7 @@ function perm_to_transpositions(perm) for i in n:-1:1 if perm[i]!=i j = findfirst(==(i), perm) + @assert !isnothing(j) push!(transpositions, (i, j)) perm[j] = perm[i] end diff --git a/src/ecc/decoder_pipeline.jl b/src/ecc/decoder_pipeline.jl index 3ac2680cf..aeb481851 100644 --- a/src/ecc/decoder_pipeline.jl +++ b/src/ecc/decoder_pipeline.jl @@ -251,7 +251,7 @@ function create_lookup_table(code::Stabilizer) for bit_to_be_flipped in 1:qubits for error_type in [single_x, single_y, single_z] # Generate e⃗ - error = error_type(qubits, bit_to_be_flipped) + error = error_type(qubits, bit_to_be_flipped)::PauliOperator{Array{UInt8, 0}, Vector{UInt}} # Calculate s⃗ # (check which stabilizer rows do not commute with the Pauli error) syndrome = comm(error, code) diff --git a/src/fastmemlayout.jl b/src/fastmemlayout.jl index f7019cd1a..67e2bbbd7 100644 --- a/src/fastmemlayout.jl +++ b/src/fastmemlayout.jl @@ -20,14 +20,14 @@ fastrow(t::Tableau{Tₚᵥ,Tₘ}) where {Tₚᵥ, Tₘ<:Adjoint} = Tableau(t.pha fastcolumn(t::Tableau{Tₚᵥ,Tₘ}) where {Tₚᵥ, Tₘ} = Tableau(t.phases, t.nqubits, collect(t.xzs')') fastcolumn(t::Tableau{Tₚᵥ,Tₘ}) where {Tₚᵥ, Tₘ<:Adjoint} = t -fastrow(s::Stabilizer) = Stabilizer(fastrow(s.tab)) -fastcolumn(s::Stabilizer) = Stabilizer(fastcolumn(s.tab)) +fastrow(s::Stabilizer) = Stabilizer(fastrow(tab(s))) +fastcolumn(s::Stabilizer) = Stabilizer(fastcolumn(tab(s))) -fastrow(s::Destabilizer) = Destabilizer(fastrow(s.tab)) -fastcolumn(s::Destabilizer) = Destabilizer(fastcolumn(s.tab)) +fastrow(s::Destabilizer) = Destabilizer(fastrow(tab(s))) +fastcolumn(s::Destabilizer) = Destabilizer(fastcolumn(tab(s))) -fastrow(s::MixedStabilizer) = MixedStabilizer(fastrow(s.tab), s.rank) -fastcolumn(s::MixedStabilizer) = MixedStabilizer(fastcolumn(s.tab), s.rank) +fastrow(s::MixedStabilizer) = MixedStabilizer(fastrow(tab(s)), rank(s)) +fastcolumn(s::MixedStabilizer) = MixedStabilizer(fastcolumn(tab(s)), rank(s)) -fastrow(s::MixedDestabilizer) = MixedDestabilizer(fastrow(s.tab), s.rank) -fastcolumn(s::MixedDestabilizer) = MixedDestabilizer(fastcolumn(s.tab), s.rank) +fastrow(s::MixedDestabilizer) = MixedDestabilizer(fastrow(tab(s)), rank(s)) +fastcolumn(s::MixedDestabilizer) = MixedDestabilizer(fastcolumn(tab(s)), rank(s)) diff --git a/src/linalg.jl b/src/linalg.jl index b95fba888..ad252e95f 100644 --- a/src/linalg.jl +++ b/src/linalg.jl @@ -260,7 +260,7 @@ function tensor(ops::CliffordOperator...) # TODO implement \otimes for Destabili last_zrow = ntot last_xrow = 0 for op in ops - t = op.tab + t = QuantumClifford.tab(op) _, last_zrow, _ = puttableau!(tab, (@view t[end÷2+1:end]), last_zrow, last_xrow) _, last_xrow, _ = puttableau!(tab, (@view t[1:end÷2]), last_xrow, last_xrow) end diff --git a/src/mul_leftright.jl b/src/mul_leftright.jl index 122fb1e61..9803ed2b5 100644 --- a/src/mul_leftright.jl +++ b/src/mul_leftright.jl @@ -56,12 +56,6 @@ function mul_ordered_lv!(r::AbstractVector{T}, l::AbstractVector{T}; phases::Val end =# -function mul_ordered!(r::SubArray{T,1,P,I1,L1}, l::SubArray{T,1,P,I2,L2}; phases::Val{B}=Val(true)) where {T<:Unsigned, B, I1, I2, L1, L2, P<:Adjoint} - # This method exists because SIMD.jl does not play well with Adjoint - # Delete it and try `QuantumClifford.mul_left!(fastcolumn(random_stabilizer(194)), 2, 1)` # works fine for 192 - _mul_ordered_nonvec!(r,l; phases=B) -end - function mul_ordered!(r::SubArray{T,1,P,I2,L2}, l::AbstractVector{T}; phases::Val{B}=Val(true)) where {T<:Unsigned, B, I2, L2, P<:Adjoint} # This method exists because SIMD.jl does not play well with Adjoint _mul_ordered_nonvec!(r,l; phases=B) diff --git a/src/pauli_operator.jl b/src/pauli_operator.jl index e556628bc..a843ef10b 100644 --- a/src/pauli_operator.jl +++ b/src/pauli_operator.jl @@ -77,7 +77,7 @@ function zbit(p::PauliOperator) [(word>>s)&one==one for word in zview(p) for s in 0:size-1][begin:p.nqubits] end -function _P_str(a) +function _P_str(a::Union{String,SubString{String}}) letters = filter(x->occursin(x,"_IZXY"),a) phase = phasedict[strip(filter(x->!occursin(x,"_IZXY"),a))] PauliOperator(phase, [l=='X'||l=='Y' for l in letters], [l=='Z'||l=='Y' for l in letters]) @@ -87,7 +87,7 @@ macro P_str(a) quote _P_str($a) end end -Base.getindex(p::PauliOperator{Tₚ,Tᵥ}, i::Int) where {Tₚ, Tᵥₑ<:Unsigned, Tᵥ<:AbstractVector{Tᵥₑ}} = (p.xz[_div(Tᵥₑ, i-1)+1] & Tᵥₑ(0x1)<<_mod(Tᵥₑ,i-1))!=0x0, (p.xz[end÷2+_div(Tᵥₑ,i-1)+1] & Tᵥₑ(0x1)<<_mod(Tᵥₑ,i-1))!=0x0 +Base.getindex(p::PauliOperator{Tₚ,Tᵥ}, i::Int) where {Tₚ, Tᵥₑ<:Unsigned, Tᵥ<:AbstractVector{Tᵥₑ}} = ((p.xz[_div(Tᵥₑ, i-1)+1] & Tᵥₑ(0x1)<<_mod(Tᵥₑ,i-1))!=0x0)::Bool, ((p.xz[end÷2+_div(Tᵥₑ,i-1)+1] & Tᵥₑ(0x1)<<_mod(Tᵥₑ,i-1))!=0x0)::Bool Base.getindex(p::PauliOperator{Tₚ,Tᵥ}, r) where {Tₚ, Tᵥₑ<:Unsigned, Tᵥ<:AbstractVector{Tᵥₑ}} = PauliOperator(p.phase[], xbit(p)[r], zbit(p)[r]) function Base.setindex!(p::PauliOperator{Tₚ,Tᵥ}, (x,z)::Tuple{Bool,Bool}, i) where {Tₚ, Tᵥₑ, Tᵥ<:AbstractVector{Tᵥₑ}} @@ -176,7 +176,8 @@ end function embed(n::Int, indices, p::PauliOperator) if nqubits(p) == length(indices) pout = zero(typeof(p), n) - @inbounds @simd for i in eachindex(indices) + @inbounds @simd for i_ in eachindex(indices) + i = i_::Int pout[indices[i]] = p[i] end pout.phase[] = p.phase[] diff --git a/src/project_trace_reset.jl b/src/project_trace_reset.jl index 19e49521b..4b2e6e2e5 100644 --- a/src/project_trace_reset.jl +++ b/src/project_trace_reset.jl @@ -339,7 +339,7 @@ end function _project!(d::Destabilizer,pauli::PauliOperator;keep_result::Val{Bkr}=Val(true),phases::Val{Bp}=Val(true)) where {Bkr, Bp} # repetition between Destabilizer and MixedDestabilizer, but the redundancy makes the two codes slightly simpler and easier to infer anticommutes = 0 - tab = d.tab + tab = QuantumClifford.tab(d) stabilizer = stabilizerview(d) destabilizer = destabilizerview(d) r = trusted_rank(d) @@ -377,7 +377,7 @@ end function _project!(d::MixedDestabilizer,pauli::PauliOperator;keep_result::Val{Bkr}=Val(true),phases::Val{Bp}=Val(true)) where {Bkr, Bp} # repetition between Destabilizer and MixedDestabilizer, but the redundancy makes the two codes slightly simpler and easier to infer anticommutes = 0 - tab = d.tab + tab = QuantumClifford.tab(d) stabilizer = stabilizerview(d) destabilizer = destabilizerview(d) r = trusted_rank(d) @@ -497,7 +497,7 @@ end """Internal method used to implement [`projectX!`](@ref), [`projectZ!`](@ref), and [`projectY!`](@ref).""" function project_cond!(d::MixedDestabilizer,qubit::Int,cond::Val{IS},reset::Val{RESET};keep_result::Bool=true,phases::Val{PHASES}=Val(true)) where {IS,RESET,PHASES} anticommutes = 0 - tab = d.tab + tab = QuantumClifford.tab(d) stabilizer = stabilizerview(d) destabilizer = destabilizerview(d) r = d.rank @@ -647,7 +647,7 @@ function traceout!(s::Union{MixedStabilizer, MixedDestabilizer}, qubits; phases= if rank return (s, i) else return s end end -function _expand_pauli(pauli,qubits,n) # TODO rename and make public +function _expand_pauli(pauli::PauliOperator,qubits,n) # TODO rename and make public expanded = zero(PauliOperator,n) for (ii, i) in enumerate(qubits) expanded[i] = pauli[ii] @@ -886,4 +886,4 @@ See also: [`traceout!`](@ref) """ function delete_columns(𝒮::Stabilizer, subset) return 𝒮[:, setdiff(1:nqubits(𝒮), subset)] -end \ No newline at end of file +end diff --git a/src/randoms.jl b/src/randoms.jl index 1d4fff388..c87932fd4 100644 --- a/src/randoms.jl +++ b/src/randoms.jl @@ -184,7 +184,7 @@ function nemo_inv(a, n)::Matrix{UInt8} end """Sample (h, S) from the distribution P_n(h, S) from Bravyi and Maslov Algorithm 1.""" -function quantum_mallows(rng, n) # each one is benchmakred in benchmarks/quantum_mallows.jl +function quantum_mallows(rng::AbstractRNG, n::Int) # each one is benchmarked in benchmarks/quantum_mallows.jl arr = collect(1:n) hadamard = falses(n) perm = zeros(Int64, n) @@ -202,7 +202,7 @@ end """ This function samples a number from 1 to `n` where `n >= 1` probability of outputting `i` is proportional to `2^i`""" -function sample_geometric_2(rng, n::Integer) +function sample_geometric_2(rng::AbstractRNG, n::Integer) n < 1 && throw(DomainError(n)) if n<30 k = rand(rng, 2:UInt(2)^n) @@ -217,7 +217,7 @@ function sample_geometric_2(rng, n::Integer) end """Assign (symmetric) random ints to off diagonals of matrix.""" -function fill_tril(rng, matrix, n; symmetric::Bool=false) +function fill_tril(rng::AbstractRNG, matrix, n; symmetric::Bool=false) # Add (symmetric) random ints to off diagonals @inbounds for row in 1:n, col in 1:row-1 b = rand(rng, Bool) diff --git a/src/symbolic_cliffords.jl b/src/symbolic_cliffords.jl index e73622217..601696855 100644 --- a/src/symbolic_cliffords.jl +++ b/src/symbolic_cliffords.jl @@ -203,7 +203,7 @@ SingleQubitOperator(p::sInvSQRTY) = SingleQubitOperator(p.q, false, tr SingleQubitOperator(o::SingleQubitOperator) = o function SingleQubitOperator(op::CliffordOperator, qubit) nqubits(op)==1 || throw(DimensionMismatch("You are trying to convert a multiqubit `CliffordOperator` into a symbolic `SingleQubitOperator`.")) - SingleQubitOperator(qubit,op.tab[1,1]...,op.tab[2,1]...,(~).(iszero.(op.tab.phases))...) + SingleQubitOperator(qubit,tab(op)[1,1]...,tab(op)[2,1]...,(~).(iszero.(tab(op).phases))...) end SingleQubitOperator(op::CliffordOperator) = SingleQubitOperator(op, 1) diff --git a/src/tableau_show.jl b/src/tableau_show.jl index 52e1adc07..303549573 100644 --- a/src/tableau_show.jl +++ b/src/tableau_show.jl @@ -76,15 +76,15 @@ function Base.show(io::IO, d::Destabilizer) print(io, "Destablizer $r×$q") elseif get(io, :limit, false) h,w = displaysize(io) - println(io, "𝒟ℯ𝓈𝓉𝒶𝒷" * "━"^max(min(w-9,size(d.tab,2)-4),0)) - _show(io, destabilizerview(d).tab, w, h÷2) - println(io, "\n𝒮𝓉𝒶𝒷" * "━"^max(min(w-7,size(d.tab,2)-2),0)) - _show(io, stabilizerview(d).tab, w, h÷2) + println(io, "𝒟ℯ𝓈𝓉𝒶𝒷" * "━"^max(min(w-9,size(tab(d),2)-4),0)) + _show(io, tab(destabilizerview(d)), w, h÷2) + println(io, "\n𝒮𝓉𝒶𝒷" * "━"^max(min(w-7,size(tab(d),2)-2),0)) + _show(io, tab(stabilizerview(d)), w, h÷2) else - println(io, "𝒟ℯ𝓈𝓉𝒶𝒷" * "━"^max(size(d.tab,2)-4,0)) - _show(io, destabilizerview(d).tab, missing, missing) - println(io, "\n𝒮𝓉𝒶𝒷" * "━"^max(size(d.tab,2)-2,0)) - _show(io, stabilizerview(d).tab, missing, missing) + println(io, "𝒟ℯ𝓈𝓉𝒶𝒷" * "━"^max(size(tab(d),2)-4,0)) + _show(io, tab(destabilizerview(d)), missing, missing) + println(io, "\n𝒮𝓉𝒶𝒷" * "━"^max(size(tab(d),2)-2,0)) + _show(io, tab(stabilizerview(d)), missing, missing) end end @@ -95,36 +95,36 @@ function Base.show(io::IO, d::MixedDestabilizer) print(io, "MixedDestablizer $r×$q") elseif get(io, :limit, false) h,w = displaysize(io) - println(io, "𝒟ℯ𝓈𝓉𝒶𝒷" * "━"^max(min(w-9,size(d.tab,2)-4),0)) - _show(io, destabilizerview(d).tab, w, h÷4) + println(io, "𝒟ℯ𝓈𝓉𝒶𝒷" * "━"^max(min(w-9,size(tab(d),2)-4),0)) + _show(io, tab(destabilizerview(d)), w, h÷4) if r != q println(io) - println(io, "𝒳ₗ" * "━"^max(min(w-5,size(d.tab,2)),0)) - _show(io, logicalxview(d).tab, w, h÷4) + println(io, "𝒳ₗ" * "━"^max(min(w-5,size(tab(d),2)),0)) + _show(io, tab(logicalxview(d)), w, h÷4) end println(io) - println(io, "𝒮𝓉𝒶𝒷" * "━"^max(min(w-7,size(d.tab,2)-2),0)) - _show(io, stabilizerview(d).tab, w, h÷4) + println(io, "𝒮𝓉𝒶𝒷" * "━"^max(min(w-7,size(tab(d),2)-2),0)) + _show(io, tab(stabilizerview(d)), w, h÷4) if r != q println(io) - println(io, "𝒵ₗ" * "━"^max(min(w-5,size(d.tab,2)),0)) - _show(io, logicalzview(d).tab, w, h÷4) + println(io, "𝒵ₗ" * "━"^max(min(w-5,size(tab(d),2)),0)) + _show(io, tab(logicalzview(d)), w, h÷4) end else - println(io, "𝒟ℯ𝓈𝓉𝒶𝒷" * "━"^max(size(d.tab,2)-4,0)) - _show(io, destabilizerview(d).tab, missing, missing) + println(io, "𝒟ℯ𝓈𝓉𝒶𝒷" * "━"^max(size(tab(d),2)-4,0)) + _show(io, tab(destabilizerview(d)), missing, missing) if r != q println(io) - println(io, "𝒳ₗ" * "━"^max(size(d.tab,2),0)) - _show(io, logicalxview(d).tab, missing, missing) + println(io, "𝒳ₗ" * "━"^max(size(tab(d),2),0)) + _show(io, tab(logicalxview(d)), missing, missing) end println(io) - println(io, "𝒮𝓉𝒶𝒷" * "━"^max(size(d.tab,2)-2,0)) - _show(io, stabilizerview(d).tab, missing, missing) + println(io, "𝒮𝓉𝒶𝒷" * "━"^max(size(tab(d),2)-2,0)) + _show(io, tab(stabilizerview(d)), missing, missing) if r != q println(io) - println(io, "𝒵ₗ" * "━"^max(size(d.tab,2)),0) - _show(io, logicalzview(d).tab, missing, missing) + println(io, "𝒵ₗ" * "━"^max(size(tab(d),2)),0) + _show(io, tab(logicalzview(d)), missing, missing) end end end @@ -144,7 +144,7 @@ function _show(io::IO, c::CliffordOperator, limit=50, limit_vertical=20) continue end print(io, "X"*digits_substr(i,nwidth)*" ⟼ ") - _show(io, c.tab[i], _limit) + _show(io, tab(c)[i], _limit) println(io) end for i in range @@ -153,7 +153,7 @@ function _show(io::IO, c::CliffordOperator, limit=50, limit_vertical=20) continue end print(io, "Z"*digits_substr(i,nwidth)*" ⟼ ") - _show(io, c.tab[i+n], _limit) + _show(io, tab(c)[i+n], _limit) i!=n && println(io) end end diff --git a/test/Project.toml b/test/Project.toml index cd15ae310..eb254c893 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -25,6 +25,7 @@ RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01" SIMD = "fdea26ae-647d-5447-a871-4b548cad5224" StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3" Static = "aedffcd0-7271-4cad-89d0-dc628f76c6d3" +StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" StridedViews = "4db3bf67-4bd7-4b4e-b153-31dc3fb37143" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" TestItemRunner = "f8b46487-2199-4994-9208-9a1283c18c0a" diff --git a/test/test_jet.jl b/test/test_jet.jl index 91348c168..7f0248ab7 100644 --- a/test/test_jet.jl +++ b/test/test_jet.jl @@ -9,6 +9,7 @@ using Nemo using AbstractAlgebra using Hecke + using StaticArrays rep = report_package("QuantumClifford"; ignored_modules=( @@ -21,10 +22,10 @@ AnyFrameModule(Nemo), AnyFrameModule(AbstractAlgebra), AnyFrameModule(Hecke), + AnyFrameModule(StaticArrays), )) @show rep @show length(JET.get_reports(rep)) - @test_broken length(JET.get_reports(rep)) == 0 - @test length(JET.get_reports(rep)) <= 23 + @test length(JET.get_reports(rep)) == 0 end diff --git a/test/test_noisycircuits.jl b/test/test_noisycircuits.jl index 8ae674161..4f5e92c3e 100644 --- a/test/test_noisycircuits.jl +++ b/test/test_noisycircuits.jl @@ -228,7 +228,7 @@ state = Register(MixedDestabilizer(S"ZZ"), zeros(Bool, 1)) meas = PauliMeasurement(P"ZI", 1) state, flag = applywstatus!(state, meas) - @test state.stab.rank == 2 + @test rank(state.stab) == 2 tab(state.stab).phases .= 0 @test stabilizerview(state.stab) == S"ZZ ZI" diff --git a/test/test_projections.jl b/test/test_projections.jl index 03d56e1e2..beae0ab70 100644 --- a/test/test_projections.jl +++ b/test/test_projections.jl @@ -76,12 +76,12 @@ @test_throws BadDataStructure pds, a, r = project!(copy(ds),p) pms, a, r = project!(copy(ms),p) @test mixed_stab_looks_good(pms) - @test pms.rank==3 - @test a==pms.rank && isnothing(r) + @test rank(pms)==3 + @test a==rank(pms) && isnothing(r) pmds, a, r = project!(copy(mds),p) @test mixed_destab_looks_good(pmds) - @test pmds.rank==3 - @test a==pmds.rank && isnothing(r) + @test rank(pmds)==3 + @test a==rank(pmds) && isnothing(r) p = P"ZZI" ps, a, r = project!(copy(s),p) @@ -90,11 +90,11 @@ @test_throws BadDataStructure pds, a, r = project!(copy(ds),p) pms, a, r = project!(copy(ms),p) @test mixed_stab_looks_good(pms) - @test pms.rank==2 + @test rank(pms)==2 @test a==0 && r==0x2 pmds, a, r = project!(copy(mds),p) @test mixed_destab_looks_good(pmds) - @test pmds.rank==2 + @test rank(pmds)==2 @test a==0 && r==0x2 @test canonicalize!(ps)==canonicalize!(stabilizerview(pms))==canonicalize!(stabilizerview(pmds)) @@ -107,11 +107,11 @@ @test a==2 && isnothing(r) pms, a, r = project!(copy(ms),p) @test mixed_stab_looks_good(pms) - @test pms.rank==2 + @test rank(pms)==2 @test a==2 && isnothing(r) pmds, a, r = project!(copy(mds),p) @test mixed_destab_looks_good(pmds) - @test pmds.rank==2 + @test rank(pmds)==2 @test a==2 && isnothing(r) @test canonicalize!(ps)==canonicalize!(stabilizerview(pms))==canonicalize!(stabilizerview(pds))==canonicalize!(stabilizerview(pmds)) end @@ -162,10 +162,10 @@ s = MixedStabilizer(s, 2) ms, a, r = project!(copy(s), P"IZI") @test (a, r) == (0, 0x0) # on commuting operator in the stabilizer - @test ms.rank == 2 + @test rank(ms) == 2 ms, a, r = project!(copy(s), P"IIZ") @test (a, r) == (3, nothing) # on commuting operator out of the stabilizer - @test ms.rank == 3 + @test rank(ms) == 3 s = S"ZII IZI" s = Destabilizer(s) @test_throws BadDataStructure project!(copy(s), P"IZI"; keep_result=true) # on comm @@ -182,16 +182,16 @@ s = MixedDestabilizer(s) mds, a, r = project!(copy(s), P"IZI"; keep_result=true) @test (a, r) == (0, 0x0) # on commuting operator in the stabilizer - @test mds.rank == 2 + @test rank(mds) == 2 mds, a, r = project!(copy(s), P"IIZ"; keep_result=true) @test (a, r) == (3, nothing) # on commuting operator out of the stabilizer - @test mds.rank == 3 + @test rank(mds) == 3 mds, a, r = project!(copy(s), P"IZI"; keep_result=false) @test (a, r) == (0, nothing) # on commuting operator in the stabilizer - @test mds.rank == 2 + @test rank(mds) == 2 mds, a, r = project!(copy(s), P"IIZ"; keep_result=false) @test (a, r) == (3, nothing) # on commuting operator out of the stabilizer - @test mds.rank == 3 + @test rank(mds) == 3 end @testset "Results from canonicalization vs from destabilizer" begin @test generate!(P"_Z", S"XZ") === nothing # for bug fixed in 4b536231c3ee4e6446262fcc61ba8da669415bc8 @@ -206,7 +206,7 @@ _, ams, rms = project!(ms,p) _, amd, rmd = project!(md,p) @test rs == rms == rmd - @test (md.rank!=r) || (canonicalize!(s) == canonicalize!(stabilizerview(ms))) + @test (rank(md)!=r) || (canonicalize!(s) == canonicalize!(stabilizerview(ms))) @test canonicalize!(stabilizerview(ms)) == canonicalize!(stabilizerview(md)) if as == 0 @test ams == amd == 0 diff --git a/test/test_trace.jl b/test/test_trace.jl index 424399ce1..6ed1022e2 100644 --- a/test/test_trace.jl +++ b/test/test_trace.jl @@ -101,7 +101,7 @@ @test canonicalize!(copy(ssr2v)[:,perm])[1:z] == canonicalize!(copy(newstate)) @test canonicalize!(msr2v) == c[1:z] # Compare different datastractures - @test canonicalize!(copy(stabilizerview(mdr1)))==canonicalize!(copy(stabilizerview(msr1)))==canonicalize!(ssr1[1:mdr1.rank]) + @test canonicalize!(copy(stabilizerview(mdr1)))==canonicalize!(copy(stabilizerview(msr1)))==canonicalize!(ssr1[1:rank(mdr1)]) end end end