From 3ccd676b51555b41d9c4c18895c11b35a4f02fa7 Mon Sep 17 00:00:00 2001 From: Abhishek Bhatt <46929125+ba2tro@users.noreply.github.com> Date: Wed, 23 Oct 2024 21:29:42 -0400 Subject: [PATCH] =?UTF-8?q?Make=20classical=20and=20quantum=20channel=20de?= =?UTF-8?q?lays=20customizable=20when=20initializ=E2=80=A6=20(#162)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --------- Co-authored-by: Stefan Krastanov Co-authored-by: Stefan Krastanov --- CHANGELOG.md | 4 ++++ Project.toml | 2 +- src/networks.jl | 18 +++++++++--------- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 557de55b..09480f72 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # News +## v0.5.1-dev + +- Add `classical_delay` and `quantum_delay` as keyword arguments to the `RegisterNet` constructor to set a default global network edge latency. + ## v0.5.0 - 2024-10-16 - Develop `CutoffProt` to deal with deadlocks in a simulation diff --git a/Project.toml b/Project.toml index ac7091b5..2789bda5 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "QuantumSavory" uuid = "2de2e421-972c-4cb5-a0c3-999c85908079" authors = ["Stefan Krastanov "] -version = "0.5" +version = "0.5.1-dev" [deps] Combinatorics = "861a8166-3701-5b0c-9a16-15d98fcdc6aa" diff --git a/src/networks.jl b/src/networks.jl index a10dc369..620030b8 100644 --- a/src/networks.jl +++ b/src/networks.jl @@ -13,7 +13,7 @@ struct RegisterNet reverse_lookup::IdDict{Register,Int} end -function RegisterNet(graph::SimpleGraph, registers, vertex_metadata, edge_metadata, directed_edge_metadata) +function RegisterNet(graph::SimpleGraph, registers, vertex_metadata, edge_metadata, directed_edge_metadata; classical_delay=0, quantum_delay=0) env = get_time_tracker(registers[1]) all_are_at_zero = all(iszero(ConcurrentSim.now(get_time_tracker(r))) && isempty(get_time_tracker(r).heap) && isnothing(get_time_tracker(r).active_proc) for r in registers) @@ -42,10 +42,10 @@ function RegisterNet(graph::SimpleGraph, registers, vertex_metadata, edge_metada end for (;src,dst) in edges(graph) - cchannels[src=>dst] = DelayQueue{Tag}(env, 0) - qchannels[src=>dst] = QuantumChannel(env, 0) - cchannels[dst=>src] = DelayQueue{Tag}(env, 0) - qchannels[dst=>src] = QuantumChannel(env, 0) + cchannels[src=>dst] = DelayQueue{Tag}(env, classical_delay) + qchannels[src=>dst] = QuantumChannel(env, quantum_delay) + cchannels[dst=>src] = DelayQueue{Tag}(env, classical_delay) + qchannels[dst=>src] = QuantumChannel(env, quantum_delay) end for (v,r) in zip(vertices(graph), registers) channels = [(;src=w, channel=cchannels[w=>v]) for w in neighbors(graph, v)] @@ -92,9 +92,9 @@ julia> neighbors(net, 1) # from Graphs.jl 3 ``` """ -function RegisterNet(graph::SimpleGraph, registers) +function RegisterNet(graph::SimpleGraph, registers; classical_delay=0, quantum_delay=0) size(graph, 1) == length(registers) || ArgumentError(lazy"You attempted to construct a `RegisterNet` with a graph of $(size(graph, 1)) vertices but provided a list of $(length(registers)) `Registers`. These two numbers have to match.") - RegisterNet(graph, registers, empty_vmd(length(registers)), empty_emd(), empty_demd()) + RegisterNet(graph, registers, empty_vmd(length(registers)), empty_emd(), empty_demd(); classical_delay, quantum_delay) end empty_vmd(n) = [Dict{Symbol,Any}() for _ in 1:n] @@ -113,9 +113,9 @@ julia> neighbors(net,2) # from Graphs.jl 3 ``` """ -function RegisterNet(registers::Vector{Register}) +function RegisterNet(registers::Vector{Register}; classical_delay=0, quantum_delay=0) graph = grid([length(registers)]) - RegisterNet(graph, registers) + RegisterNet(graph, registers; classical_delay, quantum_delay) end function add_register!(net::RegisterNet, r::Register)