Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Piecemaker #159

Draft
wants to merge 21 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
d8b724e
added new interactive example (no visualization yet) termed 'piecemaker'
Luisenden Sep 17, 2024
337fc92
added depolarization channel for stabilizer state repr and updated fi…
Luisenden Oct 1, 2024
39ae298
execute ghz generation only once, only entanglement generation should…
Luisenden Oct 4, 2024
54d9ad2
simple run finished, runs fusion protocol multiple times and collects…
Luisenden Oct 8, 2024
307fd09
updated README
Luisenden Oct 8, 2024
f7a3f47
adjustements in simulation setup and run script, noise applied after …
Luisenden Oct 31, 2024
8a14160
deleted init function, moved param value setting to run script
Luisenden Nov 6, 2024
0957cf6
changed GHZConsumer to FusionConsumer
Luisenden Nov 6, 2024
0aaeae1
deleted tag Piecemaker
Luisenden Nov 6, 2024
be08d75
reset project env in parent directory and added specific dependencies…
Luisenden Nov 6, 2024
81f12d1
deleted .DS_Store; updated local env
Luisenden Nov 6, 2024
cef2e06
updated readme
Luisenden Nov 6, 2024
467a314
Uptdated to event-driven implementation; added slot variables to Enta…
Luisenden Nov 21, 2024
77631f2
cleaned up code; deleted FusionSwitchDiscreteProtocol as it is not ne…
Luisenden Dec 3, 2024
e7d4349
deleted functions not in use (entangler functions and fusion function)
Luisenden Dec 3, 2024
5ab85ce
deleted .vscode
Luisenden Dec 3, 2024
46681bb
added explanation to tag FusionCounterpart
Luisenden Dec 3, 2024
badefaa
changed order of parameters in fusioncircuit to (control, target); ad…
Luisenden Dec 3, 2024
3a40643
extended function apply_noninstant! to work with depolarizing noise (…
Luisenden Dec 3, 2024
9a12dd6
updated readme
Luisenden Dec 4, 2024
751c5b1
updated readme
Luisenden Dec 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ Manifest.toml
build
.gitignore
ROADMAP.md
coverage
coverage
.DS_Store
3 changes: 3 additions & 0 deletions .vscode/settings.json
Copy link
Member

Choose a reason for hiding this comment

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

remove file

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"julia.environmentPath": "/Users/localadmin/Documents/github/QuantumSavory.jl/examples/piecemakerswitch"
}
2 changes: 1 addition & 1 deletion 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.6"
version = "0.6.0"

[deps]
Combinatorics = "861a8166-3701-5b0c-9a16-15d98fcdc6aa"
Expand Down
11 changes: 11 additions & 0 deletions examples/piecemakerswitch/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[deps]
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
ConcurrentSim = "6ed1e86c-fcaf-46a9-97e0-2b26a2cdb499"
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
NetworkLayout = "46757867-2c16-5918-afeb-47bfcb05e46a"
QuantumSavory = "2de2e421-972c-4cb5-a0c3-999c85908079"
ResumableFunctions = "c5292f4c-5179-55e1-98c5-05642aab7184"
Revise = "295af30f-e4ad-537b-8983-00126c2a3abe"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
52 changes: 52 additions & 0 deletions examples/piecemakerswitch/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# System Overview
A central switch node connects to **n** clients. The switch possesses **m = n + 1** qubit slots, while each client has a single qubit slot.

# Entanglement Initiation
At each clock tick, the switch initiates entanglement attempts with each of the **n** clients, resulting in **n** entanglement processes per cycle. Successful entanglement links are then merged into a GHZ (Greenberger–Horne–Zeilinger) state using an additional "piecemaker" qubit located in the \((n + 1)\)th slot of the switch node. This fusion process is assumed to occur instantaneously. Once all clients went through the fusion operation, the piecemaker qubit is measured out. This completes the fusing process and all nodes are sharing an n-GHZ state.

# Fusion Operation
The fusion operation consists of applying a **CNOT** gate followed by a measurement in the computational basis. This procedure allows the merging of two GHZ states into a single GHZ state, modulo any required Pauli corrections. We iterate over all existing entangled states with the switch node: in each iteration, the piecemaker qubit (initialized in the state \(|+\rangle\)) is fused with one of the existing entangled states.

# Noise
The memories residing the nodes' `Register`s suffer from depolarizing noise.

### Protocol flow

```mermaid
sequenceDiagram
participant Client1
participant ClientN

participant SwitchNode
participant Log

Note over Client1,SwitchNode: Round 1 (1 unit time)
par Entanglement Generation
Client1->>+SwitchNode: Try to generate entanglement
ClientN->>+SwitchNode: Try to generate entanglement
end

SwitchNode->>SwitchNode: Run fusions with successful clients

par Send Measurement Outcomes
SwitchNode-->>-Client1: Send measurement outcomes
SwitchNode-->>-ClientN: Send measurement outcomes
end

par Apply Corrections (No time cost)
Client1->>Client1: Apply correction gates
ClientN->>ClientN: Apply correction gates
end

loop Check Fusion Status (No time cost)
SwitchNode->>SwitchNode: Check if all clients are fused
alt All clients fused
SwitchNode->>SwitchNode: Measure piecemaker
SwitchNode->>SwitchNode: Compute fidelity to GHZ state
SwitchNode->>Log: Log fidelity and time
SwitchNode->>SwitchNode: Trigger STOP
else
SwitchNode->>SwitchNode: Keep checking
end
end
```
70 changes: 70 additions & 0 deletions examples/piecemakerswitch/setup.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
using QuantumSavory
using QuantumSavory.ProtocolZoo
using Graphs
using ConcurrentSim
using ResumableFunctions
using Distributions
using DataFrames
using CSV
using Profile
using NetworkLayout

