Skip to content

Commit

Permalink
Add tests for entanglement_consumer
Browse files Browse the repository at this point in the history
  • Loading branch information
hanakl committed Sep 25, 2024
1 parent 66024d3 commit 9e628a5
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/ProtocolZoo/ProtocolZoo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ end
if isnothing(a_) || isnothing(b_)
if isnothing(prot.retry_lock_time)
@debug "EntanglerProt between $(prot.nodeA) and $(prot.nodeB)|round $(round): Failed to find free slots. \nGot:\n1. \t $a_ \n2.\t $b_ \n waiting..."
@yield lock(prot.nodeA.tag_waiter) | lock(prot.nodeB.tag_waiter)
@yield lock(prot.net[prot.nodeA]tag_waiter) | lock(prot.net[prot.nodeB].tag_waiter)
else
@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)
Expand Down Expand Up @@ -407,7 +407,7 @@ end
@debug "EntanglementConsumer between $(prot.nodeA) and $(prot.nodeB): query on first node found no entanglement"
if isnothing(prot.period)
@debug "Waiting on changes in $(prot.nodeA)"
@yield lock(prot.nodeA.tag_waiter)
@yield lock(prot.net[prot.nodeA].tag_waiter)
else
@yield timeout(prot.sim, prot.period)
end
Expand All @@ -418,7 +418,7 @@ end
@debug "EntanglementConsumer between $(prot.nodeA) and $(prot.nodeB): query on second node found no entanglement (yet...)"
if isnothing(prot.period)
@debug "Waiting on changes in $(prot.nodeB)"
@yield lock(prot.nodeB.tag_waiter)
@yield lock(prot.net[prot.nodeB].tag_waiter)
else
@yield timeout(prot.sim, prot.period)
end
Expand All @@ -442,7 +442,10 @@ end
push!(prot.log, (now(prot.sim), ob1, ob2))
unlock(q1)
unlock(q2)
@yield timeout(prot.sim, prot.period)
@yield timeout(prot.sim, 0.1)
if !isnothing(prot.period)
@yield timeout(prot.sim, prot.period)
end
end
end

Expand Down
48 changes: 48 additions & 0 deletions test/test_protocolzoo_entanglement_consumer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ using QuantumSavory
using QuantumSavory.ProtocolZoo: EntanglerProt, SwapperProt, EntanglementTracker, EntanglementConsumer
using Graphs
using ConcurrentSim
using ResumableFunctions
using Test

if isinteractive()
Expand Down Expand Up @@ -44,3 +45,50 @@ for n in 3:30
end

end

# test for period=nothing
for n in 3:30
println(n)
regsize = 10
net = RegisterNet([Register(regsize) for j in 1:n])
sim = get_time_tracker(net)

@resumable function delayedProts(sim)
@yield timeout(sim, 10)
for e in edges(net)
eprot = EntanglerProt(sim, net, e.src, e.dst; rounds=-1, randomize=true, margin=5, hardmargin=3)
@process eprot()
end

for v in 2:n-1
sprot = SwapperProt(sim, net, v; nodeL = <(v), nodeH = >(v), chooseL = argmin, chooseH = argmax, rounds = -1)
@process sprot()
end

for v in vertices(net)
etracker = EntanglementTracker(sim, net, v)
@process etracker()
end
end
econ = EntanglementConsumer(sim, net, 1, n; period=nothing)
@process econ()
@process delayedProts(sim)

run(sim, 1000)

@test econ.log[1][1] > 10 #the process should start after 10
for i in 1:length(econ.log)
@test econ.log[i][2] 1.0
@test econ.log[i][3] 1.0
end

end




@test econ.log[1][1] > 10 #the process should start after 10
for i in 1:length(econ.log)
@test econ.log[i][2] 1.0
@test econ.log[i][3] 1.0
end

0 comments on commit 9e628a5

Please sign in to comment.