Skip to content

Commit c140625

Browse files
committed
first round of fixes to cutoff
1 parent 453e196 commit c140625

File tree

3 files changed

+67
-5
lines changed

3 files changed

+67
-5
lines changed

src/ProtocolZoo/cutoff.jl

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ end
3434

3535
@resumable function (prot::CutoffProt)()
3636
reg = prot.net[prot.node]
37+
<<<<<<< HEAD
3738
while true
3839
for slot in reg # TODO these should be done in parallel, otherwise we will be waiting on each slot, greatly slowing down the cutoffs
3940
islocked(slot) && continue
@@ -74,5 +75,57 @@ end
7475
else
7576
@yield timeout(prot.sim, prot.period::Float64)
7677
end
78+
=======
79+
for slot in reg
80+
@process per_slot_cutoff(prot.sim, slot, prot)
81+
end
82+
end
83+
84+
@resumable function per_slot_cutoff(sim, slot::RegRef, prot::CutoffProt)
85+
empty_query = false
86+
while true
87+
if empty_query
88+
if isnothing(prot.period)
89+
@yield onchange_tag(slot) # TODO this should be just for the slot, not for the whole register
90+
else
91+
@yield timeout(prot.sim, prot.period::Float64)
92+
end
93+
end
94+
@yield lock(slot)
95+
info = query(slot, EntanglementCounterpart, ❓, ❓)
96+
if isnothing(info)
97+
empty_query = true
98+
unlock(slot)
99+
continue
100+
end
101+
println("$(now(sim)) $slot info $info")
102+
103+
if now(prot.sim) - info.time > prot.retention_time
104+
untag!(slot, info.id)
105+
traceout!(slot)
106+
println("$(now(sim)) $slot traced out")
107+
msg = Tag(EntanglementDelete, prot.node, slot.idx, info.tag[2], info.tag[3])
108+
tag!(slot, msg)
109+
(prot.announce) && put!(channel(prot.net, prot.node=>msg[4]; permit_forward=true), msg)
110+
@debug "CutoffProt @$(prot.node): Send message to $(msg[4]) | message=`$msg` | time=$(now(prot.sim))"
111+
end
112+
113+
# TODO the tag deletions below are not necessary when announce=true and EntanglementTracker is running on other nodes. Verify the veracity of that statement, make tests for both cases, and document.
114+
115+
# delete old history tags
116+
info = query(slot, EntanglementHistory, ❓, ❓, ❓, ❓, ❓;filo=false) # TODO we should have a warning if `queryall` returns more than one result -- what does it even mean to have multiple history tags here
117+
if !isnothing(info) && now(prot.sim) - info.time > prot.retention_time
118+
untag!(slot, info.id)
119+
end
120+
121+
# delete old EntanglementDelete tags
122+
# TODO Why do we have separate entanglementhistory and entanglementupdate but we have only a single entanglementdelete that serves both roles? We should probably have both be pairs of tags, for consistency and ease of reasoning
123+
info = query(slot, EntanglementDelete, prot.node, slot.idx , ❓, ❓) # TODO we should have a warning if `queryall` returns more than one result -- what does it even mean to have multiple delete tags here
124+
if !isnothing(info) && now(prot.sim) - info.time > prot.retention_time
125+
untag!(slot, info.id)
126+
end
127+
128+
unlock(slot)
129+
>>>>>>> e5a26b4d (first round of fixes to cutoff)
77130
end
78131
end

src/queries.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -363,15 +363,15 @@ tag!(tagcontainer, args...) = tag!(tagcontainer, Tag(args...))
363363
function _query(reg::RegOrRegRef, ::Val{allB}, ::Val{filoB}, query::Tag; locked::Union{Nothing,Bool}=nothing, assigned::Union{Nothing,Bool}=nothing) where {allB, filoB}
364364
ref = isa(reg, RegRef) ? reg : nothing
365365
reg = get_register(reg)
366-
res = NamedTuple{(:slot, :id, :tag), Tuple{RegRef, Int128, Tag}}[]
366+
res = NamedTuple{(:slot, :id, :tag, :time), Tuple{RegRef, Int128, Tag, Float64}}[]
367367
l = length(reg.guids)
368368
indices = filoB ? (l:-1:1) : (1:l)
369369
for i in indices
370370
i = reg.guids[i]
371-
tag = reg.tag_info[i].tag
371+
(;tag, time) = reg.tag_info[i]
372372
slot = reg[reg.tag_info[i].slot]
373373
if _nothingor(ref, slot) && _nothingor(locked, islocked(slot)) && _nothingor(assigned, isassigned(slot)) && tag==query
374-
allB ? push!(res, (slot=slot, id=i, tag=tag)) : return (slot=slot, id=i, tag=tag)
374+
allB ? push!(res, (;slot, id=i, tag, time)) : return (;slot, id=i, tag, time)
375375
end
376376
end
377377
allB ? res : nothing

test/test_protocolzoo_entanglement_tracker_grid.jl

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,14 @@ end
229229
# More tests of 2D rectangular grids with the full stack of protocols,
230230
# but also now with an unlimited number of rounds and an entanglement consumer.
231231

232+
using Test
233+
using Revise
234+
using ResumableFunctions
235+
using ConcurrentSim
236+
using QuantumSavory
237+
using QuantumSavory.ProtocolZoo
238+
using QuantumSavory.ProtocolZoo: EntanglementCounterpart, EntanglementHistory, EntanglementUpdateX, EntanglementUpdateZ
239+
using Graphs
232240

233241
n = 6 # the size of the square grid network (n × n)
234242
regsize = 20 # the size of the quantum registers at each node
@@ -267,9 +275,10 @@ consumer = EntanglementConsumer(sim, net, 1, n^2)
267275
# at each node we discard the qubits that have decohered after a certain cutoff time
268276
for v in vertices(net)
269277
cutoffprot = CutoffProt(sim, net, v, retention_time=10, period=nothing)
270-
@process cutoffprot()
278+
#@process cutoffprot()
271279
end
272-
@test_broken (run(sim, 400); true)
280+
#@test_broken (run(sim, 400); true)
281+
run(sim, 400)
273282

274283
for i in 1:length(consumer._log)
275284
@test consumer._log[i][2] 1.0

0 commit comments

Comments
 (0)