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 many things reported by JET #152

Merged
merged 11 commits into from
Sep 14, 2024
14 changes: 9 additions & 5 deletions src/ProtocolZoo/ProtocolZoo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export

abstract type AbstractProtocol end

get_time_tracker(prot::AbstractProtocol) = prot.sim
get_time_tracker(prot::AbstractProtocol) = prot.sim::Simulation

Process(prot::AbstractProtocol, args...; kwargs...) = Process((e,a...;k...)->prot(a...;k...), get_time_tracker(prot), args...; kwargs...)

Expand Down Expand Up @@ -204,15 +204,19 @@ end
while rounds != 0
isentangled = !isnothing(query(prot.net[prot.nodeA], EntanglementCounterpart, prot.nodeB, ❓; assigned=true))
margin = isentangled ? prot.margin : prot.hardmargin
a = findfreeslot(prot.net[prot.nodeA]; randomize=prot.randomize, margin=margin)
b = findfreeslot(prot.net[prot.nodeB]; randomize=prot.randomize, margin=margin)
a_ = findfreeslot(prot.net[prot.nodeA]; randomize=prot.randomize, margin=margin)
b_ = findfreeslot(prot.net[prot.nodeB]; randomize=prot.randomize, margin=margin)

if isnothing(a) || isnothing(b)
if isnothing(a_) || isnothing(b_)
isnothing(prot.retry_lock_time) && error("We do not yet support waiting on register to make qubits available") # TODO
@debug "EntanglerProt between $(prot.nodeA) and $(prot.nodeB)|round $(round): Failed to find free slots. \nGot:\n1. \t $a \n2.\t $b \n retrying..."
@debug "EntanglerProt between $(prot.nodeA) and $(prot.nodeB)|round $(round): Failed to find free slots. \nGot:\n1. \t $a_ \n2.\t $b_ \n retrying..."
@yield timeout(prot.sim, prot.retry_lock_time)
continue
end
# we are now certain that a_ and b_ are not nothing. The compiler is not smart enough to figure this out
# on its own, so we need to tell it explicitly. A new variable name is needed due to @resumable.
a = a_::RegRef
b = b_::RegRef

@yield lock(a) & lock(b) # this yield is expected to return immediately

Expand Down
6 changes: 4 additions & 2 deletions src/ProtocolZoo/swapping.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,14 @@ end
rounds = prot.rounds
round = 1
while rounds != 0
qubit_pair = findswapablequbits(prot.net, prot.node, prot.nodeL, prot.nodeH, prot.chooseL, prot.chooseH; agelimit=prot.agelimit)
if isnothing(qubit_pair)
qubit_pair_ = findswapablequbits(prot.net, prot.node, prot.nodeL, prot.nodeH, prot.chooseL, prot.chooseH; agelimit=prot.agelimit)
if isnothing(qubit_pair_)
isnothing(prot.retry_lock_time) && error("We do not yet support waiting on register to make qubits available") # TODO
@yield timeout(prot.sim, prot.retry_lock_time)
continue
end
# The compiler is not smart enough to figure out that qubit_pair_ is not nothing, so we need to tell it explicitly. A new variable name is needed due to @resumable.
qubit_pair = qubit_pair_::NTuple{2, Base.NamedTuple{(:slot, :id, :tag), Base.Tuple{RegRef, Int128, Tag}}} # TODO: replace by `NTuple{2, @NamedTuple{slot::RegRef, id::Int128, tag::Tag}}` once https://github.com/JuliaDynamics/ResumableFunctions.jl/issues/104 is resolved

(q1, id1, tag1) = qubit_pair[1].slot, qubit_pair[1].id, qubit_pair[1].tag
(q2, id2, tag2) = qubit_pair[2].slot, qubit_pair[2].id, qubit_pair[2].tag
Expand Down
2 changes: 1 addition & 1 deletion src/backends/clifford/should_upstream.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
gates # TODO constructor that flattens nested QCGateSequence
end
function QuantumClifford.apply!(state::QuantumClifford.MixedDestabilizer, gseq::QCGateSequence, indices)
for g in gseq[end:-1:begin]
for g in gseq.gates[end:-1:begin]

Check warning on line 6 in src/backends/clifford/should_upstream.jl

View check run for this annotation

Codecov / codecov/patch

src/backends/clifford/should_upstream.jl#L6

Added line #L6 was not covered by tests
apply_popindex!(state, g, indices)
end
state
Expand Down
4 changes: 2 additions & 2 deletions src/baseops/traceout.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
function project_traceout!(reg::Register, i::Int, basis; time=nothing)
project_traceout!(identity, reg, i, basis; time=time)
end
project_traceout!(r::RegRef, basis; time=nothing) = project_traceout!(r.reg, r.idx, basis; time=nothing)
project_traceout!(r::RegRef, basis; time=nothing) = project_traceout!(r.reg, r.idx, basis; time)

function project_traceout!(f, reg::Register, i::Int, basis; time=nothing)
!isnothing(time) && uptotime!([reg], [i], time)
Expand All @@ -79,4 +79,4 @@
removebackref!(stateref, stateindex)
f(j)
end
project_traceout!(f, r::RegRef, basis; time=nothing) = project_traceout!(f, r.reg, r.idx, basis; time=nothing)
project_traceout!(f, r::RegRef, basis; time=nothing) = project_traceout!(f, r.reg, r.idx, basis; time)

