Skip to content

Commit

Permalink
Reduces JET errors to 17
Browse files Browse the repository at this point in the history
  • Loading branch information
Fe-r-oz committed Sep 12, 2024
1 parent da60deb commit 6c97943
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 24 deletions.
10 changes: 9 additions & 1 deletion src/dense_cliffords.jl
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,15 @@ function row_limit(str, limit=50)
end

digits_subchars = collect("₀₁₂₃₄₅₆₇₈₉")
digits_substr(n,nwidth) = join(([digits_subchars[d+1] for d in reverse(digits(n, pad=nwidth))]))
function digits_substr(n::Integer, nwidth::Int)
dlist = digits(n, base=10, pad=nwidth)
for d in dlist
if d < 0 || d > 9
throw(BoundsError("Digits out of range: $d"))
end
end
return join([digits_subchars[d+1] for d in reverse(dlist)])
end

function Base.copy(c::CliffordOperator)
CliffordOperator(copy(c.tab))
Expand Down
5 changes: 3 additions & 2 deletions src/ecc/ECC.jl
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,9 @@ isdegenerate(c::AbstractECC, args...) = isdegenerate(parity_checks(c), args...)
isdegenerate(c::AbstractStabilizer, args...) = isdegenerate(stabilizerview(c), args...)

function isdegenerate(H::Stabilizer, errors) # Described in https://quantumcomputing.stackexchange.com/questions/27279
syndromes = comm.((H,), errors) # TODO This can be optimized by having something that always returns bitvectors
return length(Set(syndromes)) != length(errors)
syndromes =[comm(H, error) for error in errors] # TODO This can be optimized by having something that always returns bitvectors
syndrome_set = Set(syndromes)
return length(syndrome_set) != length(errors)
end

function isdegenerate(H::Stabilizer, d::Int=1)
Expand Down
12 changes: 10 additions & 2 deletions src/sumtypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ julia> make_variant(sCNOT)
```
"""
function make_variant(type::Union{DataType,SymbolicDataType})
Expr(:call, _symbol(type), [:(::$t) for t in _types(type)]...)
variant_args = []
for t in _types(type)
push!(variant_args, :(::$t))
end
Expr(:call, _symbol(type), variant_args...)
end

"""
Expand Down Expand Up @@ -96,7 +100,11 @@ end)
"""
function make_sumtype_variant_constructor(type)
if isa(type, DataType) || isa(type, SymbolicDataType)
return :( CompactifiedGate(g::$(_header(type))) = CompactifiedGate'.$(_symbol(type))($([:(g.$n) for n in _fieldnames(type)]...)) )
variant_args = []
for n in _fieldnames(type)
push!(variant_args, :(g.$n))
end
return :( CompactifiedGate(g::$(_header(type))) = CompactifiedGate'.$(_symbol(type))($variant_args...) )
else
return :() # this is taken care of by a default constructor that also warns about the failure to compactify
end
Expand Down
39 changes: 20 additions & 19 deletions test/test_jet.jl
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
@testitem "JET checks" tags=[:jet] begin
using JET
using ArrayInterface
using Static
using Graphs
using StridedViews
using LinearAlgebra
using JET
using Test
using ArrayInterface
using Static
using Graphs
using StridedViews
using LinearAlgebra

rep = report_package("QuantumClifford";
ignored_modules=(
AnyFrameModule(Graphs.LinAlg),
AnyFrameModule(Graphs.SimpleGraphs),
AnyFrameModule(ArrayInterface),
AnyFrameModule(Static),
AnyFrameModule(StridedViews),
AnyFrameModule(LinearAlgebra),
)
)
@show rep
@test_broken length(JET.get_reports(rep)) == 0
@test length(JET.get_reports(rep)) <= 23
rep = report_package("QuantumClifford";
ignored_modules=(
AnyFrameModule(Graphs.LinAlg),
AnyFrameModule(Graphs.SimpleGraphs),
AnyFrameModule(ArrayInterface),
AnyFrameModule(Static),
AnyFrameModule(StridedViews),
AnyFrameModule(LinearAlgebra),
))

@show rep
@test_broken length(JET.get_reports(rep)) == 0
@test length(JET.get_reports(rep)) <= 17
end

0 comments on commit 6c97943

Please sign in to comment.