Skip to content

Commit 475d941

Browse files
committed
example threading
1 parent d6649b6 commit 475d941

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

examples/Honeycomb/simulation.jl

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,33 @@
1-
function simulate_QuantumClifford(L,n=10;shots=10,depth=10)
1+
function simulate_QuantumClifford(L,n=10;shots=10,depth=10,type=:Kitaev)
22
g = HoneycombGeometry(Periodic, L, L)
3-
ps = generateProbs(;n)
4-
backend = QuantumClifford.TableauSimulator(nQubits(g); mixed=true)
3+
ps = generateProbs(;n, offset=0.01)
4+
55

66
partitionsX = subsystems(g, 4; cutType=:X)
77
partitionsY = subsystems(g, 4; cutType=:Y)
88
partitionsZ = subsystems(g, 4; cutType=:Z)
99

1010
tmi = zeros(Float64, length(ps))
11-
for (i, (px,py,pz)) in enumerate(ps)
11+
Threads.@threads for i in eachindex(ps)
12+
px,py,pz = ps[i]
13+
backend = QuantumClifford.TableauSimulator(nQubits(g); mixed=true)
1214
post = (s) -> begin
1315
tmi[i] += QuantumClifford.tmi(backend.state, partitionsX)
1416
tmi[i] += QuantumClifford.tmi(backend.state, partitionsY)
1517
tmi[i] += QuantumClifford.tmi(backend.state, partitionsZ)
1618
end
17-
execute!(()->measurementOnlyKitaev!(backend, g, px,py,pz; depth), backend, post; shots=shots)
19+
if type == :Kitaev
20+
execute!(()->measurementOnlyKitaev!(backend, g, px,py,pz; depth), backend, post; shots=shots)
21+
elseif type == :Kekule
22+
execute!(()->measurementOnlyKekule!(backend, g, px,py,pz; depth), backend, post; shots=shots)
23+
else
24+
throw(ArgumentError("Unsupported type $type. Choose one of :Kitaev, :Kekule"))
25+
end
1826
end
1927
return tmi ./= 3shots
2028
end
2129

22-
function generateProbs(; n=45)
30+
function generateProbs(; n=45,offset=0.0)
2331
points = Vector{NTuple{3,Float64}}(undef, n*(n + 1) ÷ 2)
2432
m = 1
2533
for (k, i) in enumerate(range(0, 1, n))
@@ -32,5 +40,5 @@ function generateProbs(; n=45)
3240
end
3341
end
3442

35-
return points
43+
return [p .- offset .* (p .- (1 / 3, 1 / 3, 1 / 3)) for p in points]
3644
end

examples/TransverseFieldIsingFibonacci/simulation.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
using MonitoredQuantumCircuits
12
function simulate_QuantumClifford(L,ps;shots=10,depth=10)
23
g = ChainGeometry(Periodic, L)
3-
backend = QuantumClifford.TableauSimulator(nQubits(g); mixed=false, basis=:X)
4+
45

56
entanglement = zeros(Float64, length(ps))
6-
for (i, p) in enumerate(ps)
7+
Threads.@threads for i in eachindex(ps)
8+
backend = QuantumClifford.TableauSimulator(nQubits(g); mixed=false, basis=:X)
9+
p = ps[i]
710
post = (s) -> begin
811
entanglement[i] += QuantumClifford.entanglement_entropy(backend.state, 1:div(L,2))
912
end

0 commit comments

Comments
 (0)