Skip to content

Commit

Permalink
Add a connection-less and centralized protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
ba2tro committed Nov 8, 2024
1 parent 1a7bddb commit 859292e
Show file tree
Hide file tree
Showing 4 changed files with 208 additions and 5 deletions.
45 changes: 45 additions & 0 deletions examples/controlplane/3a_cl_interactive.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
include("setup.jl")

for (;src, dst) in edges(net)
entangler = EntanglerProt(sim, net, src, dst; rounds=-1, randomize=true)
@process entangler()
end

controller = CLController(sim, net, 6)
@process controller()

req_gen = RequestGenerator(sim, net, 1, 8, 6)
@process req_gen()

consumer = EntanglementConsumer(sim, net, 1, 8)
@process consumer()

for node in 1:7
tracker = RequestTracker(sim, net, node)
@process tracker()
end

for v in 1:8
tracker = EntanglementTracker(sim, net, v)
@process tracker()
end

for v in 1:8
c_prot = CutoffProt(sim, net, v)
@process c_prot()
end

sim, net, obs, entlog, entlogaxis, fid_axis, histaxis, num_epr_axis, fig = prepare_vis(consumer)

step_ts = range(0.0, 1000.0, step=0.1)
record(fig, "sim.mp4", step_ts; framerate=10, visible=true) do t
run(sim, t)
notify.((obs,entlog))
ylims!(entlogaxis, (-1.04,1.04))
xlims!(entlogaxis, max(0,t-50), 1+t)
ylims!(fid_axis, (0, 1.04))
xlims!(fid_axis, max(0, t-50), 1+t)
autolimits!(histaxis)
ylims!(num_epr_axis, (0, 4))
xlims!(num_epr_axis, max(0, t-50), 1+t)
end
112 changes: 112 additions & 0 deletions examples/controlplane/3b_cl_wglmakie.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
using WGLMakie
WGLMakie.activate!()
import Bonito
using Markdown

include("setup.jl")

const custom_css = Bonito.DOM.style("ul {list-style: circle !important;}") # TODO remove after fix of bug in JSServe https://github.com/SimonDanisch/JSServe.jl/issues/178

for (;src, dst) in edges(net)
entangler = EntanglerProt(sim, net, src, dst; rounds=-1, randomize=true)
@process entangler()
end

controller = CLController(sim, net, 6)
@process controller()

req_gen = RequestGenerator(sim, net, 1, 8, 6)
@process req_gen()

consumer = EntanglementConsumer(sim, net, 1, 8)
@process consumer()

for node in 1:7
tracker = RequestTracker(sim, net, node)
@process tracker()
end

for v in 1:8
tracker = EntanglementTracker(sim, net, v)
@process tracker()
end

for v in 1:8
c_prot = CutoffProt(sim, net, v)
@process c_prot()
end

# All the calls that happen in the main event loop of the simulation,
# encapsulated here so that we can conveniently pause the simulation from the WGLMakie app.
function continue_singlerun!(sim, obs, entlog, entlogaxis, fid_axis, histaxis, num_epr_axis, running)
step_ts = range(0, 1000, step=0.1)
for t in step_ts
run(sim, t)
notify.((obs,entlog))
ylims!(entlogaxis, (-1.04,1.04))
xlims!(entlogaxis, max(0,t-50), 1+t)
ylims!(fid_axis, (0, 1.04))
xlims!(fid_axis, max(0, t-50), 1+t)
autolimits!(histaxis)
ylims!(num_epr_axis, (0, 4))
xlims!(num_epr_axis, max(0, t-50), 1+t)
end
running[] = nothing
end

#
landing = Bonito.App() do

sim, net, obs, entlog, entlogaxis, fid_axis, histaxis, num_epr_axis, fig = prepare_vis(consumer)

running = Observable{Any}(false)
fig[5,1] = buttongrid = GridLayout(tellwidth = false)
buttongrid[1,1] = b = Makie.Button(fig, label = @lift(isnothing($running) ? "Done" : $running ? "Running..." : "Run once"), height=30, tellwidth=false)

on(b.clicks) do _
if !running[]
running[] = true
end
end
on(running) do r
if r
Threads.@spawn begin
continue_singlerun!(
sim, obs, entlog, entlogaxis, fid_axis, histaxis, num_epr_axis, running)
end
end
end


content = md"""
Pick simulation settings and hit run (see below for technical details).
$(fig.scene)
# Connection-Less, Non-Distributed and Centralized Control Plane for Entanglement Distribution
The above simulation visualizes entanglement distribution between Alice and Bob on an arbitrary network topology
given by the adjacency matrix of the graph. The control plane architecture used for this simulation is connection-less,
non-distributed and centralized. The node representing Alice is the node on the top left and the bottom right is Bob.
The actual connectivity of the physical graph isn't fully captured by the visualization above as we use edges only to
show the virtual graph.
[See and modify the code for this simulation on github.](https://github.com/QuantumSavory/QuantumSavory.jl/tree/master/examples/controlplane/3b_cl_wglmakie.jl)
"""
return Bonito.DOM.div(Bonito.MarkdownCSS, Bonito.Styling, custom_css, content)
end;

