Skip to content

Commit 82e74d1

Browse files
committed
quality of life and result
1 parent 34f9538 commit 82e74d1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+905
-952
lines changed

examples/Honeycomb/information.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ function simulate(path::String; depth=100, L=12, averaging=10, resolution=45, ty
3232
"tmi", tmi,
3333
"probs", (px, py, pz))
3434
end
35+
3536
end
3637

3738
function generateProbs(; n=45)

examples/TriangleSquare/arcs.jl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,14 @@ using MonitoredQuantumCircuits
22
import JLD2
33
import ProgressMeter
44
function simulate(path::String; depth=100, L=12, averaging=10, resolution=45)
5-
points = [(1 / 3, 1 / 3, 1 / 3), (0.8, 0.1, 0.1), (0.25, 0.5, 0.25)]
5+
points = [
6+
(1 / 3, 1 / 3, 1 / 3),
7+
(0.1, 0.8, 0.1),
8+
(0.25, 0.5, 0.25),
9+
(0.8, 0.1, 0.1),
10+
(0.1, 0.1, 0.8),
11+
(0.5, 0.25, 0.25),
12+
(0.25, 0.25, 0.5)]
613
geometry = TriangleSquareGeometry(Periodic, L, L)
714

815
progressMeter = ProgressMeter.Progress(length(points) * averaging; dt=1.0)

examples/TriangleSquare/arcs_plot.jl

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,47 @@ using CairoMakie
22
using JLD2
33
using LinearAlgebra
44

5+
function projection(point; origin=[1 / 3, 1 / 3, 1 / 3], e1=normalize(cross(normalize([0.0, 0.0, 1.0] .- origin), normalize(origin))), e2=normalize([0.0, 0.0, 1.0] .- origin))
56

7+
return sum(e1 .* (point .- origin)), sum(e2 .* (point .- origin))
8+
end
69

710
function arcPlot(file::String, data_path::String; L=12, averaging=10,depth=100)
8-
points = [(1 / 3, 1 / 3, 1 / 3), (0.8, 0.1, 0.1), (0.25, 0.5, 0.25)]
11+
points = [
12+
(1 / 3, 1 / 3, 1 / 3),
13+
(0.1, 0.8, 0.1),
14+
(0.25, 0.5, 0.25),
15+
(0.8, 0.1, 0.1),
16+
(0.1, 0.1, 0.8),
17+
(0.5, 0.25, 0.25),
18+
(0.25, 0.25, 0.5)]
19+
points2d = [projection(p) for p in points]
920
entropies = Vector{Float64}[]
1021
steps = 0:L
1122
for (i, p) in enumerate(points)
1223
push!(entropies, JLD2.load("$data_path/ARC_L=$(L)_px=$(p[1])_py=$(p[2])_pz=$(p[3])_averaging=$(averaging)_depth=$depth.jld2")["entanglement"])
1324
end
1425
fig = Figure()
15-
ax = Axis(fig[1, 1])
26+
ax = Axis(fig[1:10, 1:10], xlabel="Subsystem size", ylabel="Entropy", title="Entanglement Entropy L=$L")
27+
insetAxis = Axis(fig[1:4, 1:3], aspect=DataAspect(), tellwidth=false, tellheight=false)
28+
hidedecorations!(insetAxis)
29+
hidespines!(insetAxis)
30+
lines!(insetAxis, [
31+
projection([1, 0, 0]),
32+
projection([0, 1, 0]),
33+
projection([0, 0, 1]),
34+
projection([1, 0, 0])], color=:black, joinstyle=:bevel, linewidth=1.0)
35+
for p in points2d
36+
scatter!(insetAxis, p[1], p[2], strokewidth=0.5, markersize=10)
37+
end
38+
text!(insetAxis, Point2f[projection([1.1, 0, 0]), projection([0, 1.1, 0]), projection([0, 0, 1.1])], text=[L"$$X", L"$$Y", L"$$Z"], color=:black, align=(:center, :center))
39+
40+
1641

