Skip to content

Commit

Permalink
switch to ConcurrentSim
Browse files Browse the repository at this point in the history
  • Loading branch information
Krastanov committed Jun 11, 2023
1 parent b7eae96 commit ff3ccf1
Show file tree
Hide file tree
Showing 16 changed files with 31 additions and 31 deletions.
2 changes: 1 addition & 1 deletion docs/Project.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[deps]
CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
ConcurrentSim = "6ed1e86c-fcaf-46a9-97e0-2b26a2cdb499"
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
DocumenterCitations = "daee34ce-89f3-4625-b898-19384cb65244"
Expand All @@ -15,7 +16,6 @@ QuantumOptics = "6e0679c1-51ea-5a7c-ac74-d61b76210b0c"
QuantumSavory = "2de2e421-972c-4cb5-a0c3-999c85908079"
ResumableFunctions = "c5292f4c-5179-55e1-98c5-05642aab7184"
Revise = "295af30f-e4ad-537b-8983-00126c2a3abe"
SimJulia = "428bdadb-6287-5aa5-874b-9969638295fd"
StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3"
ThreadTools = "dbf13d8f-d36e-4350-8970-f3a99faba1a8"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ For a convenient data structure to track per-node metadata in a graph (network)

Moreover, behind the scenes `QuantumSavory.jl` will use:

- `SimJulia.jl` for discrete event scheduling and simulation;
- `ConcurrentSim.jl` for discrete event scheduling and simulation;
- `Makie.jl` together with our custom plotting recipes for visualizations;
- `QuantumOptics.jl` for low-level quantum states.

Expand Down
10 changes: 5 additions & 5 deletions docs/src/howto/firstgenrepeater/firstgenrepeater.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ For a convenient data structure to track per-node metadata in a graph (network)

Moreover, behind the scenes `QuantumSavory.jl` will use:

- `SimJulia.jl` for discrete event scheduling and simulation;
- `ConcurrentSim.jl` for discrete event scheduling and simulation;
- `Makie.jl` together with our custom plotting recipes for visualizations;
- `QuantumOptics.jl` for low-level quantum states.

Expand All @@ -54,7 +54,7 @@ The `RegisterNet` would contain, on each node:

- a [`Register`](@ref) of the appropriate size;
- an array of tuples keeping track of whom each qubit in the register is entangled to (as the `:enttracker` property);
- an array of locks (from `SimJulia.jl`) keeping track of whether a process is happening on the given qubit (as the `:locks` property).
- an array of locks (from `ConcurrentSim.jl`) keeping track of whether a process is happening on the given qubit (as the `:locks` property).

!!! note
To see how to visualize these data structures as the simulation is proceeding, consult the [Visualizations](@ref Visualizations) page.
Expand Down Expand Up @@ -481,7 +481,7 @@ end
## Running the simulations

Now that we have defined the Entangler, Swapper, and Purifier processes, we just need to run the simulation.
That is no different from running any other `SimJulia.jl` simulation, after our custom setup:
That is no different from running any other `ConcurrentSim.jl` simulation, after our custom setup:

```julia
sizes = [2,3,4,3,2] # Number of qubits in each register
Expand Down Expand Up @@ -513,7 +513,7 @@ end
```

Then to run the simulation up to time `t` we just write `run(sim, t)`.
If we want to run until the next event, whenever that is, we can do `SimJulia.step(sim)`
If we want to run until the next event, whenever that is, we can do `ConcurrentSim.step(sim)`

## Figures of Merit and Visualizations

Expand Down Expand Up @@ -558,7 +558,7 @@ Many of the above functions take the `time` keyword argument, which ensures that

