Skip to content

Commit 670fb53

Browse files
committed
plot examples
1 parent 7e50a84 commit 670fb53

File tree

6 files changed

+249
-7
lines changed

6 files changed

+249
-7
lines changed

examples/2D_GHZ/plot/histogram.jl

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
using CairoMakie
2+
theme = Theme(
3+
figure_padding=7,
4+
size=(246, 3/4*246),
5+
fontsize=8,
6+
Scatter=(
7+
markersize=2.0,
8+
strokewidth=0.0,
9+
marker=:circle,
10+
strokecolor=(:black, 0.5),
11+
),
12+
Lines=(
13+
linewidth=1.0,
14+
),
15+
VLines=(
16+
linewidth=1.0,
17+
),
18+
Errorbars=(
19+
linewidth=0.35,
20+
whiskerwidth=2.0,
21+
color=:black,
22+
),
23+
Axis=(
24+
titlefont=:regular,
25+
titlesize=10,
26+
xlabelsize=10,
27+
ylabelsize=10,
28+
xgridvisible=false,
29+
ygridvisible=false,
30+
xticksize=2.5,
31+
yticksize=2.5,
32+
xminorticksize=1.5,
33+
yminorticksize=1.5,
34+
spinewidth=0.75,
35+
xtickwidth=0.75,
36+
ytickwidth=0.75,
37+
xminortickwidth=0.75,
38+
yminortickwidth=0.75,
39+
xticksmirrored = true,
40+
yticksmirrored = true,
41+
xtickalign=1,
42+
ytickalign=1,
43+
xminortickalign=1,
44+
yminortickalign=1,
45+
xminorticksvisible=true,
46+
yminorticksvisible=true,
47+
48+
),
49+
Legend=(
50+
labelfont=:regular,
51+
padding=(2, 2, 2, 2), # The additional space between the legend content and the border.
52+
patchlabelgap=3, # The gap between the patch and the label of each legend entry.
53+
patchsize=(4, 4), # The size of the rectangles containing the legend markers.
54+
rowgap=0, # The gap between the entry rows.
55+
colgap=0, # The gap between the entry columns.
56+
titlefont=:regular,
57+
titlegap=1,
58+
margin=(2, 2, 2, 2),
59+
framevisible=false,
60+
),
61+
)
62+
# merge the theme with the theme_latexfonts() and update the theme
63+
theme = merge(theme, theme_latexfonts())
64+
update_theme!(theme)
65+
66+
67+
function plot_magnetization(data; title="magnetization_histogram")
68+
fig = Figure()
69+
ax = Axis(fig[1, 1], xlabel="magnetization", ylabel="relative counts",xticks=(-12:4:12),xminorticks=IntervalsBetween(4),yminorticks=IntervalsBetween(10))
70+
71+
bars = -10:10
72+
hist_data = [sum(data .== b)/length(data) for b in bars]
73+
74+
barplot!(ax, bars, hist_data, color=:orange, strokecolor=:black, strokewidth=0.5)
75+
# density!(ax, data, color=:orange, strokecolor=:black, strokewidth=0.5,strokearound = true,boundary=(-15,15), bandwidth=1.3)
76+
77+
# hist!(ax, data, color=:orange, strokecolor=:black, strokewidth=0.5, bins=21, normalization=:pdf)
78+
79+
# hidedecorations!(ax)
80+
filename = title
81+
limits!(ax, -13,13,0,nothing)
82+
save("figures/$filename.svg", fig)
83+
save("figures/$filename.png", fig)
84+
save("figures/$filename.pdf", fig)
85+
return fig
86+
end

examples/2D_GHZ/simulation.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ function simulate_QuantumClifford(;shots=10,postselect=false)
1313
return magnetization
1414
end
1515

16-
function simulate_Qiskit(;shots=10,postselect=false)
16+
function simulate_Qiskit(;shots=10,postselect=false,tApi=1/4)
1717
g = IBMQ_Falcon()
18-
backend = Qiskit.CliffordSimulator(nQubits(g);ancillas=nControlQubits(g))
18+
backend = Qiskit.StateVectorSimulator(nQubits(g);ancillas=nControlQubits(g))
1919

