Skip to content

Commit c964f3b

Browse files
committed
examples
1 parent b627d58 commit c964f3b

25 files changed

+1362
-27
lines changed

examples/Fibonacci/entanglement.jl

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using MonitoredQuantumCircuits
2+
import JLD2
3+
import ProgressMeter
4+
function simulate(path::String; depth=100, L=12, averaging=10, resolution=100, boundary=Open)
5+
6+
# points = point_distribution(resolution; ratio_in_high_density_region=0.7, high_density_center=0.39, high_density_width=0.1)
7+
points = point_distribution(resolution; ratio_in_high_density_region=0.7, high_density_center=0.43, high_density_width=0.15)
8+
9+
10+
geometry = ChainGeometry(boundary, L)
11+
progressMeter = ProgressMeter.Progress(length(points) * averaging; dt=1.0)
12+
Threads.@threads for p in points
13+
circuit = compile(MeasurementOnlyFibonacciDrive(geometry, p; depth))
14+
15+
sim = QuantumClifford.TableauSimulator(nQubits(geometry); mixed=false, basis=:X)
16+
entropies = zeros(L + 1)
17+
for _ in 1:averaging
18+
result = execute(circuit, sim)
19+
for i in 0:L
20+
entropies[i+1] += QuantumClifford.entanglement_entropy(result.stab, 1:i)
21+
end
22+
ProgressMeter.next!(progressMeter)
23+
end
24+
entropies ./= averaging
25+
JLD2.save(
26+
"$path/$(L)_$(depth)/ENT_L=$(L)_averaging=$(averaging)_p=$(p)_depth=$(depth).jld2",
27+
"entropies", entropies, "p", p)
28+
end
29+
end
30+
31+
32+
function point_distribution(n; ratio_in_high_density_region=0.5, high_density_center=0.3, high_density_width=0.1)
33+
d = ratio_in_high_density_region / 2high_density_width
34+
a = high_density_center
35+
b = high_density_width
36+
equal_points = range(0, 1, n)
37+
f1(x) = (a - b) / (-b * d + a) * x
38+
f2(x) = 1 / d * (x - a) + a
39+
40+
f3(x) = (1 - a - b) / (1 - d * b - a) * (x - b * d - a) + a + b
41+
42+
cross12 = (-a / d + a) / ((a - b) / (-b * d + a) - 1 / d)
43+
cross23 = ((1 - a - b) / (1 - b * d - a) * (b * d + a) - b - a / d) / ((1 - a - b) / (1 - d * b - a) - 1 / d)
44+
f(x) = x < cross12 ? f1(x) : x < cross23 ? f2(x) : f3(x)
45+
return [f(x) for x in equal_points]
46+
end
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using MonitoredQuantumCircuits
2+
import Statistics
3+
import UUIDs
4+
import JLD2
5+
import ProgressMeter
6+
function simulate(path::String; depth=15, L=128, averaging=10000, resolution=24)
7+
8+
# define the p values to sample
9+
rg = (1+sqrt(5))/2
10+
left = 1/(1+rg)
11+
right = (1+rg)^2/2rg - sqrt(((1+rg)^2/2rg)^2 - (1+rg)/rg)
12+
points = range(left, right+0.01, resolution)
13+
14+
# construct the geometry
15+
geometry = ChainGeometry(Open, L)
16+
17+
# create the progress meter
18+
progressMeter = ProgressMeter.Progress(length(points) * averaging; dt=1.0)
19+
20+
# simulate the circuit for each probability point
21+
Threads.@threads for p in points
22+
23+
# construct circuit and simulator
24+
circuit = compile(MeasurementOnlyFibonacciDrive(geometry, p; depth))
25+
sim = QuantumClifford.TableauSimulator(nQubits(geometry); mixed=false, basis=:X)
26+
27+
entropies = zeros(averaging)
28+
for i in 1:averaging
29+
result = execute(circuit, sim)
30+
entropies[i] = QuantumClifford.entanglement_entropy(result.stab, 1:L÷2)
31+
ProgressMeter.next!(progressMeter)
32+
end
33+
average = sum(entropies) / averaging
34+
error = Statistics.std(entropies) / sqrt(averaging)
35+
JLD2.save(
36+
"$path/L$(L)_D$(depth)/ENTh_avg$(averaging)_p$(p)_$(UUIDs.uuid4().value).jld2",
37+
"probability", p,
38+
"entanglement", average,
39+
"error", error,
40+
"depth", depth,
41+
"system_size", L,
42+
"samples", averaging)
43+
end
44+
end
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
using LinearRegression
2+
function entanglementPlotPeaks(file::String, data_path::String; depths=[100], Ls=[100], averagings=[100], resolutions=[24])
3+
4+
5+
6+
7+
fig = Figure()
8+
ax = Axis(fig[1, 1], xlabel=L"$1/L$", ylabel=L"$$peak probability",
9+
title=L"$$Entanglement Entropy for Fibonacci Drive, depth=%$(depths[1])",)
10+
11+
hlines!(ax, [0.38196601125010515], color=:orange)
12+
data_xs = Float64[]
13+
data_ys = Float64[]
14+
for (d, l, a, resolution) in zip(depths, Ls, averagings, resolutions)
15+
points = point_distribution(resolution; ratio_in_high_density_region=0.7, high_density_center=0.43, high_density_width=0.15)
16+
17+
entropies = Float64[]
18+
for (i, p) in enumerate(points)
19+
push!(entropies, JLD2.load("$data_path/ENT_L=$(l)_averaging=$(a)_p=$(p)_depth=$(d).jld2")["entropies"][div(l, 2)+1])
20+
end
21+
# scatterlines!(ax, points, entropies, color=l, colormap=:blues, colorrange=(32, 512), label=L"%$l")
22+
23+
# cubic_spline interpolation
24+
itp = cubic_spline(points, entropies)
25+
x_interp = range(0, 1, 10000)
26+
y_interp = itp(x_interp)
27+
28+
push!(data_xs, 1 / l)
29+
push!(data_ys, x_interp[argmax(y_interp)])
30+
31+
32+
end
33+
34+
35+
# fit = linregress(data_xs[end-2:end], data_ys[end-2:end])
36+
# fit = linregress(data_xs, data_ys)
37+
fit = linregress(data_xs[end-3:end], data_ys[end-3:end])
38+
39+
xs = range(0, 1 / minimum(Ls), 1000)
40+
lines!(ax, xs, LinearRegression.slope(fit) .* xs .+ LinearRegression.bias(fit), color=:black)
41+
hlines!(ax, [LinearRegression.bias(fit)], color=:orange)
42+
43+
44+
text!(ax, [0.01], [LinearRegression.bias(fit)], text=L"$$linear fit intercept=%$(LinearRegression.bias(fit))", color=:orange)
45+
46+
text!(ax, [0.02], [0.38196601125010515], text=L"$$golden ratio", color=:orange)
47+
48+
49+
scatter!(ax, data_xs, data_ys, color=1.0 ./ data_xs, colormap=:reds, colorrange=(32, 1024))
50+
51+
limits!(ax, 0, nothing,nothing,nothing)
52+
# axislegend(ax, L"system size $L$", position=:lb,)
53+
save("$file.svg", fig)
54+
save("$file.png", fig)
55+
save("$file.pdf", fig)
56+
display(fig)
57+
end
58+
59+
using Dierckx
60+
function cubic_spline(x::AbstractVector{<:Real},
61+
y::AbstractVector{<:Real})
62+
63+
length(x) == length(y) ||
64+
throw(ArgumentError("x and y must have the same length"))
65+
66+
# Ensure the nodes are strictly increasing
67+
idx = sortperm(x)
68+
xs = collect(Float64, x[idx]) # force concrete arrays
69+
ys = collect(Float64, y[idx])
70+
71+
# sitp = Spline1D(xs, ys, xs[5:2:end-12]; w=ones(length(xs)), k=3, bc="nearest")
72+
sitp = Spline1D(xs, ys; w=ones(length(xs)), k=3, bc="nearest", s=0.0)
73+
return sitp
74+
end
75+
76+
function point_distribution(n; ratio_in_high_density_region=0.5, high_density_center=0.3, high_density_width=0.1)
77+
d = ratio_in_high_density_region / 2high_density_width
78+
a = high_density_center
79+
b = high_density_width
80+
equal_points = range(0, 1, n)
81+
f1(x) = (a - b) / (-b * d + a) * x
82+
f2(x) = 1 / d * (x - a) + a
83+
84+
f3(x) = (1 - a - b) / (1 - d * b - a) * (x - b * d - a) + a + b
85+
86+
cross12 = (-a / d + a) / ((a - b) / (-b * d + a) - 1 / d)
87+
cross23 = ((1 - a - b) / (1 - b * d - a) * (b * d + a) - b - a / d) / ((1 - a - b) / (1 - d * b - a) - 1 / d)
88+
f(x) = x < cross12 ? f1(x) : x < cross23 ? f2(x) : f3(x)
89+
return [f(x) for x in equal_points]
90+
end
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using CairoMakie
2+
using JLD2
3+
using LinearAlgebra
4+
5+
function entanglementPlot(file::String, data_path::String; depth=100, L=100, averaging=100, resolution=100)
6+
7+
# points = point_distribution(resolution; ratio_in_high_density_region=0.7, high_density_center=0.43, high_density_width=0.15)
8+
points = point_distribution(resolution; ratio_in_high_density_region=0.7, high_density_center=0.39, high_density_width=0.1)
9+
10+
entropies = Float64[]
11+
for (i, p) in enumerate(points)
12+
push!(entropies, JLD2.load("$data_path/ENT_L=$(L)_averaging=$(averaging)_p=$(p)_depth=$depth.jld2")["entropies"][div(L,2)+1])
13+
end
14+
15+
16+
fig = Figure()
17+
ax = Axis(fig[1, 1], xlabel=L"measurement ratio $p$", ylabel=L"entanglement entropy $S_{L/2}$",
18+
title="Entanglement Entropy for Fibonacci Drive")
19+
20+
scatterlines!(ax, points, entropies)
21+
22+
vlines!(ax, [0.38196601125010515])
23+
save("$file.svg", fig)
24+
save("$file.png", fig)
25+
display(fig)
26+
end
27+
28+
function point_distribution(n; ratio_in_high_density_region=0.5, high_density_center=0.3, high_density_width=0.1)
29+
d = ratio_in_high_density_region/2high_density_width
30+
a = high_density_center
31+
b = high_density_width
32+
equal_points = range(0, 1, n)
33+
f1(x) = (a-b)/(-b*d+a)*x
34+
f2(x) = 1/d*(x-a)+a
35+
36+
f3(x) = (1-a-b)/(1-d*b-a)*(x-b*d-a)+a+b
37+
38+
cross12 = (-a/d+a)/((a-b)/(-b*d+a)-1/d)
39+
cross23 = ((1-a-b)/(1-b*d-a)*(b*d+a)-b-a/d)/((1-a-b)/(1-d*b-a)-1/d)
40+
f(x) = x < cross12 ? f1(x) : x < cross23 ? f2(x) : f3(x)
41+
return [f(x) for x in equal_points]
42+
end
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
function entanglementPlotTogether(file::String, data_path::String; depths=[100], Ls=[100], averagings=[100], resolutions=[24])
2+
3+
# points = point_distribution(resolution; ratio_in_high_density_region=0.7, high_density_center=0.43, high_density_width=0.15)
4+
5+
6+
7+
fig = Figure()
8+
ax = Axis(fig[1, 1], xlabel=L"measurement rate $p$", ylabel=L"entanglement entropy $S_{L/2}$",
9+
title=L"$$Entanglement Entropy for Fibonacci Drive, depth=%$(depths[1])",)
10+
11+
12+
l1 = vlines!(ax, [0.38196601125010515], color=:orange)
13+
l2 = vlines!(ax, [0.41279780151928236], color=:red)
14+
l3 =vlines!(ax, [0.4245069034188409], color=:black)
15+
for (d, l, a, resolution) in reverse(collect(zip(depths, Ls, averagings, resolutions)))
16+
points = point_distribution(resolution; ratio_in_high_density_region=0.7, high_density_center=0.43, high_density_width=0.15)
17+
18+
entropies = Float64[]
19+
for (i, p) in enumerate(points)
20+
push!(entropies, JLD2.load("$data_path/ENT_L=$(l)_averaging=$(a)_p=$(p)_depth=$(d).jld2")["entropies"][div(l, 2)+1])
21+
end
22+
plot = scatterlines!(ax, points, entropies, color=l, colormap=:blues, colorrange=(32, 1024), label=L"%$l")
23+
translate!(plot, 0,0,1/l)
24+
25+
# cubic_spline interpolation
26+
itp = cubic_spline(points, entropies; bc=:flat)
27+
x_interp = range(0, 1, 10000)
28+
y_interp = itp(x_interp)
29+
30+
31+
int = lines!(ax, x_interp, y_interp, color=l, colormap=:reds, colorrange=(32, 1024))
32+
translate!(int, 0,0,1/l+0.001)
33+
34+
end
35+
# text!(ax, [0.38196601125010515], [0.5], text=L"$$golden ratio", color=:orange, rotation=pi / 2)
36+
37+
axislegend(ax, L"system size $L$", position=:rt,)
38+
axislegend(ax, [l1,l2,l3], [L"golden ratio $1/(1+\phi)$", L"$$numerical extrapolation", L"$$theoretical value"], position = :lb)
39+
save("$file.svg", fig)
40+
save("$file.png", fig)
41+
save("$file.pdf", fig)
42+
display(fig)
43+
end
44+
45+
using Dierckx
46+
function cubic_spline(x::AbstractVector{<:Real},
47+
y::AbstractVector{<:Real};
48+
bc::Symbol=:flat)
49+
50+
length(x) == length(y) ||
51+
throw(ArgumentError("x and y must have the same length"))
52+
53+
# Ensure the nodes are strictly increasing
54+
idx = sortperm(x)
55+
xs = collect(Float64, x[idx]) # force concrete arrays
56+
ys = collect(Float64, y[idx])
57+
58+
sitp = Spline1D(xs, ys; w=ones(length(xs)), k=3, bc="nearest", s=0.0)
59+
return sitp
60+
end
61+
62+
function point_distribution(n; ratio_in_high_density_region=0.5, high_density_center=0.3, high_density_width=0.1)
63+
d = ratio_in_high_density_region / 2high_density_width
64+
a = high_density_center
65+
b = high_density_width
66+
equal_points = range(0, 1, n)
67+
f1(x) = (a - b) / (-b * d + a) * x
68+
f2(x) = 1 / d * (x - a) + a
69+
70+
f3(x) = (1 - a - b) / (1 - d * b - a) * (x - b * d - a) + a + b
71+
72+
cross12 = (-a / d + a) / ((a - b) / (-b * d + a) - 1 / d)
73+
cross23 = ((1 - a - b) / (1 - b * d - a) * (b * d + a) - b - a / d) / ((1 - a - b) / (1 - d * b - a) - 1 / d)
74+
f(x) = x < cross12 ? f1(x) : x < cross23 ? f2(x) : f3(x)
75+
return [f(x) for x in equal_points]
76+
end