1742
for (entropy, point) in zip(entropies, points)
18-
lines!(ax, steps, entropy, label=point)
43+
scatterlines!(ax, steps, entropy, label="px=$(round(point[1];digits=3)), py=$(round(point[2];digits=3)), pz=$(round(point[3];digits=3))")
1944
end
45+
# axislegend(ax, position=:rt)
2046
save("$file.svg", fig)
2147
save("$file.png", fig)
2248
end

examples/TriangleSquare/entanglement.jl

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,23 @@ function simulate(path::String; depth=100, L=12, averaging=10, resolution=45)
55
points = generateProbs(n=resolution)
66
geometry = TriangleSquareGeometry(Periodic, L, L)
77

8-
h_subsystems = subsystems(geometry, 4; cutType=:HORIZONTAL)
9-
v_subsystems = subsystems(geometry, 4; cutType=:VERTICAL)
10-
118
progressMeter = ProgressMeter.Progress(length(points) * averaging; dt=1.0)
129
Threads.@threads for (px, py, pz) in points
1310

1411
circuit = MeasurementOnlyTriangleSquareXYZ(geometry, px, py, pz; depth, purify=true)
1512
compiled = compile(circuit)
1613
sim = QuantumClifford.TableauSimulator(nQubits(geometry))
17-
tmi = 0
14+
entanglement = 0
1815
for _ in 1:averaging
1916
result = execute(compiled, sim)
20-
tmi += QuantumClifford.tmi(result, h_subsystems)
21-
tmi += QuantumClifford.tmi(result, v_subsystems)
17+
entanglement += QuantumClifford.entanglement_entropy(result, subsystem(geometry, L ÷ 2; cutType=:HORIZONTAL))
18+
entanglement += QuantumClifford.entanglement_entropy(result, subsystem(geometry, L ÷ 2; cutType=:VERTICAL))
2219
ProgressMeter.next!(progressMeter)
2320
end
24-
tmi /= 2averaging
21+
entanglement /= 2averaging
2522
JLD2.save(
26-
"$path/TMI_L=$(L)_px=$(px)_py=$(py)_pz=$(pz)_averaging=$(averaging)_depth=$(depth).jld2",
27-
"tmi", tmi,
23+
"$path/Lhalf_ENT_L=$(L)_px=$(px)_py=$(py)_pz=$(pz)_averaging=$(averaging)_depth=$(depth).jld2",
24+
"entanglement", entanglement,
2825
"probs", (px, py, pz))
2926
end
3027
end
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
using CairoMakie
2+
using CairoMakie.GeometryBasics
3+
using DelaunayTriangulation
4+
using JLD2
5+
using LinearAlgebra
6+
# using AestheticSuperposition
7+
8+
function generateProbs(; n=45)
9+
points = NTuple{3,Float64}[]
10+
# N = k * (k + 1) / 2
11+
for (k, i) in enumerate(range(0, 1, n))
12+
for j in range(i, 1, n - k + 1)
13+
px = i
14+
py = j - i
15+
pz = 1 - j
16+
push!(points, (px, py, pz))
17+
end
18+
end
19+
20+
return [p .- 0 .* (p .- (1 / 3, 1 / 3, 1 / 3)) for p in points]
21+
end
22+
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]))
23+
24+
return sum(e1 .* (point .- origin)), sum(e2 .* (point .- origin))
25+
end
26+
function informationPlot(file::String, data_path::String; depth=100, L=12, averaging=10, resolution=45)
27+
# set_theme!(AestheticSuperpositionTheme())
28+
points = generateProbs(n=resolution)
29+
tmis = Float64[]
30+
for (i, p) in enumerate(points)
31+
push!(tmis, JLD2.load("$data_path/Lhalf_ENT_L=$(L)_px=$(p[1])_py=$(p[2])_pz=$(p[3])_averaging=$(averaging)_depth=$depth.jld2")["entanglement"])
32+
end
33+
points2d = [projection(p) for p in points]
34+
fig = Figure()
35+
ax = Axis(fig[1, 1], aspect=DataAspect())
36+
hidedecorations!(ax)
37+
hidespines!(ax)
38+
39+
colormap = Reverse(:vik)
40+
colormap = to_colormap(cgrad([
41+
CairoMakie.RGB(165 / 255, 0 / 255, 38 / 255),
42+
CairoMakie.RGB(249 / 255, 152 / 255, 89 / 255),
43+
CairoMakie.RGB(254 / 255, 208 / 255, 130 / 255),
44+
CairoMakie.RGB(234 / 255, 236 / 255, 204 / 255),
45+
# CairoMakie.RGB(0, 0, 0),
46+
CairoMakie.RGB(131 / 255, 184 / 255, 215 / 255),
47+
CairoMakie.RGB(83 / 255, 134 / 255, 189 / 255),
48+
CairoMakie.RGB(54 / 255, 75 / 255, 154 / 255)]))
49+
50+
51+
52+
# 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)
53+
#
54+
# tricontourf!(ax, [p[1] for p in points2d], [p[2] for p in points2d], averagedTmis, colormap=:vik10, levels=5)
55+
tri = triangulate(points2d)
56+
faces = Matrix{Int}(undef, length(each_solid_triangle(tri)), 3)
57+
for (i, t) in enumerate(each_solid_triangle(tri))
58+
faces[i, :] .= t
59+
end
60+
mesh!(ax, points2d, faces, color=tmis, colormap=colormap, rasterize=10)
61+
62+
63+
p = Polygon(
64+
Point2f[(-0.8, -0.5), (0.8, -0.5), (0.8, 0.9), (-0.8, 0.9)],
65+
[Point2f[
66+
projection([1, 0, 0]),
67+
projection([0, 1, 0]),
68+
projection([0, 0, 1])
69+
]]
70+
)
71+
# poly!(p, color=:white)
72+
73+
74+
75+
lines!(ax, [
76+
projection([1, 0, 0]),
77+
projection([0, 1, 0]),
78+
projection([0, 0, 1]),
79+
projection([1, 0, 0])], color=:black, joinstyle=:bevel, linewidth=1.0)
80+
81+
scatter!(ax, [p[1] for p in points2d], [p[2] for p in points2d], color=tmis, strokewidth=0.5, strokecolor=(:black, 0.5), colormap=colormap, markersize=2)
82+
# scatter!(ax, [p[1] for p in points2d], [p[2] for p in points2d], color=:black, strokewidth=0, markersize=2)
83+
84+
text!(ax, Point2f[projection([1.1, 0, 0]), projection([0, 1.1, 0]), projection([0, 0, 1.1])], text=[L"$$X", L"$$Y", L"$$Z"], color=:black, align=(:center, :center))
85+
# limits!(ax, (-0.8, 0.8), (-0.5, 0.9))
86+
Colorbar(fig[1, 2], limits=(minimum(tmis), maximum(tmis)), colormap=colormap,
87+
flipaxis=true, label=L"$$Entanglement entropy S(L/2)", minorticksvisible=true, minortickalign=1.0)
88+
89+
save("$file.svg", fig)
90+
save("$file.png", fig)
91+
end
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=45)
5+
points = generateProbs(n=resolution)
6+
geometry = TriangleSquareGeometry(Periodic, L, L)
7+
8+
h_subsystems = subsystems(geometry, 4; cutType=:HORIZONTAL)
9+
v_subsystems = subsystems(geometry, 4; cutType=:VERTICAL)
10+
11+
progressMeter = ProgressMeter.Progress(length(points) * averaging; dt=1.0)
12+
Threads.@threads for (px, py, pz) in points
13+
14+
circuit = MeasurementOnlyTriangleSquareXYZ(geometry, px, py, pz; depth, purify=false)
15+
compiled = compile(circuit)
16+
sim = QuantumClifford.TableauSimulator(nQubits(geometry))
17+
tmi = 0
18+
for _ in 1:averaging
19+
result = execute(compiled, sim)
20+
tmi += QuantumClifford.tmi(result.stab, h_subsystems)
21+
tmi += QuantumClifford.tmi(result.stab, v_subsystems)
22+
ProgressMeter.next!(progressMeter)
23+
end
24+
tmi /= 2averaging
25+
JLD2.save(
26+
"$path/TMI_L=$(L)_px=$(px)_py=$(py)_pz=$(pz)_averaging=$(averaging)_depth=$(depth).jld2",
27+
"tmi", tmi,
28+
"probs", (px, py, pz))
29+
end
30+
return
31+
end
32+
33+
function generateProbs(; n=45)
34+
points = NTuple{3,Float64}[]
35+
# N = k * (k + 1) / 2
36+
for (k, i) in enumerate(range(0, 1, n))
37+
for j in range(i, 1, n - k + 1)
38+
px = i
39+
py = j - i
40+
pz = 1 - j
41+
push!(points, (px, py, pz))
42+
end
43+
end
44+
45+
return [p .- 0 .* (p .- (1 / 3, 1 / 3, 1 / 3)) for p in points]
46+
end
Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,41 @@
11
using MonitoredQuantumCircuits
22
import JLD2
33
import ProgressMeter
4-
function simulate(path::String; L=12, averaging=10)
5-
points = [(1 / 3, 1 / 3, 1 / 3), (0.8, 0.1, 0.1), (0.25, 0.5, 0.25)]
6-
steps = Int64.(10.0 .^ (0:1:4))
7-
pushfirst!(steps, 0)
4+
function simulate(path::String; L=12, averaging=10, max_depth=1000, resolution=100)
5+
points = [
6+
(1 / 3, 1 / 3, 1 / 3),
7+
(0.1, 0.8, 0.1),
8+
(0.25, 0.5, 0.25),
9+
(0.8, 0.1, 0.1),
10+
(0.1, 0.1, 0.8),
11+
(0.5, 0.25, 0.25),
12+
(0.25, 0.25, 0.5)]
13+
steps = range(0, max_depth, resolution)
14+
# steps = vcat(steps, [range(10.0^(i - 1), 10.0^i, resolution) for i in 0:max_depth]...)
815
geometry = TriangleSquareGeometry(Periodic, L, L)
916