Of note is that we also used
`Makie.jl` for plotting,
`SimJulia.jl` for discrete event scheduling,
`ConcurrentSim.jl` for discrete event scheduling,
`QuantumClifford.jl` for efficient simulation of Clifford circuits,
and `QuantumOptics.jl` for convenient master equation integration.
Many of these tools were used under the hood without being invoked directly.
Expand Down
10 changes: 5 additions & 5 deletions docs/src/tutorial/message_queues.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ end
```

In network simulations, a convenient synchronization primitive is the passing of messages between nodes.
The `ResumableFunctions` and `SimJulia` libraries provide such primitives, convenient to use with `QuatumSavory`.
The `ResumableFunctions` and `ConcurrentSim` libraries provide such primitives, convenient to use with `QuatumSavory`.

Here we run through a simple example: there are two nodes that perform certain measurements. If the measurement result is the same, then the simulation ends. If the results differ, then we reset both nodes and try again. No actual physics will be simulated here (we will just generate some random numbers).

There are a number of convenient queue structures provided by these libraries. We will focus on `Store` and `DelayChannel` both of which are FILO stacks on which you can `put` messages or `get` messages.

We use `SimJulia`'s `@yield` and `@process` constructs to provide concurrency in our simulation.
We use `ConcurrentSim`'s `@yield` and `@process` constructs to provide concurrency in our simulation.

First we create a `Simulation` object (to track the fictitious simulation time and currently active simulated process) and create a few FILO stacks for `put`ting and `get`ting messages.

```@example messagechannel
using QuantumSavory
using ResumableFunctions
using SimJulia
using ConcurrentSim
using CairoMakie
sim = Simulation()
Expand Down Expand Up @@ -118,7 +118,7 @@ Finally, we schedule the two concurrent processes and run the simulation until s
@process process_node1(sim)
@process process_node2(sim)
SimJulia.run(sim)
ConcurrentSim.run(sim)
time_before_success = now(sim)
```

Expand Down Expand Up @@ -183,7 +183,7 @@ end
@process process_node1(sim)
@process process_node2(sim)
SimJulia.run(sim)
ConcurrentSim.run(sim)
fig = Figure()
ax = Axis(fig[1,1],xlabel="time")
Expand Down
2 changes: 1 addition & 1 deletion docs/src/visualizations.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ The [`resourceplot_axis`](@ref) function can be used to draw all locks and resou

```@example vis
using Graphs
using SimJulia
using ConcurrentSim
sim = Simulation()
Expand Down
2 changes: 1 addition & 1 deletion examples/colorcentermodularcluster/1_time_to_connected.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function run_until_connected(root_conf)
net, sim, observables, conf = prep_sim(root_conf)
# Run until all connections succeed
while !all([net[v,:link_register] for v in edges(net)])
SimJulia.step(sim)
ConcurrentSim.step(sim)
end
# Calculate fidelity of each cluster vertex
fid = map(vertices(net)) do v
Expand Down
2 changes: 1 addition & 1 deletion examples/colorcentermodularcluster/3_makie_interactive.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function run_until_connected(root_conf)
net, sim, observables, conf = prep_sim(root_conf)
# Run until all connections succeed
while !all([net[v,:link_register] for v in edges(net)])
SimJulia.step(sim)
ConcurrentSim.step(sim)
end
# Calculate fidelity of each cluster vertex
fid = map(vertices(net)) do v
Expand Down
4 changes: 2 additions & 2 deletions examples/colorcentermodularcluster/Project.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[deps]
ConcurrentSim = "6ed1e86c-fcaf-46a9-97e0-2b26a2cdb499"
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
JSServe = "824d6782-a2ef-11e9-3a09-e5662e0c26f9"
Expand All @@ -7,8 +8,7 @@ QuantumOptics = "6e0679c1-51ea-5a7c-ac74-d61b76210b0c"
QuantumSavory = "2de2e421-972c-4cb5-a0c3-999c85908079"
ResumableFunctions = "c5292f4c-5179-55e1-98c5-05642aab7184"
Revise = "295af30f-e4ad-537b-8983-00126c2a3abe"
SimJulia = "428bdadb-6287-5aa5-874b-9969638295fd"
WGLMakie = "276b4fcb-3e11-5398-bf8b-a0c2d153d008"

[compat]
JSServe = "2.2.3"
JSServe = "2.2.7"
4 changes: 2 additions & 2 deletions examples/colorcentermodularcluster/setup.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ using Graphs

# For discrete event simulation
using ResumableFunctions
using SimJulia
using ConcurrentSim

# For sampling from probability distributions
using Distributions
Expand Down Expand Up @@ -87,7 +87,7 @@ function prep_sim(root_conf)
# compute various derived constants for the simulation
conf = derive_conf(root_conf)

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

net[:, :espin_queue] = () -> Resource(sim,1)
Expand Down
2 changes: 1 addition & 1 deletion examples/firstgenrepeater/setup.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ using Graphs

# For discrete event simulation
using ResumableFunctions
using SimJulia
using ConcurrentSim