examples/Fibonacci/entanglent_plot.jl

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using CairoMakie
2+
using JLD2
3+
using LinearAlgebra
4+
5+
function entanglementPlot(file::String, data_path::String; depth=100, L=100, averaging=100, resolution=100)
6+
7+
points = range(0, 1, resolution)
8+
entropies = Vector{Float64}[]
9+
for (i, p) in enumerate(points)
10+
push!(entropies, JLD2.load("$data_path/ENT_L=$(L)_averaging=$(averaging)_p=$(p)_depth=$depth.jld2")["entropies"])
11+
end
12+
13+
14+
fig = Figure()
15+
ax = Axis(fig[1, 1], xlabel=L"subsystem size $l$", ylabel=L"entanglement entropy $S_l$",
16+
title="Entanglement Entropy for Fibonacci Drive")
17+
for (i,e) in enumerate(entropies)
18+
scatterlines!(ax, 0:L, e, label="p=$(round(points[i], digits=2))", color = 1-points[i], colormap = :blues, colorrange = (0,1))
19+
end
20+
axislegend(ax)
21+
save("$file.svg", fig)
22+
save("$file.png", fig)
23+
display(fig)
24+
end

examples/Nishimori/NishimorisCat.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using MonitoredQuantumCircuits
22
import JLD2
33
import ProgressMeter
4-
function simulate(; path="", L=12, averaging=10)
4+
function simulate(; path="", L=12, averaging=10, tApi=1/4)
55
geometry = HoneycombGeometry(Open, L, L)
6-
circuit = compile(NishimorisCat(geometry))
6+
circuit = compile(NishimorisCat(geometry; tApi))
77
end

0 commit comments

Comments
 (0)