1017
progressMeter = ProgressMeter.Progress(length(points) * averaging * length(steps); dt=1.0)
11-
for (px, py, pz) in points
18+
Threads.@threads for (px, py, pz) in points
1219
entropies = zeros(Float64, length(steps))
13-
Threads.@threads for (i, depth) in enumerate(steps)
14-
circuit = MeasurementOnlyTriangleSquareXYZ(geometry, px, py, pz; depth)
15-
compiled = compile(circuit)
16-
sim = QuantumClifford.TableauSimulator(nQubits(geometry))
17-
18-
for _ in 1:averaging
20+
circuit = MeasurementOnlyTriangleSquareXYZ(geometry, px, py, pz; depth=step(steps), purify=false)
21+
compiled = compile(circuit)
22+
sim = QuantumClifford.TableauSimulator(nQubits(geometry))
23+
initial_state = copy(sim.initial_state)
24+
for _ in 1:averaging
25+
QuantumClifford.setInitialState!(sim, initial_state)
26+
entropies[1] += QuantumClifford.state_entropy(sim.initial_state)
27+
for i in eachindex(steps)[2:end]
1928
result = execute(compiled, sim)
2029
entropies[i] += QuantumClifford.state_entropy(result)
30+
QuantumClifford.setInitialState!(sim, result)
2131
ProgressMeter.next!(progressMeter)
2232
end
23-
2433
end
2534
entropies ./= averaging
2635
JLD2.save(
2736
"$path/Purification_L=$(L)_px=$(px)_py=$(py)_pz=$(pz)_averaging=$(averaging).jld2",
2837
"entropies", entropies,
2938
"probs", (px, py, pz),
3039
"steps", steps)
31-
3240
end
3341
end

