From f99806bf3c7b2cbb5d6a74e69664045a46ef6500 Mon Sep 17 00:00:00 2001 From: Abhishek Bhatt Date: Sun, 22 Sep 2024 14:47:06 -0400 Subject: [PATCH] Minor updates --- src/ProtocolZoo/ProtocolZoo.jl | 24 +++++++++---- src/ProtocolZoo/controllers.jl | 4 +-- src/ProtocolZoo/swapping.jl | 4 +-- src/ProtocolZoo/utils.jl | 64 ++++++++++++++++++---------------- src/states_registers.jl | 1 + 5 files changed, 56 insertions(+), 41 deletions(-) diff --git a/src/ProtocolZoo/ProtocolZoo.jl b/src/ProtocolZoo/ProtocolZoo.jl index 0143ba7e..b49359bb 100644 --- a/src/ProtocolZoo/ProtocolZoo.jl +++ b/src/ProtocolZoo/ProtocolZoo.jl @@ -18,13 +18,16 @@ using Random export # protocols - EntanglerProt, SwapperProt, EntanglementTracker, EntanglementConsumer, CutoffProt, RequestTracker, + EntanglerProt, SwapperProt, EntanglementTracker, EntanglementConsumer, CutoffProt, RequestTracker, RequestGenerator, # tags - EntanglementCounterpart, EntanglementHistory, EntanglementUpdateX, EntanglementUpdateZ, EntanglementRequest, SwapRequest, + EntanglementCounterpart, EntanglementHistory, EntanglementUpdateX, EntanglementUpdateZ, EntanglementRequest, SwapRequest, DistributionRequest, RequestCompletion, # from Switches SimpleSwitchDiscreteProt, SwitchRequest, # controllers - NetController + NetController, Controller, + # utils + PhysicalGraph, path_selection + abstract type AbstractProtocol end get_time_tracker(prot::AbstractProtocol) = prot.sim @@ -563,6 +566,8 @@ end end end +include("utils.jl") + """ $TYPEDEF @@ -589,17 +594,25 @@ $TYPEDFIELDS λ::Int = 4 end +function RequestGenerator(sim, net, src, dst, controller, phys_graph; kwargs...) + return RequestGenerator(;sim, net, src, dst, controller, phys_graph, kwargs...) +end + @resumable function (prot::RequestGenerator)() - d = Exponential(inv(λ)) # Parametrized with the scale which is inverse of the rate + d = Exponential(inv(prot.λ)) # Parametrized with the scale which is inverse of the rate mb = messagebuffer(prot.net, prot.src) while true path_index = path_selection(prot.phys_graph) + if isnothing(path_index) + prot.phys_graph.failures[] += 1 + continue + end msg = Tag(DistributionRequest, prot.src, prot.dst, path_index) put!(channel(prot.net, prot.src=>prot.controller; permit_forward=true), msg) @yield timeout(prot.sim, rand(d)) # incoming message from the controller after a request has been served - in_msg = querydelete!(RequestCompletion, ❓) + in_msg = querydelete!(mb, RequestCompletion, ❓) if !isnothing(in_msg) (src, (_, path_id)) = in_msg prot.phys_graph.workloads[path_id] -= 1 @@ -611,7 +624,6 @@ end include("cutoff.jl") include("swapping.jl") include("controllers.jl") -include("utils.jl") include("switches.jl") using .Switches diff --git a/src/ProtocolZoo/controllers.jl b/src/ProtocolZoo/controllers.jl index 62d8fe0d..86ffe331 100644 --- a/src/ProtocolZoo/controllers.jl +++ b/src/ProtocolZoo/controllers.jl @@ -1,4 +1,4 @@ - """ +""" $TYPEDEF A network control protocol that is connection oriented, non-distributed and centralized. The generation of @@ -86,7 +86,7 @@ end msg = querydelete!(mb, DistributionRequest, ❓, ❓, ❓) if !isnothing(msg) (msg_src, (_, src, dst, path_ind)) = msg - path = phys_graph.paths[path_ind] + path = prot.phys_graph.paths[path_ind] @debug "Running Entanglement Distribution on path $(path) @ $(now(prot.sim))" for i in 1:length(path)-1 msg = Tag(EntanglementRequest, path[i], path[i+1], 1) diff --git a/src/ProtocolZoo/swapping.jl b/src/ProtocolZoo/swapping.jl index 83ef8158..e7897432 100644 --- a/src/ProtocolZoo/swapping.jl +++ b/src/ProtocolZoo/swapping.jl @@ -67,12 +67,12 @@ end xmeas, zmeas = swapcircuit(q1, q2) # send from here to new entanglement counterpart: # tag with EntanglementUpdateX past_local_node, past_local_slot_idx past_remote_slot_idx new_remote_node, new_remote_slot, correction - msg1 = Tag(EntanglementUpdateX, prot.node, q1.idx, tag1[3], tag2[2], tag2[3], xmeas) + msg1 = Tag(EntanglementUpdateX, prot.node, q1.idx, tag1[3], tag2[2], tag2[3], Int(xmeas)) put!(channel(prot.net, prot.node=>tag1[2]; permit_forward=true), msg1) @debug "SwapperProt @$(prot.node)|round $(round): Send message to $(tag1[2]) | message=`$msg1` | time = $(now(prot.sim))" # send from here to new entanglement counterpart: # tag with EntanglementUpdateZ past_local_node, past_local_slot_idx past_remote_slot_idx new_remote_node, new_remote_slot, correction - msg2 = Tag(EntanglementUpdateZ, prot.node, q2.idx, tag2[3], tag1[2], tag1[3], zmeas) + msg2 = Tag(EntanglementUpdateZ, prot.node, q2.idx, tag2[3], tag1[2], tag1[3], Int(zmeas)) put!(channel(prot.net, prot.node=>tag2[2]; permit_forward=true), msg2) @debug "SwapperProt @$(prot.node)|round $(round): Send message to $(tag2[2]) | message=`$msg2` | time = $(now(prot.sim))" @yield timeout(prot.sim, prot.local_busy_time) diff --git a/src/ProtocolZoo/utils.jl b/src/ProtocolZoo/utils.jl index 0bf01bde..d4bd7c9e 100644 --- a/src/ProtocolZoo/utils.jl +++ b/src/ProtocolZoo/utils.jl @@ -1,28 +1,3 @@ -function random_index(arr) - return rand(keys(arr)) -end - -""" -Find a qubit pair in a register that is suitable for performing a swap by [`SwapperProt`](@ref) according to the given predicate and choosing functions, satisfying the agelimit(if any) of the qubits -""" -function findswapablequbits(net, node, pred_low, pred_high, choose_low, choose_high; agelimit=nothing) - reg = net[node] - low_nodes = [ - n for n in queryall(reg, EntanglementCounterpart, pred_low, ❓; locked=false, assigned=true) - if isnothing(agelimit) || !isolderthan(n.slot, agelimit) - ] - high_nodes = [ - n for n in queryall(reg, EntanglementCounterpart, pred_high, ❓; locked=false, assigned=true) - if isnothing(agelimit) || !isolderthan(n.slot, agelimit) - ] - - (isempty(low_nodes) || isempty(high_nodes)) && return nothing - il = choose_low((n.tag[2] for n in low_nodes)) # TODO make [2] into a nice named property - ih = choose_high((n.tag[2] for n in high_nodes)) - return (low_nodes[il], high_nodes[ih]) -end - - """ $TYPEDEF @@ -35,27 +10,54 @@ $TYPEDFIELDS """The vector of paths between the user pair""" paths::Vector{Vector{Int}} """The vector containing the workload information of a path""" - workloads::Vec{Float64} + workloads::Vector{Int} """The number of slots available at each node. Scalar if all are same, vector otherwise.""" - capacity::Union{Vec{Int}, Int} + capacity::Union{Vector{Int}, Int} + """Number of failed requests due to high request traffic""" + failures::Ref{Int} end -function PhysicalGraph(graph::SimpleGraph{Int64}, src::Int, dst::Int, caps::Union{Vector{Int}, Int}) +function PhysicalGraph(graph::SimpleGraph{Int64}, src::Int, dst::Int, caps::Union{Vector{Int}, Int}; failures=Ref{Int}(0)) paths = sort(collect(all_simple_paths(graph, src, dst)); by = x->length(x)) workloads = zeros(length(paths)) - PhysicalGraph(paths, workloads, caps) + PhysicalGraph(paths, workloads, caps, failures) end """ A simple path selection algorithm for connection oriented networks. """ -function path_selection(phys_graph::PhysicalGraph) +function path_selection(phys_graph::PhysicalGraph) for i in 1:length(phys_graph.paths) capacity = isa(phys_graph.capacity, Number) ? phys_graph.capacity : phys_graph.capacity[i] if phys_graph.workloads[i]