# Useful for interactive work
# Enables automatic re-compilation of modified codes
Expand Down
4 changes: 2 additions & 2 deletions ext/QuantumSavoryMakie/QuantumSavoryMakie.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module QuantumSavoryMakie
using QuantumSavory
using Graphs
using NetworkLayout
import SimJulia
import ConcurrentSim
import Makie
import Makie: Theme, Figure, Axis, @recipe
import QuantumSavory: registernetplot, registernetplot_axis, resourceplot_axis, showonplot
Expand Down Expand Up @@ -129,7 +129,7 @@ end

##

showonplot(r::SimJulia.Resource) = !isfree(r)
showonplot(r::ConcurrentSim.Resource) = !isfree(r)
showonplot(b::Bool) = b

"""Draw the various resources and locks stored in the given meta-graph on a given Makie axis.
Expand Down
2 changes: 1 addition & 1 deletion src/QuantumSavory.jl
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ include("noninstant.jl")
include("backends/quantumoptics/quantumoptics.jl")
include("backends/clifford/clifford.jl")

include("simjulia.jl")
include("concurrentsim.jl")

include("plots.jl")

Expand Down
8 changes: 4 additions & 4 deletions src/simjulia.jl → src/concurrentsim.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using ResumableFunctions
import SimJulia # Should be using
using SimJulia: Environment, request, release, now, active_process, timeout, Store, @process, Process, put, get
import ConcurrentSim # Should be using
using ConcurrentSim: Environment, request, release, now, active_process, timeout, Store, @process, Process, put, get
using Printf

export @simlog, isfree, nongreedymultilock, spinlock, DelayChannel
Expand Down Expand Up @@ -59,10 +59,10 @@ end
put(channel.store, value)
end

function SimJulia.put(channel::DelayChannel, value) # TODO rename to the ones from Base
function ConcurrentSim.put(channel::DelayChannel, value) # TODO rename to the ones from Base
@process latency(channel.store.env, channel, value) # results in the scheduling of all events generated by latency
end

function SimJulia.get(channel::DelayChannel) # TODO rename to the ones from Base
function ConcurrentSim.get(channel::DelayChannel) # TODO rename to the ones from Base
get(channel.store) # returns an element stored in the cable store
end
2 changes: 1 addition & 1 deletion test/Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[deps]
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
ConcurrentSim = "6ed1e86c-fcaf-46a9-97e0-2b26a2cdb499"
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
DiffEqBase = "2b5f629d-d688-5b77-993f-72d75c75574e"
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
Expand All @@ -23,7 +24,6 @@ RecursiveArrayTools = "731186ca-8d62-57ce-b412-fbd966d074cd"
ResumableFunctions = "c5292f4c-5179-55e1-98c5-05642aab7184"
Revise = "295af30f-e4ad-537b-8983-00126c2a3abe"
SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f"
SimJulia = "428bdadb-6287-5aa5-874b-9969638295fd"
StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
SymbolicUtils = "d1185830-fcd6-423d-90d6-eec64667417b"
Expand Down
4 changes: 2 additions & 2 deletions test/test_jet.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using QuantumSavory, JET
using DiffEqBase, Graphs, JumpProcesses, Makie, ResumableFunctions, SimJulia, QuantumOptics, QuantumOpticsBase, QuantumClifford, Symbolics, WignerSymbols
using DiffEqBase, Graphs, JumpProcesses, Makie, ResumableFunctions, ConcurrentSim, QuantumOptics, QuantumOpticsBase, QuantumClifford, Symbolics, WignerSymbols

using JET: ReportPass, BasicPass, InferenceErrorReport, UncaughtExceptionReport

Expand Down Expand Up @@ -30,7 +30,7 @@ rep = report_package("QuantumSavory";
AnyFrameModule(QuantumOpticsBase),
AnyFrameModule(QuantumClifford),
AnyFrameModule(ResumableFunctions),
AnyFrameModule(SimJulia),
AnyFrameModule(ConcurrentSim),
AnyFrameModule(WignerSymbols),
))

Expand Down
2 changes: 1 addition & 1 deletion test/test_plotting.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ display(fig)
##

using Graphs
using SimJulia
using ConcurrentSim
sim = Simulation()
for v in vertices(network)
network[v,:bool] = rand(Bool)
Expand Down

0 comments on commit ff3ccf1

Please sign in to comment.