examples/TriangleSquare/purification_plot.jl

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,45 @@ using CairoMakie
22
using JLD2
33
using LinearAlgebra
44

5+
function projection(point; origin=[1 / 3, 1 / 3, 1 / 3], e1=normalize(cross(normalize([0.0, 0.0, 1.0] .- origin), normalize(origin))), e2=normalize([0.0, 0.0, 1.0] .- origin))
56

7+
return sum(e1 .* (point .- origin)), sum(e2 .* (point .- origin))
8+
end
69

710
function purificationPlot(file::String, data_path::String; L=12, averaging=10)
8-
points = [(1 / 3, 1 / 3, 1 / 3), (0.8, 0.1, 0.1), (0.25, 0.5, 0.25)]
11+
points = [
12+
(1 / 3, 1 / 3, 1 / 3),
13+
(0.1, 0.8, 0.1),
14+
(0.25, 0.5, 0.25),
15+
(0.8, 0.1, 0.1),
16+
(0.1, 0.1, 0.8),
17+
(0.5, 0.25, 0.25),
18+
(0.25, 0.25, 0.5)]
19+
points2d = [projection(p) for p in points]
920
entropies = Vector{Float64}[]
10-
steps = Vector{Int64}[]
21+
steps = Vector{Float64}[]
1122
for (i, p) in enumerate(points)
1223
push!(entropies, JLD2.load("$data_path/Purification_L=$(L)_px=$(p[1])_py=$(p[2])_pz=$(p[3])_averaging=$(averaging).jld2")["entropies"])
1324
push!(steps, JLD2.load("$data_path/Purification_L=$(L)_px=$(p[1])_py=$(p[2])_pz=$(p[3])_averaging=$(averaging).jld2")["steps"])
1425
end
1526
fig = Figure()
16-
ax = Axis(fig[1, 1])
27+
ax = Axis(fig[1:10, 1:10], xlabel="Depth", ylabel="Entropy", title="Purification Entropy L=$L")
28+
29+
insetAxis = Axis(fig[2:5, 6:10], aspect=DataAspect(), tellwidth=false, tellheight=false)
30+
hidedecorations!(insetAxis)
31+
hidespines!(insetAxis)
32+
lines!(insetAxis, [
33+
projection([1, 0, 0]),
34+
projection([0, 1, 0]),
35+
projection([0, 0, 1]),
36+
projection([1, 0, 0])], color=:black, joinstyle=:bevel, linewidth=1.0)
37+
for p in points2d
38+
scatter!(insetAxis, p[1], p[2], strokewidth=0.5, markersize=10)
39+
end
40+
text!(insetAxis, Point2f[projection([1.1, 0, 0]), projection([0, 1.1, 0]), projection([0, 0, 1.1])], text=[L"$$X", L"$$Y", L"$$Z"], color=:black, align=(:center, :center))
1741

