Skip to content

Commit

Permalink
use self referencing functors (#109)
Browse files Browse the repository at this point in the history
With JuliaDynamics/ResumableFunctions.jl/issues/77 fixed we can use the callable structs normally
  • Loading branch information
ba2tripleO authored Feb 27, 2024
1 parent 2b91fc2 commit bc8cca2
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/ProtocolZoo/ProtocolZoo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ abstract type AbstractProtocol end

get_time_tracker(prot::AbstractProtocol) = prot.sim

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

@kwdef struct EntanglementCounterpart
remote_node::Int
Expand Down Expand Up @@ -108,8 +108,7 @@ end

#TODO """Convenience constructor for specifying `fidelity` of generation instead of success probability and time"""

@resumable function (prot::EntanglerProt)(;_prot::EntanglerProt=prot)
prot = _prot # weird workaround for no support for `struct A a::Int end; @resumable function (fa::A) return fa.a end`; see https://github.com/JuliaDynamics/ResumableFunctions.jl/issues/77
@resumable function (prot::EntanglerProt)()
rounds = prot.rounds
while rounds != 0
a = findfreeslot(prot.net[prot.nodeA], randomize=prot.randomize)
Expand Down Expand Up @@ -177,8 +176,7 @@ function SwapperProt(sim::Simulation, net::RegisterNet, node::Int; kwargs...)
return SwapperProt(;sim, net, node, kwargs...)
end

@resumable function (prot::SwapperProt)(;_prot::SwapperProt=prot)
prot = _prot # weird workaround for no support for `struct A a::Int end; @resumable function (fa::A) return fa.a end`; see https://github.com/JuliaDynamics/ResumableFunctions.jl/issues/77
@resumable function (prot::SwapperProt)()
rounds = prot.rounds
while rounds != 0
reg = prot.net[prot.node]
Expand Down Expand Up @@ -248,8 +246,7 @@ $FIELDS
node::Int
end

@resumable function (prot::EntanglementTracker)(;_prot::EntanglementTracker=prot)
prot = _prot # weird workaround for no support for `struct A a::Int end; @resumable function (fa::A) return fa.a end`; see https://github.com/JuliaDynamics/ResumableFunctions.jl/issues/77
@resumable function (prot::EntanglementTracker)()
nodereg = prot.net[prot.node]
mb = messagebuffer(prot.net, prot.node)
while true
Expand Down

0 comments on commit bc8cca2

Please sign in to comment.