2020
magnetization = Int64[]
2121
p = (s) -> begin
@@ -24,6 +24,6 @@ function simulate_Qiskit(;shots=10,postselect=false)
2424
push!(magnetization, sum(i->2*i-1, measurements[12:end]))
2525
end
2626
end
27-
execute!(()->monitoredGHZ!(backend, g; tApi=1/4), backend, p; shots=shots)
27+
execute!(()->monitoredGHZ!(backend, g; tApi), backend, p; shots=shots)
2828
return magnetization
2929
end
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
using HDF5
2+
using CairoMakie
3+
using CairoMakie.GeometryBasics
4+
using DelaunayTriangulation
5+
using MonitoredQuantumCircuits
6+
using LinearAlgebra
7+
theme = Theme(
8+
figure_padding=7,
9+
size=(246, 3/4*246),
10+
fontsize=8,
11+
Scatter=(
12+
markersize=2.0,
13+
strokewidth=0.0,
14+
marker=:circle,
15+
strokecolor=(:black, 0.5),
16+
),
17+
Lines=(
18+
linewidth=1.0,
19+
),
20+
VLines=(
21+
linewidth=1.0,
22+
),
23+
Errorbars=(
24+
linewidth=0.35,
25+
whiskerwidth=2.0,
26+
color=:black,
27+
),
28+
Axis=(
29+
titlefont=:regular,
30+
titlesize=10,
31+
xlabelsize=10,
32+
ylabelsize=10,
33+
xgridvisible=false,
34+
ygridvisible=false,
35+
xticksize=2.5,
36+
yticksize=2.5,
37+
xminorticksize=1.5,
38+
yminorticksize=1.5,
39+
spinewidth=0.75,
40+
xtickwidth=0.75,
41+
ytickwidth=0.75,
42+
xminortickwidth=0.75,
43+
yminortickwidth=0.75,
44+
xticksmirrored = true,
45+
yticksmirrored = true,
46+
xtickalign=1,
47+
ytickalign=1,
48+
xminortickalign=1,
49+
yminortickalign=1,
50+
xminorticksvisible=true,
51+
yminorticksvisible=true,
52+
53+
),
54+
Legend=(
55+
labelfont=:regular,
56+
padding=(2, 2, 2, 2), # The additional space between the legend content and the border.
57+
patchlabelgap=3, # The gap between the patch and the label of each legend entry.
58+
patchsize=(4, 4), # The size of the rectangles containing the legend markers.
59+
rowgap=0, # The gap between the entry rows.
60+
colgap=0, # The gap between the entry columns.
61+
titlefont=:regular,
62+
titlegap=1,
63+
margin=(2, 2, 2, 2),
64+
framevisible=false,
65+
),
66+
)
67+
# merge the theme with the theme_latexfonts() and update the theme
68+
theme = merge(theme, theme_latexfonts())
69+
update_theme!(theme)
70+
71+
function average_data(f)
72+
tmi = read(f["tmi"])
73+
n_samples = read(f["averaging"])
74+
75+
averaged_tmi = sum(tmi, dims=1) ./ n_samples
76+
f["tmi_averaged"] = averaged_tmi
77+
return nothing
78+
end
79+
80+
function projection(point; origin=[1 / 3, 1 / 3, 1 / 3], e1=normalize(cross(normalize([0.0, 0.0, 1.0] .- [1 / 3, 1 / 3, 1 / 3]), normalize([1 / 3, 1 / 3, 1 / 3]))), e2=normalize([0.0, 0.0, 1.0] .- [1 / 3, 1 / 3, 1 / 3]))
81+
82+
return sum(e1 .* (point .- origin)), sum(e2 .* (point .- origin))
83+
end
84+
function plot_phasediagram(file)
85+
f = file
86+
L = read(f["L"])
87+
depth = read(f["depth"])
88+
89+
averaging = read(f["averaging"])
90+
type = read(f["type"])
91+
tmis = vec(read(f["tmi_averaged"]))
92+
points = read(f["probabilities"])
93+
n = length(points)
94+
points2d = [projection(p) for p in eachcol(points)]
95+
96+
fig = Figure()
97+
ax = Axis(fig[1, 1], aspect=DataAspect())
98+
hidedecorations!(ax)
99+
hidespines!(ax)
100+
101+
colormap = Reverse(:vik)
102+
colormap = to_colormap(cgrad([
103+
CairoMakie.RGB(165 / 255, 0 / 255, 38 / 255),
104+
CairoMakie.RGB(249 / 255, 152 / 255, 89 / 255),
105+
CairoMakie.RGB(254 / 255, 208 / 255, 130 / 255),
106+
CairoMakie.RGB(234 / 255, 236 / 255, 204 / 255),
107+
# CairoMakie.RGB(0, 0, 0),
108+
CairoMakie.RGB(131 / 255, 184 / 255, 215 / 255),
109+
CairoMakie.RGB(83 / 255, 134 / 255, 189 / 255),
110+
CairoMakie.RGB(54 / 255, 75 / 255, 154 / 255)]))
111+
112+
113+
114+
# voronoiplot!(ax, [p[1] for p in points2d], [p[2] for p in points2d], averagedTmis, colormap=:vik10, markersize=5, strokewidth=0.0, show_generators=false, smooth=false, unbounded_edge_extension_factor=1.0, colorrange=(-1, 1), highclip=:white, lowclip=:white, nan_color=:black)
115+
#
116+
# tricontourf!(ax, [p[1] for p in points2d], [p[2] for p in points2d], averagedTmis, colormap=:vik10, levels=5)
117+
tri = triangulate(points2d)
118+
faces = Matrix{Int}(undef, length(each_solid_triangle(tri)), 3)
119+
for (i, t) in enumerate(each_solid_triangle(tri))
120+
faces[i, :] .= t
121+
end
122+
mesh!(ax, points2d, faces, color=tmis, colormap=colormap, rasterize=10)
123+
124+
125+
p = Polygon(
126+
Point2f[(-0.8, -0.5), (0.8, -0.5), (0.8, 0.9), (-0.8, 0.9)],
127+
[Point2f[
128+
projection([1, 0, 0]),
129+
projection([0, 1, 0]),
130+
projection([0, 0, 1])
131+
]]
132+
)
133+
134+
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)
137+
poly!(p, color=:white)
138+
lines!(ax, [
139+
projection([1, 0, 0]),
140+
projection([0, 1, 0]),
141+
projection([0, 0, 1]),
142+
projection([1, 0, 0])], color=:black, joinstyle=:bevel, linewidth=0.75)
143+
144+
145+
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)
148+
# limits!(ax, (-0.8, 0.8), (-0.5, 0.9))
149+
Colorbar(fig[1, 2], limits=(minimum(tmis), maximum(tmis)), 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)
151+
limits!(ax, (-0.82, 0.82), (-0.515, 0.915))
152+
filename = "honeycomb_circuit_L$(L)_D$(depth)_pres$(n)_avg$(averaging)_$(type)"
153+
save("figures/$filename.svg", fig)
154+
save("figures/$filename.png", fig)
155+
save("figures/$filename.pdf", fig)
156+
end