Check warning on line 82 in src/baseops/traceout.jl

View check run for this annotation

Codecov / codecov/patch

src/baseops/traceout.jl#L82

Added line #L82 was not covered by tests
2 changes: 1 addition & 1 deletion src/concurrentsim.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function get_time_tracker(rn::RegisterNet)
return get_time_tracker(rn.registers[1])
end
function get_time_tracker(r::Register)
r.locks[1].env
r.locks[1].env::Simulation
end
function get_time_tracker(r::RegRef)
get_time_tracker(r.reg)
Expand Down
6 changes: 3 additions & 3 deletions src/states_registers_networks_getset.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
## Networks

# Graph interface
Graphs.add_vertex!(net::RegisterNet, a, b) = add_vertex!(net.graph, a, b)
Graphs.add_vertex!(net::RegisterNet) = add_vertex!(net.graph)

Check warning on line 11 in src/states_registers_networks_getset.jl

View check run for this annotation

Codecov / codecov/patch

src/states_registers_networks_getset.jl#L11

Added line #L11 was not covered by tests
Graphs.vertices(net::RegisterNet) = vertices(net.graph)
Graphs.edges(net::RegisterNet) = edges(net.graph)
Graphs.neighbors(net::RegisterNet, v) = neighbors(net.graph, v)
Expand Down Expand Up @@ -43,8 +43,8 @@
Base.getindex(net::RegisterNet, ::Colon) = net.registers
Base.getindex(net::RegisterNet, ::Colon, j::Int) = [r[j] for r in net.registers]
Base.getindex(net::RegisterNet, ::Colon, k::Symbol) = [m[k] for m in net.vertex_metadata]
Base.getindex(net::RegisterNet, ::Tuple{Colon,Colon}, k::Symbol) = [net.edge_metadata[minmax(ij)...][k] for ij in edges(net)]
Base.getindex(net::RegisterNet, ::Pair{Colon,Colon}, k::Symbol) = [net.directed_edge_metadata[ij][k] for ij in edges(net)]
Base.getindex(net::RegisterNet, ::Tuple{Colon,Colon}, k::Symbol) = [net.edge_metadata[minmax(Tuple(ij)...)][k] for ij in edges(net)]
Base.getindex(net::RegisterNet, ::Pair{Colon,Colon}, k::Symbol) = [net.directed_edge_metadata[Pair(ij)][k] for ij in edges(net)]

Check warning on line 47 in src/states_registers_networks_getset.jl

View check run for this annotation

Codecov / codecov/patch

src/states_registers_networks_getset.jl#L46-L47

Added lines #L46 - L47 were not covered by tests

function Base.setindex!(net::RegisterNet, v, ::Colon, k::Symbol)
for m in net.vertex_metadata
Expand Down
3 changes: 3 additions & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
GraphsMatching = "c3af3a8c-b79e-4b01-bf44-c718d7e0e0d6"
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
IterTools = "c8e1da08-722c-5040-9ed9-7db0dc04731e"
JET = "c3a54625-cd67-489e-a8e7-0a5a0ff4e31b"
JuMP = "4076af6c-e467-56ae-b986-b466b2749572"
JumpProcesses = "ccbc3e58-028d-4f4c-8cd5-9ae44345cda5"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
Expand All @@ -29,6 +31,7 @@ Revise = "295af30f-e4ad-537b-8983-00126c2a3abe"
SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f"
StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
SumTypes = "8e1ec7a9-0e02-4297-b0fe-6433085c89f2"
SymbolicUtils = "d1185830-fcd6-423d-90d6-eec64667417b"
Symbolics = "0c5d862f-8b57-4792-8d23-62f2024744c7"
TermInterface = "8ea1fca8-c5ef-4a55-8b96-4e9afe9c9a3c"
Expand Down
7 changes: 5 additions & 2 deletions test/test_jet.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Test
using QuantumSavory, JET
using DiffEqBase, Graphs, JumpProcesses, Makie, ResumableFunctions, ConcurrentSim, QuantumOptics, QuantumOpticsBase, QuantumClifford, Symbolics, WignerSymbols
using DiffEqBase, Graphs, JumpProcesses, Makie, ResumableFunctions, ConcurrentSim, QuantumOptics, QuantumOpticsBase, QuantumClifford, Symbolics, WignerSymbols, GraphsMatching, JuMP, SumTypes

rep = report_package("QuantumSavory";
ignored_modules=(
Expand All @@ -16,10 +16,13 @@ rep = report_package("QuantumSavory";
AnyFrameModule(ResumableFunctions),
AnyFrameModule(ConcurrentSim),
AnyFrameModule(WignerSymbols),
AnyFrameModule(GraphsMatching),
AnyFrameModule(JuMP.Containers),
AnyFrameModule(SumTypes),
))

@show length(JET.get_reports(rep))
@show rep

@test length(JET.get_reports(rep)) <= 85
@test length(JET.get_reports(rep)) <= 33
@test_broken length(JET.get_reports(rep)) == 0
Loading