Skip to content

Commit cd630c8

Browse files
committed
fixes
1 parent 8d3dd88 commit cd630c8

File tree

14 files changed

+570
-157
lines changed

14 files changed

+570
-157
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ LocalPreferences.toml
3131
*.jls
3232

3333
thesis/*
34-
/thesis/
34+
/thesis

examples/2D_GHZ/plot/histogram.jl

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,94 @@ function plot_magnetization(data; title="magnetization_histogram")
8484
save("figures/$filename.pdf", fig)
8585
return fig
8686
end
87+
88+
function plot_magnetization(tApi)
89+
data = JLD2.load("data/m_tApi=$(tApi)_postfalse_qpu.jld2", "magnetization")
90+
plot_magnetization(data; title="magnetization_histogram_$(tApi)_qpu")
91+
data = JLD2.load("data/m_tApi=$(tApi)_posttrue_qpu.jld2", "magnetization")
92+
plot_magnetization(data; title="magnetization_histogram_$(tApi)_qpu_postselect")
93+
end
94+
95+
function plot_simulation_magnetization(;tApi=0.2)
96+
data = JLD2.load("data/m_tApi=$(tApi)_postfalse_statevec.jld2", "magnetization")
97+
data_post = JLD2.load("data/m_tApi=$(tApi)_posttrue_tensor.jld2", "magnetization")
98+
99+
fig = Figure(size=(246, 246))
100+
ax = Axis(fig[1, 1], ylabel="relative counts",xticks=(-12:2:12),xminorticks=IntervalsBetween(2),xticklabelsvisible=false)
101+
ax2 = Axis(fig[2, 1], xlabel="magnetization", ylabel="relative counts",xticks=(-12:2:12),xminorticks=IntervalsBetween(2))
102+
103+
bars = -10:10
104+
hist_data = [sum(data .== b)/length(data) for b in bars]
105+
hist_data_post = [sum(data_post .== b)/length(data_post) for b in bars]
106+
barplot!(ax, bars, hist_data, color=:orange, strokecolor=:black, strokewidth=0.75)
107+
barplot!(ax2, bars, hist_data_post, color=:orange, strokecolor=:black, strokewidth=0.75)
108+
filename = "magnetization_histogram_$(tApi)_simulation"
109+
limits!(ax, -11,11,0,nothing)
110+
limits!(ax2, -11,11,0,nothing)
111+
linkyaxes!(ax, ax2)
112+
113+
axislegend(ax,
114+
[
115+
MarkerElement(color=(:white, 0.0), markersize=0.0, marker=:circle) for i in 1:4
116+
],
117+
["Raw",L"t_A=%$tApi\pi", "10 qubits", "$(length(data)) samples"],
118+
position=:rt,
119+
labelhalign=:center,
120+
margin=(15, 15, 10, 10))
121+
122+
axislegend(ax2,
123+
[
124+
MarkerElement(color=(:white, 0.0), markersize=0.0, marker=:circle) for i in 1:4
125+
],
126+
["Post-Selected",L"t_A=%$tApi\pi", "10 qubits", "$(length(data_post)) samples"],
127+
position=:rt,
128+
labelhalign=:center,
129+
margin=(15, 15, 10, 10))
130+
131+
save("figures/$filename.svg", fig)
132+
save("figures/$filename.png", fig)
133+
save("figures/$filename.pdf", fig)
134+
return fig
135+
end
136+
137+
function plot_qpu_magnetization(;tApi=0.2)
138+
data = JLD2.load("data/m_tApi=$(tApi)_postfalse_qpu.jld2", "magnetization")
139+
data_post = JLD2.load("data/m_tApi=$(tApi)_posttrue_qpu.jld2", "magnetization")
140+
141+
fig = Figure(size=(246, 246))
142+
ax = Axis(fig[1, 1], ylabel="relative counts",xticks=(-12:2:12),xminorticks=IntervalsBetween(2),xticklabelsvisible=false)
143+
ax2 = Axis(fig[2, 1], xlabel="magnetization", ylabel="relative counts",xticks=(-12:2:12),xminorticks=IntervalsBetween(2))
144+
145+
bars = -10:10
146+
hist_data = [sum(data .== b)/length(data) for b in bars]
147+
hist_data_post = [sum(data_post .== b)/length(data_post) for b in bars]
148+
barplot!(ax, bars, hist_data, color=:orange, strokecolor=:black, strokewidth=0.75)
149+
barplot!(ax2, bars, hist_data_post, color=:orange, strokecolor=:black, strokewidth=0.75)
150+
filename = "magnetization_histogram_$(tApi)_qpu"
151+
limits!(ax, -11,11,0,nothing)
152+
limits!(ax2, -11,11,0,nothing)
153+
linkyaxes!(ax, ax2)
154+
155+
axislegend(ax,
156+
[
157+
MarkerElement(color=(:white, 0.0), markersize=0.0, marker=:circle) for i in 1:4
158+
],
159+
["Raw",L"t_A=%$tApi\pi", "10 qubits", "$(length(data)) samples"],
160+
position=:rt,
161+
labelhalign=:center,
162+
margin=(15, 15, 10, 10))
163+
164+
axislegend(ax2,
165+
[
166+
MarkerElement(color=(:white, 0.0), markersize=0.0, marker=:circle) for i in 1:4
167+
],
168+
["Post-Selected",L"t_A=%$tApi\pi", "10 qubits", "$(length(data_post)) samples"],
169+
position=:rt,
170+
labelhalign=:center,
171+
margin=(15, 15, 10, 10))
172+
173+
save("figures/$filename.svg", fig)
174+
save("figures/$filename.png", fig)
175+
save("figures/$filename.pdf", fig)
176+
return fig
177+
end

examples/2D_GHZ/simulation.jl

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using JLD2
12
function simulate_QuantumClifford(;shots=10,postselect=false)
23
g = IBMQ_Falcon()
34
backend = QuantumClifford.TableauSimulator(nQubits(g);
@@ -27,3 +28,81 @@ function simulate_Qiskit(;shots=10,postselect=false,tApi=1/4)
2728
execute!(()->monitoredGHZ!(backend, g; tApi), backend, p; shots=shots)
2829
return magnetization
2930
end
31+
32+
function simulate_Qiskit_QPU(;shots=10,tApi=1/4)
33+
g = IBMQ_Falcon()
34+
backend = Qiskit.IBMBackend(nQubits(g);ancillas=nControlQubits(g))
35+
36+
execute!(()->monitoredGHZ!(backend, g; tApi), backend; shots=shots)
37+
return backend
38+
end
39+
40+
function process_Qiskit_QPU(backend::Qiskit.IBMBackend, jobId::String, tApi; postselect=false)
41+
empty!(Qiskit.get_measurements(backend))
42+
magnetization = Int64[]
43+
p = (s) -> begin
44+
measurements = Qiskit.get_measurements(backend, s)
45+
if postselect && all(i->i==0, (@view measurements[1:11])) || !postselect
46+
push!(magnetization, sum(i->2*i-1, measurements[12:end]))
47+
end
48+
end
49+
Qiskit.postprocess!(backend, jobId, p)
50+
JLD2.save("data/m_tApi=$(tApi)_post$(postselect)_qpu.jld2","magnetization", magnetization)
51+
return magnetization
52+
end
53+
54+
function simulate_QuantumClifford2(;shots=10)
55+
g = IBMQ_Falcon()
56+
backend = QuantumClifford.TableauSimulator(nQubits(g);
57+
mixed=false, basis=:Z)
58+
59+
magnetization = zeros(Int64, shots)
60+
correction_mask = zeros(Bool, nQubits(g))
61+
depth_first_walk = (1, 7, 8, 9, 10, 2, 3, 4, 5, 6, 11)
62+
p = (s) -> begin
63+
correct_falcon!(
64+
correction_mask,
65+
bonds(g),
66+
(@view backend.measurements[1:11]),
67+
depth_first_walk)
68+
69+
correction_mask .⊻= (@view backend.measurements[12:end])
70+
magnetization[s] = sum(i->2*i-1, correction_mask)
71+
end
72+
execute!(()->monitoredGHZ!(backend, g; tApi=1/4), backend, p; shots=shots)
73+
return magnetization
74+
end
75+
76+
function correct_falcon!(mask, bonds, ancillaMeasurements,tree)
77+
fill!(mask, false)
78+
for b_idx in tree
79+
bond = bonds[b_idx]
80+
meas = ancillaMeasurements[b_idx]
81+
q1, q2 = bond.qubit1, bond.qubit2
82+
mask[q2] = mask[q1] meas
83+
end
84+
end
85+
86+
87+
88+
function simulate_Qiskit2(;shots=10,tApi=1/4)
89+
g = IBMQ_Falcon()
90+
backend = Qiskit.GPUTensorNetworkSimulator(nQubits(g);ancillas=11)
91+
92+
magnetization = zeros(Int64, shots)
93+
correction_mask = zeros(Bool, nQubits(g))
94+
depth_first_walk = (1, 7, 8, 9, 10, 2, 3, 4, 5, 6, 11)
95+
p = (s) -> begin
96+
measurements = Qiskit.get_measurements(backend, s)
97+
correct_falcon!(
98+
correction_mask,
99+
bonds(g),
100+
(@view measurements[1:11]),
101+
depth_first_walk)
102+
103+
correction_mask .⊻= (@view measurements[12:end])
104+
magnetization[s] = sum(i->2*i-1, correction_mask)
105+
end
106+
execute!(()->monitoredGHZ!(backend, g; tApi), backend, p; shots=shots)
107+
return magnetization
108+
end

examples/Honeycomb/plot/phase_diagram.jl

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ function average_data(f)
7272
tmi = read(f["tmi"])
7373
n_samples = read(f["averaging"])
7474

75-
averaged_tmi = sum(tmi, dims=1) ./ n_samples
75+
averaged_tmi = sum(tmi, dims=1) ./ 3n_samples
7676
f["tmi_averaged"] = averaged_tmi
7777
return nothing
7878
end
@@ -119,7 +119,7 @@ function plot_phasediagram(file)
119119
for (i, t) in enumerate(each_solid_triangle(tri))
120120
faces[i, :] .= t
121121
end
122-
mesh!(ax, points2d, faces, color=tmis, colormap=colormap, rasterize=10,colorrange=(-1,1), highclip=:black, lowclip=:black)
122+
mesh!(ax, points2d, faces, color=tmis, colormap=colormap, rasterize=20,colorrange=(-1,1))
123123

124124

125125
p = Polygon(
@@ -132,8 +132,8 @@ function plot_phasediagram(file)
132132
)
133133

134134

135-
# scatter!(ax, [p[1] for p in points2d], [p[2] for p in points2d], color=:black, strokewidth=0, markersize=5)
136-
scatter!(ax, [p[1] for p in points2d], [p[2] for p in points2d], color=tmis, strokewidth=0.25, strokecolor=:black, colormap=colormap, markersize=2,colorrange=(-1, 1), highclip=:black, lowclip=:black, nan_color=:black)
135+
# scatter!(ax, [p[1] for p in points2d], [p[2] for p in points2d], color=:black, strokewidth=0, markersize=0.25)
136+
# scatter!(ax, [p[1] for p in points2d], [p[2] for p in points2d], color=tmis, strokewidth=0.25, strokecolor=:black, colormap=colormap, markersize=2,colorrange=extrema(tmis))
137137
poly!(p, color=:white)
138138
lines!(ax, [
139139
projection([1, 0, 0]),
@@ -143,12 +143,15 @@ function plot_phasediagram(file)
143143

144144

145145

146-
147-
text!(ax, Point2f[projection([1.1, 0, 0]), projection([0, 1.1, 0]), projection([0, 0, 1.1])], text=[L"$p_X$", L"$p_Y$", L"$p_Z$"], color=:black, align=(:center, :center),fontsize=8)
146+
if type == "Kitaev"
147+
text!(ax, Point2f[projection([1.1, 0, 0]), projection([0, 1.1, 0]), projection([0, 0, 1.1])], text=[L"$p_X$", L"$p_Y$", L"$p_Z$"], color=:black, align=(:center, :center),fontsize=8)
148+
elseif type == "Kekule"
149+
text!(ax, Point2f[projection([1.1, 0, 0]), projection([0, 1.1, 0]), projection([0, 0, 1.1])], text=[L"$p_R$", L"$p_G$", L"$p_B$"], color=:black, align=(:center, :center),fontsize=8)
150+
end
148151
# limits!(ax, (-0.8, 0.8), (-0.5, 0.9))
149-
Colorbar(fig[1, 2], limits=(-1, 1), colormap=colormap,
150-
flipaxis=true, label=L"$$Tripartite Information", minorticksvisible=true, minortickalign=1.0,tickalign=1.0,spinewidth=0.75,minortickwidth=0.75,tickwidth=0.75,height=154, tellheight=false, highclip=:black, lowclip=:black)
151-
limits!(ax, (-0.82, 0.82), (-0.515, 0.915))
152+
Colorbar(fig[1, 2], limits=(-1,1), colormap=colormap,
153+
flipaxis=true, label=L"$$Tripartite Information", minorticksvisible=true, minortickalign=1.0,tickalign=1.0,spinewidth=0.75,minortickwidth=0.75,tickwidth=0.75,height=154, tellheight=false)
154+
limits!(ax, (-0.83, 0.83), (-0.515, 0.915))
152155
filename = "honeycomb_circuit_L$(L)_D$(depth)_pres$(n)_avg$(averaging)_$(type)"
153156
save("figures/$filename.svg", fig)
154157
save("figures/$filename.png", fig)

examples/Honeycomb/simulation.jl

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
function simulate_QuantumClifford(L,n=10;shots=10,depth=10,type=:Kitaev)
22
g = HoneycombGeometry(Periodic, L, L)
33
ps = generateProbs(;n, offset=0.01)
4-
5-
64
partitionsX = subsystems(g, 4; cutType=:X)
75
partitionsY = subsystems(g, 4; cutType=:Y)
86
partitionsZ = subsystems(g, 4; cutType=:Z)
9-
107
tmi = zeros(Float64, length(ps))
118
Threads.@threads for i in eachindex(ps)
129
px,py,pz = ps[i]
@@ -16,11 +13,7 @@ function simulate_QuantumClifford(L,n=10;shots=10,depth=10,type=:Kitaev)
1613
x = QuantumClifford.tmi(backend.state, partitionsX)
1714
y = QuantumClifford.tmi(backend.state, partitionsY)
1815
z = QuantumClifford.tmi(backend.state, partitionsZ)
19-
if -1 <= x <= 1 && -1 <= y <= 1 && -1 <= z <= 1
20-
tmi[i] += x + y + z
21-
else
22-
@warn "TMI out of bounds: $x, $y, $z, px=$px, py=$py, pz=$pz, sum=$(px+py+pz), $(QuantumClifford.state_entropy(backend.state))"
23-
end
16+
tmi[i] += x + y + z
2417
end
2518
if type == :Kitaev
2619
execute!(()->measurementOnlyKitaev!(backend, g, px,py,pz; depth), backend, post; shots=shots)
@@ -33,7 +26,7 @@ function simulate_QuantumClifford(L,n=10;shots=10,depth=10,type=:Kitaev)
3326
return tmi ./= 3shots
3427
end
3528

36-
function generateProbs(; n=45,offset=0.0)
29+
function generateProbabilities(resolution)
3730
points = Vector{NTuple{3,Float64}}(undef, n*(n + 1) ÷ 2)
3831
m = 1
3932
for (k, i) in enumerate(range(0, 1, n))
@@ -45,6 +38,5 @@ function generateProbs(; n=45,offset=0.0)
4538
m += 1
4639
end
4740
end
48-
49-
return [p .- offset .* (p .- (1 / 3, 1 / 3, 1 / 3)) for p in points]
41+
return points
5042
end

examples/TransverseFieldIsing/simulation.jl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@ function simulate_QuantumClifford(L,ps;shots=10,depth=10)
55
entanglement = zeros(Float64, length(ps))
66
for (i, p) in enumerate(ps)
77
post = (s) -> begin
8-
entanglement[i] += QuantumClifford.entanglement_entropy(backend.state, 1:div(L,2))
8+
subsystem = 1:div(L,2)
9+
entropy = QuantumClifford.entanglement_entropy(backend.state, subsystem)
10+
entanglement[i] += entropy
911
end
10-
execute!(()->monitoredTransverseFieldIsing!(backend, g, p; depth), backend, post; shots=shots)
12+
execute!(
13+
()->monitoredTransverseFieldIsing!(backend, g, p; depth),
14+
backend, post; shots=shots)
1115
end
12-
1316
return entanglement ./= shots
1417
end

0 commit comments

Comments
 (0)