1842
for (step, entropy, point) in zip(steps, entropies, points)
19-
println(entropy)
20-
lines!(ax, step, entropy, color=:black, label=point)
43+
scatterlines!(ax, step, entropy, label="px=$(round(point[1];digits=3)), py=$(round(point[2];digits=3)), pz=$(round(point[3];digits=3))")
2144
end
2245
save("$file.svg", fig)
2346
save("$file.png", fig)

ext/MonitoredQuantumCircuitsMPIExt.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,13 @@ function MonitoredQuantumCircuits.get_mpi_ref()
1515
size = MPI.Comm_size(MPI.COMM_WORLD)
1616
return MPI, rank, size
1717
end
18+
19+
function mpirun(file::String, hosts::Vararg{String}; nice::Int=19, wait::Bool=true, julia_path::String=joinpath(Sys.BINDIR, Base.julia_exename()))
20+
# Check if the file exists
21+
if !isfile(file)
22+
error("File $file does not exist.")
23+
end
24+
run(`mpirun --bind-to none -np $(length(hosts)) -host $(hosts) nice -n $nice $(julia_path) -t auto --project $file`; wait)
25+
end
1826
end
1927
# mpirun --bind-to none -np 2 -host l19,l90 nice -n 19 path/to/julia -t 20 --project file.jl

src/Backends/Qiskit/Simulation.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ function Base.getproperty(qc::AerSimulator, prop::Symbol)
7474
end
7575
end
7676

77-
function MQC.execute(circuit::MQC.CompiledCircuit, backend::AerSimulator; shots=1024, verbose::Bool=true)
77+
function MQC.execute(circuit::MQC.CompiledCircuit, backend::AerSimulator; shots=1024)
78+
verbose = false
7879
verbose && print("Transpiling circuit to Qiskit...")
7980
qc = translate(Circuit, circuit)
8081
verbose && println("")

0 commit comments

Comments
 (0)