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 JET issues #155

Merged
merged 2 commits into from
Jul 17, 2023
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
21 changes: 11 additions & 10 deletions .github/workflows/ci-julia-nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,17 @@ jobs:
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
arch:
- x64
version:
- 'nightly'
threads:
- 2
jet:
- 'true'
include:
- os: ubuntu-latest
arch: x64
version: nightly
threads: 2
jet: 'false'
- os: ubuntu-latest
arch: x64
version: '1'
threads: 2
jet: 'true'
steps:
- uses: actions/checkout@v3
- uses: julia-actions/setup-julia@v1
Expand Down
4 changes: 2 additions & 2 deletions src/QuantumClifford.jl
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ end
function Tableau(paulis::AbstractVector{PauliOperator{Tz,Tv}}) where {Tz<:AbstractArray{UInt8,0},Tve<:Unsigned,Tv<:AbstractVector{Tve}}
r = length(paulis)
n = nqubits(paulis[1])
tab = zero(Tableau{Vector{UInt8},Matrix{Tve}},r,n)
tab = zero(Tableau{Vector{UInt8},Matrix{Tve}},r,n)::Tableau{Vector{UInt8},Matrix{Tve}} # typeassert for JET
for i in eachindex(paulis)
tab[i] = paulis[i]
tab[i] = paulis[i]::PauliOperator{Tz,Tv} # typeassert for JET
end
tab
end
Expand Down
8 changes: 4 additions & 4 deletions src/dense_cliffords.jl
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ function _apply!(stab::AbstractStabilizer, c::CliffordOperator; phases::Val{B}=V
nqubits(stab)==nqubits(c) || throw(DimensionMismatch("The tableau and the Clifford operator need to act on the same number of qubits. Consider specifying an array of indices as a third argument to the `apply!` function to avoid this error."))
s_tab = tab(stab)
c_tab = tab(c)
threadlocal=zero(c_tab[1])
@inbounds @simd for row_stab in eachindex(s_tab)
threadlocal=zero(c_tab[1])::PauliOperator # typeassert for JET
@inbounds for row_stab in eachindex(s_tab)
zero!(threadlocal) # a new stabrow for temporary storage
apply_row_kernel!(threadlocal, row_stab, s_tab, c_tab, phases=phases)
end
Expand Down Expand Up @@ -173,8 +173,8 @@ function _apply!(stab::AbstractStabilizer, c::CliffordOperator, indices_of_appli
#max(indices_of_application)<=nqubits(s) || throw(DimensionMismatch("")) # Too expensive to check every time
s_tab = tab(stab)
c_tab = tab(c)
threadlocal=zero(c_tab[1])
@inbounds @simd for row_stab in eachindex(s_tab)
threadlocal=zero(c_tab[1])::PauliOperator # typeassert for JET
@inbounds for row_stab in eachindex(s_tab)
zero!(threadlocal) # a new stabrow for temporary storage
apply_row_kernel!(threadlocal, row_stab, s_tab, c_tab, indices_of_application, phases=phases)
end
Expand Down
6 changes: 3 additions & 3 deletions src/ecc/ECC.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ function naive_syndrome_circuit(code_type::AbstractECC, ancillary_index=1, bit_i
naive_syndrome_circuit(parity_checks(code_type), ancillary_index, bit_index)
end

"""Circuit that measures the corresponding PauliOperator by using conditional gates into an ancillary
"""Circuit that measures the corresponding PauliOperator by using conditional gates into an ancillary
qubit at index `nqubits(p)+ancillary_index` and stores the measurement result into classical bit `bit_index`."""
function naive_ancillary_paulimeasurement(p::PauliOperator, ancillary_index=1, bit_index=1)
circuit = AbstractOperation[]
numQubits = nqubits(p)
for qubit in 1:numQubits
if p[qubit] == (1,0)
if p[qubit] == (1,0)
push!(circuit, sXCX(qubit, numQubits + ancillary_index))
elseif p[qubit] == (0,1)
push!(circuit, sCNOT(qubit, numQubits + ancillary_index))
Expand Down Expand Up @@ -280,7 +280,7 @@ function faults_matrix(c::AbstractECC)
logviews = [logicalxview(md); logicalzview(md)]
errors = [one(Stabilizer,n; basis=:X);one(Stabilizer,n)]
for i in 1:2k
O[i, :] = comm(logviews[i], errors)
O[i, :] = comm(logviews[i]::PauliOperator, errors) # typeassert for JET
end
return O
end
Expand Down
2 changes: 1 addition & 1 deletion src/mctrajectory.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ end
See also: [`pftrajectories`](@ref), [`petrajectories`](@ref)"""
mctrajectories(initialstate,circuit;trajectories=500,keepstates::Bool=false) = _mctrajectories(initialstate,circuit;trajectories,keepstates=Val(keepstates))

function _mctrajectories(initialstate,circuit;trajectories=500,keepstates::Val{B}) where {B}
function _mctrajectories(initialstate,circuit;trajectories=500,keepstates::Val{B}=Val(false)) where {B}
if B
counter = DefaultDict{Tuple{typeof(initialstate),CircuitStatus},Int}
counts = counter((mctrajectory!(copy(initialstate),circuit)[2] for i in 1:trajectories)) # TODO use threads or at least a generator
Expand Down
8 changes: 7 additions & 1 deletion src/pauli_operator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,13 @@ struct PauliOperator{Tz<:AbstractArray{UInt8,0}, Tv<:AbstractVector{<:Unsigned}}
end

PauliOperator(phase::UInt8, nqubits::Int, xz::Tv) where Tv<:AbstractVector{<:Unsigned} = PauliOperator(fill(UInt8(phase),()), nqubits, xz)
PauliOperator(phase::UInt8, x::AbstractVector{Bool}, z::AbstractVector{Bool}) = PauliOperator(fill(UInt8(phase),()), length(x), vcat(reinterpret(UInt,BitVector(x).chunks),reinterpret(UInt,BitVector(z).chunks)))
function PauliOperator(phase::UInt8, x::AbstractVector{Bool}, z::AbstractVector{Bool})
phase = fill(UInt8(phase),())
xs = reinterpret(UInt,BitVector(x).chunks)::Vector{UInt}
zs = reinterpret(UInt,BitVector(z).chunks)::Vector{UInt}
xzs = cat(xs, zs, dims=1)
PauliOperator(phase, length(x), xzs)
end
PauliOperator(x::AbstractVector{Bool}, z::AbstractVector{Bool}) = PauliOperator(0x0, x, z)
PauliOperator(xz::AbstractVector{Bool}) = PauliOperator(0x0, (@view xz[1:end÷2]), (@view xz[end÷2+1:end]))

Expand Down
4 changes: 2 additions & 2 deletions src/project_trace_reset.jl
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ function _project!(d::Destabilizer,pauli::PauliOperator;keep_result::Val{Bkr}=Va
:Destabilizer))
end
if Bkr
new_pauli = zero(pauli)
new_pauli = zero(pauli)::PauliOperator # typeassert for JET
new_pauli.phase[] = pauli.phase[]
for i in 1:r
comm(pauli,destabilizer,i)!=0 && mul_left!(new_pauli, stabilizer, i, phases=phases)
Expand Down Expand Up @@ -422,7 +422,7 @@ function _project!(d::MixedDestabilizer,pauli::PauliOperator;keep_result::Val{Bk
result = nothing
else
if Bkr
new_pauli = zero(pauli)
new_pauli = zero(pauli)::PauliOperator # typeassert for JET
new_pauli.phase[] = pauli.phase[]
for i in 1:r
comm(pauli,destabilizer,i)!=0 && mul_left!(new_pauli, stabilizer, i, phases=phases)
Expand Down
4 changes: 2 additions & 2 deletions test/test_jet.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ end
)
)
@show rep
@test_broken length(JET.get_reports(rep)) == 0 # false positive from https://github.com/aviatesk/JET.jl/issues/444
@test length(JET.get_reports(rep)) <= 2
@test_broken length(JET.get_reports(rep)) == 0
@test length(JET.get_reports(rep)) <= 7
end
Loading