src/Backends/Qiskit/operations/WeakMXX.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ function MQC.apply!(
4747
qc.h(ax)
4848
qc.h(p2)
4949
qc.measure(ax, ax)
50-
qc.x(p1).c_if(ax,true)
50+
# qc.x(p1).c_if(ax,true)
5151
measured_qubits = get_measured_qubits(backend)
5252
push!(measured_qubits, ax+1)
5353
return qc

src/Backends/Qiskit/operations/WeakMYY.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function MQC.apply!(
2424
qc.s(p1)
2525
qc.measure(ax, ax)
2626
qc.s(p2)
27-
qc.y(p1).c_if(ax,true)
27+
# qc.y(p1).c_if(ax,true)
2828
measured_qubits = get_measured_qubits(backend)
2929
push!(measured_qubits, ax+1)
3030
return qc
@@ -55,7 +55,7 @@ function MQC.apply!(
5555
qc.s(p1)
5656
qc.measure(ax, ax)
5757
qc.s(p2)
58-
qc.y(p1).c_if(ax,true)
58+
# qc.y(p1).c_if(ax,true)
5959
measured_qubits = get_measured_qubits(backend)
6060
push!(measured_qubits, ax+1)
6161
return qc

src/Backends/Qiskit/operations/WeakMZZ.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ function MQC.apply!(
3939
qc.rzz(operation.t * 2, p2, ax)
4040
qc.h(ax)
4141
qc.measure(ax, ax)
42-
qc.z(p1).c_if(ax,true)
42+
# qc.z(p1).c_if(ax,true)
4343
measured_qubits = get_measured_qubits(backend)
4444
push!(measured_qubits, ax+1)
4545
return qc

0 commit comments

Comments
 (0)