@resumable function entangle_and_fuse(sim, net, client, link_success_prob)

# Set up the entanglement trackers at each client
tracker = EntanglementTracker(sim, net, client)
@process tracker()

# Set up the entangler and fuser protocols at each client
entangler = EntanglerProt(
sim=sim, net=net, nodeA=1, slotA=client-1, nodeB=client,
success_prob=link_success_prob, rounds=1, attempts=-1,
start_timer_after_first_attempt=true, # TODO: for some reason attempt_timeout=1 is not working, hardcoded in constructor for now
)
@yield @process entangler()

fuser = FusionProt(
sim=sim, net=net, node=1,
nodeC=client,
rounds=1
)
@yield @process fuser()
end


@resumable function run_protocols(sim, net, nclients, link_success_prob)
# Run entangler and fusion for each client and wait for all to finish
procs_succeeded = []
for k in 2:nclients+1
proc_succeeded = @process entangle_and_fuse(sim, net, k, link_success_prob)
push!(procs_succeeded, proc_succeeded)
end
@yield reduce(&, procs_succeeded)
end

function prepare_simulation(nclients=2, mem_depolar_prob = 0.1, link_success_prob = 0.5)

m = nclients+1 # memory slots in switch is equal to the number of clients + 1 slot for piecemaker qubit
r_depol = - log(1 - mem_depolar_prob) # depolarization rate

# The graph of network connectivity. Index 1 corresponds to the switch.
graph = star_graph(nclients+1)

switch_register = Register(m, Depolarization(1/r_depol)) # the first slot is reserved for the 'piecemaker' qubit used as fusion qubit
client_registers = [Register(1, Depolarization(1/r_depol)) for _ in 1:nclients] #Depolarization(1/r_depol)
net = RegisterNet(graph, [switch_register, client_registers...])
sim = get_time_tracker(net)

# Set up the initial |+> state of the piecemaker qubit
initialize!(net[1][m], X1)

# Run entangler and fusion for each client and wait for all to finish
@process run_protocols(sim, net, nclients, link_success_prob)

# Set up the consumer to measure final entangled state
consumer = FusionConsumer(net, net[1][m]; period=1)
@process consumer()

return sim, consumer
end

60 changes: 60 additions & 0 deletions examples/piecemakerswitch/simple_run.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
include("setup.jl")
using DataFrames
using CSV


# Set up the simulation parameters
name = "qs_piecemeal"
nruns = 1000
mem_depolar_prob = 0.1
link_success_prob = 0.5

results_per_client = DataFrame[]
for nclients in 2:9
# Prepare simulation data storage
distribution_times = Float64[]
fidelities = Float64[]
elapsed_times = Float64[]

# Run the simulation nruns times
for i in 1:nruns
sim, consumer = prepare_simulation(nclients, mem_depolar_prob, link_success_prob)
elapsed_time = @elapsed run(sim)
# Extract data from consumer.log
distribution_time, fidelity = consumer.log[1]
append!(distribution_times, distribution_time)
append!(fidelities, fidelity)
append!(elapsed_times, elapsed_time)
@info "Run $i completed"
end

# Fill the results DataFrame
results = DataFrame(
distribution_times = distribution_times,
fidelities = fidelities,
elapsed_times = elapsed_times
)
results.num_remote_nodes .= nclients
results.link_success_prob .= link_success_prob
results.mem_depolar_prob .= mem_depolar_prob
results.type .= name

push!(results_per_client, results)
@info "Clients $nclients completed"
end
results_total = vcat(results_per_client...)

# Group and summarize the data
grouped_df = groupby(results_total, [:num_remote_nodes, :distribution_times])
summary_df = combine(
grouped_df,
:fidelities => mean => :mean_fidelities,
:fidelities => std => :std_fidelities
)

@info summary_df

# Write results to CSV
# CSV.write("examples/piecemakerswitch/output/piecemaker-eventdriven.csv", results_total)
# CSV.write("examples/piecemakerswitch/output/piecemaker-eventdriven_summary.csv", summary_df)

12 changes: 11 additions & 1 deletion src/CircuitZoo/CircuitZoo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module CircuitZoo
using QuantumSavory
using DocStringExtensions

export EntanglementSwap, LocalEntanglementSwap,
export EntanglementFusion, EntanglementSwap, LocalEntanglementSwap,
Purify2to1, Purify2to1Node, Purify3to1, Purify3to1Node,
PurifyStringent, PurifyStringentNode, PurifyExpedient, PurifyExpedientNode,
SDDecode, SDEncode
Expand Down Expand Up @@ -46,6 +46,16 @@ end

inputqubits(::LocalEntanglementSwap) = 2

struct EntanglementFusion <: AbstractCircuit
end

function (::EntanglementFusion)(localq, piecemaker)
apply!((piecemaker, localq), CNOT)
zmeas = project_traceout!(localq, σᶻ)
zmeas
end

inputqubits(::EntanglementFusion) = 2
Copy link
Member

Choose a reason for hiding this comment

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

Can we add tests for the correctness of this circuit?

Copy link
Member

Choose a reason for hiding this comment

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

and a docstring


"""
$TYPEDEF
Expand Down
Loading