Skip to content

Commit 600ea55

Browse files
authored
Formatter (#75)
1 parent 4cc89df commit 600ea55

Some content is hidden

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

45 files changed

+2153
-1956
lines changed

benchmark/benchtools.jl

+48-48
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,82 @@
1-
function distributeZ2(D; p = 0.5)
2-
D0 = ceil(Int, p*D)
1+
function distributeZ2(D; p=0.5)
2+
D0 = ceil(Int, p * D)
33
D1 = D - D0
44
return [(0, D0), (1, D1)]
55
end
66

7-
distributeU1(D; p = 0.25) = distributeU1_poisson(D; p = p)
7+
distributeU1(D; p=0.25) = distributeU1_poisson(D; p=p)
88

9-
function distributeU1_exponential(D; p = 0.25)
10-
λ = (1-p)/(1+p)
11-
D0 = ceil(Int, p*D)
12-
if isodd(D-D0)
13-
D0 = D0 == 1 ? 2 : D0-1
9+
function distributeU1_exponential(D; p=0.25)
10+
λ = (1 - p) / (1 + p)
11+
D0 = ceil(Int, p * D)
12+
if isodd(D - D0)
13+
D0 = D0 == 1 ? 2 : D0 - 1
1414
end
1515
sectors = [(0, D0)]
1616
Drem = D - D0
1717
n = 1
1818
while Drem > 0
1919
pn = p * λ^n
20-
Dn = ceil(Int, pn*D)
20+
Dn = ceil(Int, pn * D)
2121
sectors = push!(sectors, (n, Dn), (-n, Dn))
22-
Drem -= 2*Dn
22+
Drem -= 2 * Dn
2323
n += 1
2424
end
25-
return sort!(sectors, by = first)
25+
return sort!(sectors; by=first)
2626
end
2727

28-
function distributeU1_poisson(D; p = 0.25)
29-
λ = log((1/p+1)/2)
30-
D0 = ceil(Int, p*D)
31-
if isodd(D-D0)
32-
D0 = D0 == 1 ? 2 : D0-1
28+
function distributeU1_poisson(D; p=0.25)
29+
λ = log((1 / p + 1) / 2)
30+
D0 = ceil(Int, p * D)
31+
if isodd(D - D0)
32+
D0 = D0 == 1 ? 2 : D0 - 1
3333
end
3434
sectors = [(0, D0)]
3535
Drem = D - D0
3636
n = 1
3737
while Drem > 0
3838
pn = p * λ^n / factorial(n)
39-
Dn = ceil(Int, pn*D)
39+
Dn = ceil(Int, pn * D)
4040
sectors = push!(sectors, (n, Dn), (-n, Dn))
41-
Drem -= 2*Dn
41+
Drem -= 2 * Dn
4242
n += 1
4343
end
44-
return sort!(sectors, by = first)
44+
return sort!(sectors; by=first)
4545
end
4646

4747
module Timers
48-
struct Timer{F,D<:Tuple}
49-
f::F
50-
argsref::Base.RefValue{D}
51-
Timer(f, args...) = new{typeof(f), typeof(args)}(f, Ref(args))
52-
end
48+
struct Timer{F,D<:Tuple}
49+
f::F
50+
argsref::Base.RefValue{D}
51+
Timer(f, args...) = new{typeof(f),typeof(args)}(f, Ref(args))
52+
end
5353

54-
@noinline donothing(arg) = arg
55-
function (t::Timer)(; inner = 1, outer = 1)
56-
args = t.argsref[]
57-
f = t.f
58-
f(args...) # run once to compile
59-
times = zeros(Float64, (outer,))
60-
gctimes = zeros(Float64, (outer,))
61-
@inbounds for i = 1:outer
62-
if inner == 1
63-
gcstart = Base.gc_num()
64-
start = Base.time_ns()
54+
@noinline donothing(arg) = arg
55+
function (t::Timer)(; inner=1, outer=1)
56+
args = t.argsref[]
57+
f = t.f
58+
f(args...) # run once to compile
59+
times = zeros(Float64, (outer,))
60+
gctimes = zeros(Float64, (outer,))
61+
@inbounds for i in 1:outer
62+
if inner == 1
63+
gcstart = Base.gc_num()
64+
start = Base.time_ns()
65+
donothing(f(args...))
66+
stop = Base.time_ns()
67+
gcstop = Base.gc_num()
68+
else
69+
gcstart = Base.gc_num()
70+
start = Base.time_ns()
71+
for _ in 1:inner
6572
donothing(f(args...))
66-
stop = Base.time_ns()
67-
gcstop = Base.gc_num()
68-
else
69-
gcstart = Base.gc_num()
70-
start = Base.time_ns()
71-
for _ = 1:inner
72-
donothing(f(args...))
73-
end
74-
stop = Base.time_ns()
75-
gcstop = Base.gc_num()
7673
end
77-
times[i] = (stop - start)/(1e9)/inner
78-
gctimes[i] = Base.GC_Diff(gcstop, gcstart).total_time/1e9/inner
74+
stop = Base.time_ns()
75+
gcstop = Base.gc_num()
7976
end
80-
return times, gctimes
77+
times[i] = (stop - start) / (1e9) / inner
78+
gctimes[i] = Base.GC_Diff(gcstop, gcstart).total_time / 1e9 / inner
8179
end
80+
return times, gctimes
81+
end
8282
end

benchmark/itensors_timers.jl

+68-67
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,86 @@
11
include("benchtools.jl")
22
module ITensorsTimers
3-
using ITensors
4-
import ..Timers
3+
using ITensors
4+
using ..Timers: Timers
55

6-
function add_indexlabels_as_tags(tensor, labels)
7-
new_inds = map(x -> settags(x[2], "l$(x[1])"), zip(labels, tensor.inds))
8-
return ITensor(tensor.store, new_inds)
9-
end
6+
function add_indexlabels_as_tags(tensor, labels)
7+
new_inds = map(x -> settags(x[2], "l$(x[1])"), zip(labels, tensor.inds))
8+
return ITensor(tensor.store, new_inds)
9+
end
1010

11-
function mpo_timer(T = Float64; Vmpo, Vmps, Vphys)
12-
A = randomITensor(T, Vmps, Vphys, dag(Vmps))
13-
M = randomITensor(T, Vmpo, Vphys, dag(Vphys), dag(Vmpo))
14-
FL = randomITensor(T, Vmps, dag(Vmpo), dag(Vmps))
15-
FR = randomITensor(T, Vmps, Vmpo, dag(Vmps))
11+
function mpo_timer(T=Float64; Vmpo, Vmps, Vphys)
12+
A = randomITensor(T, Vmps, Vphys, dag(Vmps))
13+
M = randomITensor(T, Vmpo, Vphys, dag(Vphys), dag(Vmpo))
14+
FL = randomITensor(T, Vmps, dag(Vmpo), dag(Vmps))
15+
FR = randomITensor(T, Vmps, Vmpo, dag(Vmps))
1616

17-
FL1 = add_indexlabels_as_tags(FL, (4, 2, 1))
18-
A1 = add_indexlabels_as_tags(A, (1, 3, 6))
19-
M1 = add_indexlabels_as_tags(M, (2, 5, 3, 7))
20-
A2 = add_indexlabels_as_tags(A, (4, 5, 8))
21-
FR1 = add_indexlabels_as_tags(FR, (6, 7, 8))
17+
FL1 = add_indexlabels_as_tags(FL, (4, 2, 1))
18+
A1 = add_indexlabels_as_tags(A, (1, 3, 6))
19+
M1 = add_indexlabels_as_tags(M, (2, 5, 3, 7))
20+
A2 = add_indexlabels_as_tags(A, (4, 5, 8))
21+
FR1 = add_indexlabels_as_tags(FR, (6, 7, 8))
2222

23-
return Timers.Timer(A1, A2, M1, FL1, FR1) do A1, A2, M1, FL1, FR1
24-
C = ((((FL1*A1)*M1)*dag(A2))*FR1)
25-
return C[]
26-
end
23+
return Timers.Timer(A1, A2, M1, FL1, FR1) do A1, A2, M1, FL1, FR1
24+
C = ((((FL1 * A1) * M1) * dag(A2)) * FR1)
25+
return C[]
2726
end
27+
end
2828

29-
function pepo_timer(T = Float64; Vpepo, Vpeps, Venv, Vphys)
30-
Vpeps′ = dag(Vpeps)
31-
Vpepo′ = dag(Vpepo)
32-
Venv′ = dag(Venv)
33-
Vphys′ = dag(Vphys)
29+
function pepo_timer(T=Float64; Vpepo, Vpeps, Venv, Vphys)
30+
Vpeps′ = dag(Vpeps)
31+
Vpepo′ = dag(Vpepo)
32+
Venv′ = dag(Venv)
33+
Vphys′ = dag(Vphys)
3434

35-
A = randomITensor(T, Vpeps, Vpeps, Vphys, Vpeps′, Vpeps′)
36-
P = randomITensor(T, Vpepo, Vpepo, Vphys, Vphys′, Vpepo′, Vpepo′)
37-
FL = randomITensor(T, Venv, Vpeps, Vpepo′, Vpeps′, Venv′)
38-
FD = randomITensor(T, Venv, Vpeps, Vpepo′, Vpeps′, Venv′)
39-
FR = randomITensor(T, Venv, Vpeps, Vpepo, Vpeps′, Venv′)
40-
FU = randomITensor(T, Venv, Vpeps, Vpepo, Vpeps′, Venv′)
35+
A = randomITensor(T, Vpeps, Vpeps, Vphys, Vpeps′, Vpeps′)
36+
P = randomITensor(T, Vpepo, Vpepo, Vphys, Vphys′, Vpepo′, Vpepo′)
37+
FL = randomITensor(T, Venv, Vpeps, Vpepo′, Vpeps′, Venv′)
38+
FD = randomITensor(T, Venv, Vpeps, Vpepo′, Vpeps′, Venv′)
39+
FR = randomITensor(T, Venv, Vpeps, Vpepo, Vpeps′, Venv′)
40+
FU = randomITensor(T, Venv, Vpeps, Vpepo, Vpeps′, Venv′)
4141

42-
FL1 = add_indexlabels_as_tags(FL, (18, 7, 4, 2, 1))
43-
FU1 = add_indexlabels_as_tags(FU, (1, 3, 6, 9, 10))
44-
A1 = add_indexlabels_as_tags(A, (2, 17, 5, 3, 11))
45-
P1 = add_indexlabels_as_tags(P, (4, 16, 8, 5, 6, 12))
46-
A2 = add_indexlabels_as_tags(A, (7, 15, 8, 9, 13))
47-
FR1 = add_indexlabels_as_tags(FR, (10, 11, 12, 13, 14))
48-
FD1 = add_indexlabels_as_tags(FD, (14, 15, 16, 17, 18))
42+
FL1 = add_indexlabels_as_tags(FL, (18, 7, 4, 2, 1))
43+
FU1 = add_indexlabels_as_tags(FU, (1, 3, 6, 9, 10))
44+
A1 = add_indexlabels_as_tags(A, (2, 17, 5, 3, 11))
45+
P1 = add_indexlabels_as_tags(P, (4, 16, 8, 5, 6, 12))
46+
A2 = add_indexlabels_as_tags(A, (7, 15, 8, 9, 13))
47+
FR1 = add_indexlabels_as_tags(FR, (10, 11, 12, 13, 14))
48+
FD1 = add_indexlabels_as_tags(FD, (14, 15, 16, 17, 18))
4949

50-
return Timers.Timer(A1, A2, P1, FL1, FD1, FR1, FU1) do A1, A2, P1, FL1, FD1, FR1, FU1
51-
C = (((((FL1*FU1)*A1)*P1)*dag(A2))*FR1)*FD1
52-
return C[]
53-
end
50+
return Timers.Timer(A1, A2, P1, FL1, FD1, FR1, FU1) do A1, A2, P1, FL1, FD1, FR1, FU1
51+
C = (((((FL1 * FU1) * A1) * P1) * dag(A2)) * FR1) * FD1
52+
return C[]
5453
end
54+
end
5555

56-
function mera_timer(T = Float64; Vmera)
57-
Vmera′ = dag(Vmera);
56+
function mera_timer(T=Float64; Vmera)
57+
Vmera′ = dag(Vmera)
5858

59-
u = randomITensor(T, Vmera, Vmera, Vmera′, Vmera′)
60-
w = randomITensor(T, Vmera, Vmera, Vmera′)
61-
ρ = randomITensor(T, Vmera, Vmera, Vmera, Vmera′, Vmera′, Vmera′)
62-
h = randomITensor(T, Vmera, Vmera, Vmera, Vmera′, Vmera′, Vmera′)
59+
u = randomITensor(T, Vmera, Vmera, Vmera′, Vmera′)
60+
w = randomITensor(T, Vmera, Vmera, Vmera′)
61+
ρ = randomITensor(T, Vmera, Vmera, Vmera, Vmera′, Vmera′, Vmera′)
62+
h = randomITensor(T, Vmera, Vmera, Vmera, Vmera′, Vmera′, Vmera′)
6363

64-
h1 = add_indexlabels_as_tags(h, (9, 3, 4, 5, 1, 2))
65-
u1 = add_indexlabels_as_tags(u, (1, 2, 7, 12))
66-
u2 = add_indexlabels_as_tags(u, (3, 4, 11, 13))
67-
u3 = add_indexlabels_as_tags(u, (8, 5, 15, 6))
68-
w1 = add_indexlabels_as_tags(w, (6, 7, 19))
69-
u4 = add_indexlabels_as_tags(u, (8, 9, 17, 10))
70-
w2 = add_indexlabels_as_tags(w, (10, 11, 22))
71-
w3 = add_indexlabels_as_tags(w, (12, 14, 20))
72-
w4 = add_indexlabels_as_tags(w, (13, 14, 23))
73-
ρ1 = add_indexlabels_as_tags(ρ, (18, 19, 20, 21, 22, 23))
74-
w5 = add_indexlabels_as_tags(w, (16, 15, 18))
75-
w6 = add_indexlabels_as_tags(w, (16, 17, 21))
64+
h1 = add_indexlabels_as_tags(h, (9, 3, 4, 5, 1, 2))
65+
u1 = add_indexlabels_as_tags(u, (1, 2, 7, 12))
66+
u2 = add_indexlabels_as_tags(u, (3, 4, 11, 13))
67+
u3 = add_indexlabels_as_tags(u, (8, 5, 15, 6))
68+
w1 = add_indexlabels_as_tags(w, (6, 7, 19))
69+
u4 = add_indexlabels_as_tags(u, (8, 9, 17, 10))
70+
w2 = add_indexlabels_as_tags(w, (10, 11, 22))
71+
w3 = add_indexlabels_as_tags(w, (12, 14, 20))
72+
w4 = add_indexlabels_as_tags(w, (13, 14, 23))
73+
ρ1 = add_indexlabels_as_tags(ρ, (18, 19, 20, 21, 22, 23))
74+
w5 = add_indexlabels_as_tags(w, (16, 15, 18))
75+
w6 = add_indexlabels_as_tags(w, (16, 17, 21))
7676

77-
return Timers.Timer(u1, u2, u3, u4, w1, w2, w3, w4, w5, w6, ρ1, h1) do u1, u2, u3, u4, w1, w2, w3, w4, w5, w6, ρ1, h1
78-
C = (((((( (h1*u1) * dag(u2) ) *
79-
(u3*w1) ) *
80-
(dag(u4)*dag(w2)) ) *
81-
( (w3 * dag(w4)) * ρ1)) * w5) * dag(w6))
82-
return C
83-
end
77+
return Timers.Timer(u1, u2, u3, u4, w1, w2, w3, w4, w5, w6, ρ1,
78+
h1) do u1, u2, u3, u4, w1, w2, w3, w4, w5, w6, ρ1, h1
79+
C = (((((((h1 * u1) * dag(u2)) *
80+
(u3 * w1)) *
81+
(dag(u4) * dag(w2))) *
82+
((w3 * dag(w4)) * ρ1)) * w5) * dag(w6))
83+
return C
8484
end
8585
end
86+
end

benchmark/plotmera.jl

+22-18
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,18 @@ meraplots = Matrix{Any}(undef, (numplots, 3))
1414
data = ["_mera_triv.txt", "_mera_z2.txt", "_mera_u1.txt"]
1515
dims = [meradims_triv, meradims_z2, meradims_u1]
1616
name = ["Trivial", "Z2 symmetry", "U1 symmetry"]
17-
for j = 1:3
17+
for j in 1:3
1818
s = data[j]
1919
data_tensorkit = try
20-
readdlm("results/tensorkit"*s)
20+
readdlm("results/tensorkit" * s)
2121
catch
2222
nothing
2323
end
2424
ymin = minimum(data_tensorkit)
2525
ymax = maximum(data_tensorkit)
2626
data_itensors = try
27-
readdlm("results/itensors"*s) - readdlm("results/itensors"*s[1:end-4]*"_gc.txt")
27+
readdlm("results/itensors" * s) -
28+
readdlm("results/itensors" * s[1:(end - 4)] * "_gc.txt")
2829
catch
2930
nothing
3031
end
@@ -33,7 +34,7 @@ for j = 1:3
3334
ymax = max(ymax, maximum(data_itensors))
3435
end
3536
data_tenpy = try
36-
readdlm("results/tenpy"*s)
37+
readdlm("results/tenpy" * s)
3738
catch
3839
nothing
3940
end
@@ -42,7 +43,7 @@ for j = 1:3
4243
ymax = max(ymax, maximum(data_tenpy))
4344
end
4445
data_tensornetwork = try
45-
readdlm("results/tensornetwork"*s)
46+
readdlm("results/tensornetwork" * s)
4647
catch
4748
nothing
4849
end
@@ -53,31 +54,34 @@ for j = 1:3
5354
ymin = 10^(floor(log10(ymin)))
5455
ymax = 10^(ceil(log10(ymax)))
5556

56-
for i = 1:numplots
57+
for i in 1:numplots
5758
Dmera = dims[j][1][i]
5859

59-
p = boxplot(data_tensorkit[:,i], label="TensorKit.jl", markersize = M)
60+
p = boxplot(data_tensorkit[:, i]; label="TensorKit.jl", markersize=M)
6061
!isnothing(data_itensors) &&
61-
boxplot!(p, data_itensors[:,i], label="ITensors.jl", markersize = M)
62+
boxplot!(p, data_itensors[:, i]; label="ITensors.jl", markersize=M)
6263
!isnothing(data_tenpy) &&
63-
boxplot!(p, data_tenpy[:,i], label="Tenpy", markersize = M)
64+
boxplot!(p, data_tenpy[:, i]; label="Tenpy", markersize=M)
6465
!isnothing(data_tensornetwork) &&
65-
boxplot!(p, data_tensornetwork[:,i], label="TensorNetwork", markersize = M)
66-
plot!(p, yscale = :log10, yminorticks = true, xticks = [], xgrid = false, xshowaxis = false, ylim = (ymin, ymax))
66+
boxplot!(p, data_tensornetwork[:, i]; label="TensorNetwork", markersize=M)
67+
plot!(p; yscale=:log10, yminorticks=true, xticks=[], xgrid=false, xshowaxis=false,
68+
ylim=(ymin, ymax))
6769
if i == 1
68-
plot!(p, yguide = name[j], yguide_position = :left, yguidefontsize = 10, ytickfontsize = 8, left_margin = 6mm)
69-
plot!(p, title = "χ = $Dmera", titlefontsize = 10)
70+
plot!(p; yguide=name[j], yguide_position=:left, yguidefontsize=10,
71+
ytickfontsize=8, left_margin=6mm)
72+
plot!(p; title="χ = $Dmera", titlefontsize=10)
7073
else
71-
plot!(p, title = "$Dmera", titlefontsize = 10)
72-
plot!(p, left_margin = -5mm, yformatter = _->"", yshowaxis = false)
74+
plot!(p; title="$Dmera", titlefontsize=10)
75+
plot!(p; left_margin=-5mm, yformatter=_ -> "", yshowaxis=false)
7376
end
7477
if i == numplots && j == 3
75-
plot!(p, legendfontsize = 10, legend = :bottomright)
78+
plot!(p; legendfontsize=10, legend=:bottomright)
7679
else
77-
plot!(p, legend = false)
80+
plot!(p; legend=false)
7881
end
7982
meraplots[i, j] = p
8083
end
8184
end
82-
plotgrid = plot(meraplots..., layout=grid(3,numplots), link = :y, thickness_scaling = 1, size = (1500, 800))
85+
plotgrid = plot(meraplots...; layout=grid(3, numplots), link=:y, thickness_scaling=1,
86+
size=(1500, 800))
8387
savefig(plotgrid, "meraresults.pdf")

0 commit comments

Comments
 (0)