Skip to content

Commit

Permalink
Remove isfree and add locks to each slot (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
Krastanov authored Aug 3, 2023
1 parent c2d155f commit 554db7e
Show file tree
Hide file tree
Showing 21 changed files with 221 additions and 99 deletions.
6 changes: 3 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "QuantumSavory"
uuid = "2de2e421-972c-4cb5-a0c3-999c85908079"
authors = ["Stefan Krastanov <[email protected]>"]
version = "0.2.1"
version = "0.3.0"

[deps]
ConcurrentSim = "6ed1e86c-fcaf-46a9-97e0-2b26a2cdb499"
Expand All @@ -28,7 +28,7 @@ Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
QuantumSavoryMakie = "Makie"

[compat]
ConcurrentSim = "1"
ConcurrentSim = "1.1"
Graphs = "1.7.3"
IterTools = "1.4.0"
Makie = "0.19"
Expand All @@ -38,7 +38,7 @@ QuantumClifford = "0.8"
QuantumInterface = "0.3.0"
QuantumOptics = "1.0.5"
QuantumOpticsBase = "0.4"
QuantumSymbolics = "0.2.0"
QuantumSymbolics = "0.2.3"
Reexport = "1.2.2"
ResumableFunctions = "0.6.1"
julia = "1.9"
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ registercoords = p_rg[:registercoords]
# Plots of various metadata and locks
_,_,_,obs_1 = resourceplot_axis(F[1,2],
net,
[:link_queue], [:espin_queue,:nspin_queue,:decay_queue];
[:link_queue], [:decay_queue];
registercoords=registercoords,
title="Processes and Queues")
_,_,_,obs_2 = resourceplot_axis(F[2,2],
Expand Down Expand Up @@ -59,7 +59,7 @@ display(F)
FRAMERATE = 10
tscale = conf[:T₂ⁿ]/3
step_ts = range(0, tscale, step=tscale/500)
record(F, "colorcentermodularcluster-02.simdashboard.mp4", step_ts, framerate=FRAMERATE) do t
record(F, "colorcentermodularcluster-02.simdashboard.mp4", step_ts, framerate=FRAMERATE, visible=true) do t
run(sim, t)

# calculate the fidelities for each node of the cluster state
Expand Down
6 changes: 3 additions & 3 deletions examples/colorcentermodularcluster/3_makie_interactive.jl
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ ensemble = App() do
Drag over the plot to select manual region to zoom in.
`Ctrl`+click resets the view.
Back at the [landing page](..) you can view multiple other ways to simulate and visualize this cluster state preparation experiment.
Back at the [landing page](./..) you can view multiple other ways to simulate and visualize this cluster state preparation experiment.
[See and modify the code for this simulation on github.](https://github.com/QuantumSavory/QuantumSavory.jl/tree/master/examples/colorcentermodularcluster)
"""
Expand Down Expand Up @@ -242,7 +242,7 @@ singletraj = App() do
# Plots of various metadata and locks
_,_,_,obs_1 = resourceplot_axis(F[1:3,2],
net,
[:link_queue], [:espin_queue,:nspin_queue,:decay_queue];
[:link_queue], [:decay_queue];
registercoords=registercoords,
title="Processes and Queues")
_,_,_,obs_2 = resourceplot_axis(F[4:6,2],
Expand Down Expand Up @@ -321,7 +321,7 @@ singletraj = App() do
$(config_str)
Back at the [landing page](..) you can view multiple other ways to simulate and visualize this cluster state preparation experiment.
Back at the [landing page](./..) you can view multiple other ways to simulate and visualize this cluster state preparation experiment.
[See and modify the code for this simulation on github.](https://github.com/QuantumSavory/QuantumSavory.jl/tree/master/examples/colorcentermodularcluster)
"""
Expand Down
22 changes: 10 additions & 12 deletions examples/colorcentermodularcluster/setup.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ end
@resumable function barrettkok(env::Environment, net, nodea, nodeb, conf)
# check whether this link is already being attempted
link_resource = net[(nodea, nodeb), :link_queue]
!isfree(link_resource) && return
islocked(link_resource) && return
# if not, reserve both electronic spins, by using a nongreedy multilock
spin_resources = [net[nodea, :espin_queue], net[nodeb, :espin_queue]]
espin_slots = [net[nodea, 1], net[nodeb, 1]]
@yield request(link_resource)
@yield @process nongreedymultilock(env, spin_resources)
@yield @process nongreedymultilock(env, espin_slots)
# wait for a successful entangling attempt (separate attempts not modeled explicitly)
rega = net[nodea]
regb = net[nodeb]
Expand All @@ -56,8 +56,8 @@ end
@yield timeout(env, duration)
bk_el_init(env, rega, regb, conf)
# reserve the nuclear spins, by using a nongreedy multilock
nspin_resources = [net[nodea, :nspin_queue], net[nodeb, :nspin_queue]]
@yield @process nongreedymultilock(env, nspin_resources)
nspin_slots = [net[nodea, 2], net[nodeb, 2]]
@yield @process nongreedymultilock(env, nspin_slots)
# wait for the two parallel swaps from the electronic to nuclear spins
@yield timeout(env, conf[:τˢʷᵃᵖ])
r1 = bk_swap(env, rega, conf)
Expand All @@ -69,8 +69,8 @@ end
# register that we believe an entanglement was established
net[(nodea, nodeb), :link_register] = true
# release locks
release.(nspin_resources)
release.(spin_resources)
release.(nspin_slots)
release.(espin_slots)
release(link_resource)
#@simlog env "success on $(nodea) $(nodeb) after $(attempts) attempt(s) $(duration)"
end
Expand All @@ -88,12 +88,10 @@ function prep_sim(root_conf)
conf = derive_conf(root_conf)

# set up ConcurrentSim discrete events simulation
sim = Simulation()
sim = get_time_tracker(net)

net[:, :espin_queue] = () -> Resource(sim,1)
net[:, :nspin_queue] = () -> Resource(sim,1)
net[:, :decay_queue] = () -> Resource(sim,1)
net[(:,:), :link_queue] = () -> Resource(sim,1)
net[:, :decay_queue] = () -> Resource(sim)
net[(:,:), :link_queue] = () -> Resource(sim)
net[(:,:), :link_register] = false

for (;src,dst) in edges(net)
Expand Down
4 changes: 2 additions & 2 deletions examples/congestionchain/1_visualization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ regsize = 2 # Number of qubits in each register
T2 = 100.0 # T2 dephasing time of all qubits
F = 0.97 # Fidelity of the raw Bell pairs
entangler_wait_time = 0.1 # How long to wait if all qubits are busy before retring entangling
entangler_busy_λinv = 0.5 # How long it takes to establish a newly entangled pair (Exponential distribution parameter)
entangler_busy_λ = 0.5 # How long it takes to establish a newly entangled pair (Exponential distribution parameter)
swapper_wait_time = 0.1 # How long to wait if all qubits are unavailable for swapping
swapper_busy_time = 0.55 # How long it takes to swap two qubits
consume_wait_time = 0.1 # How long to wait if there are no qubits ready for consumption
Expand All @@ -20,7 +20,7 @@ sim, network = simulation_setup(len, regsize, T2)

noisy_pair = noisy_pair_func(F)
for (;src, dst) in edges(network)
@process entangler(sim, network, src, dst, noisy_pair, entangler_wait_time, 1/entangler_busy_λinv)
@process entangler(sim, network, src, dst, noisy_pair, entangler_wait_time, entangler_busy_λ)
end

for node in vertices(network)
Expand Down
10 changes: 5 additions & 5 deletions examples/congestionchain/2_makie_interactive.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function prepare_singlerun(
T2 = 100.0, # T2 dephasing time of all qubits
F = 0.97, # Fidelity of the raw Bell pairs
entangler_wait_time = 0.1, # How long to wait if all qubits are busy before retring entangling
entangler_busy_λinv = 0.5, # How long it takes to establish a newly entangled pair (Exponential distribution parameter)
entangler_busy_λ = 0.5, # How long it takes to establish a newly entangled pair (Exponential distribution parameter)
swapper_wait_time = 0.1, # How long to wait if all qubits are unavailable for swapping
swapper_busy_time = 0.55, # How long it takes to swap two qubits
consume_wait_time = 0.1, # How long to wait if there are no qubits ready for consumption
Expand All @@ -27,7 +27,7 @@ function prepare_singlerun(

noisy_pair = noisy_pair_func(F)
for (;src, dst) in edges(network)
@process entangler(sim, network, src, dst, noisy_pair, entangler_wait_time, 1/entangler_busy_λinv)
@process entangler(sim, network, src, dst, noisy_pair, entangler_wait_time, entangler_busy_λ)
end

for node in vertices(network)
Expand Down Expand Up @@ -131,7 +131,7 @@ function add_conf_sliders(fig)
:regsize => 2,
:T2 => 100.0,
:F => 0.97,
:entangler_busy_λinv => 0.5,
:entangler_busy_λ => 0.5,
:swapper_busy_time => 0.5
)
conf_obs = Observable(conf)
Expand All @@ -148,15 +148,15 @@ function add_conf_sliders(fig)
(label = "fidelity of raw pairs",
range = 0.6:0.01:1.0, format = "{:.2f}", startvalue = conf[:F]),
(label = "avg. time of ent. generation",
range = 0.05:0.05:1.0, format = "{:.2f}", startvalue = conf[:entangler_busy_λinv]),
range = 0.05:0.05:1.0, format = "{:.2f}", startvalue = conf[:entangler_busy_λ]),
(label = "swap duration",
range = 0.05:0.05:1.0, format = "{:.2f}", startvalue = conf[:swapper_busy_time]),
width = 600,
#tellheight = false
)

# TODO there should be a nicer way to link sliders to the configuration
names = [:len, :regsize, :T2, :F, :entangler_busy_λinv, :swapper_busy_time]
names = [:len, :regsize, :T2, :F, :entangler_busy_λ, :swapper_busy_time]
for (name,slider) in zip(names,sg.sliders)
on(slider.value) do val
conf_obs[][name] = val
Expand Down
78 changes: 78 additions & 0 deletions examples/congestionchain/3_aggregate_of_multiple_simulations.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
include("setup.jl")

using GLMakie # For plotting
GLMakie.activate!(inline=false)

##
# Demo visualizations of the performance of the network
##

function prepare_singlerun(
;
len = 5, # Number of registers in the chain
regsize = 2, # Number of qubits in each register
T2 = 100.0, # T2 dephasing time of all qubits
F = 0.97, # Fidelity of the raw Bell pairs
entangler_wait_time = 0.1, # How long to wait if all qubits are busy before retring entangling
entangler_busy_λ = 0.5, # How long it takes to establish a newly entangled pair (Exponential distribution parameter)
swapper_wait_time = 0.1, # How long to wait if all qubits are unavailable for swapping
swapper_busy_time = 0.55, # How long it takes to swap two qubits
consume_wait_time = 0.1, # How long to wait if there are no qubits ready for consumption
)
sim, network = simulation_setup(len, regsize, T2)

noisy_pair = noisy_pair_func(F)
for (;src, dst) in edges(network)
@process entangler(sim, network, src, dst, noisy_pair, entangler_wait_time, entangler_busy_λ)
end

for node in vertices(network)
@process swapper(sim, network, node, swapper_wait_time, swapper_busy_time)
end

ts = Ref(Float64[])
fidXX = Ref(Float64[])
fidZZ = Ref(Float64[])
@process consumer(sim, network, 1, len, consume_wait_time,ts,fidXX,fidZZ)

sim, network, ts, fidXX, fidZZ
end

##

link_lengths = 3:40 # change the range of chain lengths being simulated
results = Vector{Any}(undef,length(link_lengths))

Threads.@threads for i in eachindex(link_lengths)
conf = Dict( # change the settings here
:len => link_lengths[i],
:regsize => 2,
:T2 => 100.0,
:F => 0.97,
:entangler_busy_λ => 0.5,
:swapper_busy_time => 0.5
)
sim, network, ts, fidXX, fidZZ = prepare_singlerun(; conf...)
run(sim, 1000) # run for 1000 time units
results[i] = (ts, fidXX, fidZZ)
@info "Finished run $(i) of $(length(link_lengths)) -- the chain length was $(link_lengths[i])"
end

##

avgt = [mean(res[1][]) for res in results]
avgxx = [mean(res[2][]) for res in results]
avgzz = [mean(res[3][]) for res in results]

F = Figure(resolution=(600,600))
ax1 = Axis(F[1,1], ylabel="avg time to connection")
scatter!(ax1, link_lengths, avgt)
ylims!(ax1,0,nothing)
ax2 = Axis(F[2,1], ylabel="XX Stabilizer\nExpectation")
scatter!(ax2, link_lengths, avgxx)
ylims!(ax2,0,1)
ax3 = Axis(F[3,1], ylabel="ZZ Stabilizer\nExpectation", xlabel="chain length")
scatter!(ax3, link_lengths, avgzz)
ylims!(ax3,0,1)
save("stats_vs_chainlength.png", F)
display(F)
3 changes: 2 additions & 1 deletion examples/congestionchain/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ A simple, more instructive, example is also

The `setup.jl` file implements all necessary base functionality.
The other files run the simulation and generate visuals in a number of different circumstances:
1. A single simulator script convenient for exploratory coding;
1. A single simulator script convenient for exploratory coding, running one single Monte Carlo simulation of a repeater chain;
2. A web-app version of the simulator;
3. A script running thousands of simulations like the ones in point 1, followed by plotting average statistical results for these simulations for a variety of repeater chain lengths.
Loading

2 comments on commit 554db7e

@Krastanov
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/88920

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.3.0 -m "<description of version>" 554db7eb6be2171738f718a021e48fd5f02337f4
git push origin v0.3.0

Please sign in to comment.