#
# Serve the Makie app

isdefined(Main, :server) && close(server);
port = parse(Int, get(ENV, "CNC_PORT", "8888"))
interface = get(ENV, "CNC_IP", "127.0.0.1")
proxy_url = get(ENV, "CNC_PROXY", "")
server = Bonito.Server(interface, port; proxy_url);
Bonito.HTTPServer.start(server)
Bonito.route!(server, "/" => landing);

##

wait(server)
6 changes: 3 additions & 3 deletions src/ProtocolZoo/ProtocolZoo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export
# from Switches
SimpleSwitchDiscreteProt, SwitchRequest,
# controllers
NetController, Controller,
NetController, Controller, CLController,
#utils
PathMetadata, path_selection

Expand Down Expand Up @@ -424,7 +424,7 @@ end
error("`EntanglementTracker` on node $(prot.node) received a message $(msg) that it does not know how to handle (due to the absence of corresponding `EntanglementCounterpart` or `EntanglementHistory` or `EntanglementDelete` tags). This might have happened due to `CutoffProt` deleting qubits while swaps are happening. Make sure that the retention times in `CutoffProt` are sufficiently larger than the `agelimit` in `SwapperProt`. Otherwise, this is a bug in the protocol and should not happen -- please report an issue at QuantumSavory's repository.")
end
end
# @debug "EntanglementTracker @$(prot.node): Starting message wait at $(now(prot.sim)) with MessageBuffer containing: $(mb.buffer)"
@debug "EntanglementTracker @$(prot.node): Starting message wait at $(now(prot.sim)) with MessageBuffer containing: $(mb.buffer)"
@yield wait(mb)
@debug "EntanglementTracker @$(prot.node): Message wait ends at $(now(prot.sim))"
end
Expand Down Expand Up @@ -543,7 +543,7 @@ end
end
end
end
# @debug "RequestTracker @$(prot.node): Starting message wait at $(now(prot.sim)) with MessageBuffer containing: $(mb.buffer)"
@debug "RequestTracker @$(prot.node): Starting message wait at $(now(prot.sim)) with MessageBuffer containing: $(mb.buffer)"
@yield wait(mb)
@debug "RequestTracker @$(prot.node): Message wait ends at $(now(prot.sim))"
end
Expand Down
50 changes: 48 additions & 2 deletions src/ProtocolZoo/controllers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ end
end

for i in 2:length(path)-1
last = i == length(path) - 1 ? 1 : 0
msg = Tag(SwapRequest, path[i], 1)
if prot.node == path[i]
put!(mb, msg)
Expand All @@ -113,7 +112,54 @@ end
end
end
end
# @debug "Controller @$(prot.node): Starting message wait at $(now(prot.sim)) with MessageBuffer containing: $(mb.buffer)"
@debug "Controller @$(prot.node): Starting message wait at $(now(prot.sim)) with MessageBuffer containing: $(mb.buffer)"
@yield wait(mb)
@debug "Controller @$(prot.node): Message wait ends at $(now(prot.sim))"
end
end
end


"""
$TYPEDEF
A network control protocol that is connection less, non-distributed and centralized. The controller is located at one of the nodes in the network from where it messages all
the other nodes' [`RequestTracker`](@ref) protocols when it receives [`DistributionRequest`](@ref) from the [`RequestGenerator`](@ref).
$TYPEDFIELDS
See also [`RequestGenerator`](@ref), [`RequestTracker`](@ref)
"""
@kwdef struct CLController <: AbstractProtocol
"""Time-and-schedule-tracking instance from `ConcurrentSim`"""
sim::Simulation
"""A network graph of registers"""
net::RegisterNet
"""The node in the network where the control protocol is physically located, ideally a centrally located node"""
node::Int
end

@resumable function (prot::CLController)()
mb = messagebuffer(prot.net, prot.node)
while true
workwasdone = true
while workwasdone
workwasdone = false
msg = querydelete!(mb, DistributionRequest, ❓, ❓)
if !isnothing(msg)
(msg_src, (_, req_src, req_dst)) = msg
for v in vertices(prot.net)
if v != req_src && v != req_dst
msg = Tag(SwapRequest, v, 1)
if prot.node == v
put!(mb, msg)
else
put!(channel(prot.net, prot.node=>msg[2];permit_forward=true), msg)
end
end
end
end
@debug "Controller @$(prot.node): Starting message wait at $(now(prot.sim)) with MessageBuffer containing: $(mb.buffer)"
@yield wait(mb)
@debug "Controller @$(prot.node): Message wait ends at $(now(prot.sim))"
end
Expand Down

0 comments on commit 859292e

Please sign in to comment.