Skip to content

Commit c8f866a

Browse files
committed
Add TensorNetworkBenchmarks
1 parent d66b03e commit c8f866a

File tree

2 files changed

+207
-0
lines changed

2 files changed

+207
-0
lines changed
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
module TensorNetworkBenchmarks
2+
3+
include(joinpath(@__DIR__, "..", "utils", "BenchUtils.jl"))
4+
5+
using .BenchUtils
6+
using BenchmarkTools
7+
using TensorKit
8+
using TOML
9+
10+
const SUITE = BenchmarkGroup()
11+
const all_parameters = TOML.parsefile(joinpath(@__DIR__, "benchparams.toml"))
12+
13+
# mpo contraction
14+
# ---------------
15+
function init_mpo_tensors(T, (Vmps, Vmpo, Vphys))
16+
A = Tensor(randn, T, Vmps Vphys Vmps')
17+
M = Tensor(randn, T, Vmpo Vphys Vphys' Vmpo')
18+
FL = Tensor(randn, T, Vmps Vmpo' Vmps')
19+
FR = Tensor(randn, T, Vmps Vmpo Vmps')
20+
return A, M, FL, FR
21+
end
22+
23+
function benchmark_mpo(A, M, FL, FR)
24+
return @tensor FL[4, 2, 1] * A[1, 3, 6] * M[2, 5, 3, 7] * conj(A[4, 5, 8]) * FR[6, 7, 8]
25+
end
26+
27+
function benchmark_mpo!(benchgroup, params::Dict)
28+
haskey(benchgroup, "mpo") || addgroup!(benchgroup, "mpo")
29+
bench = benchgroup["mpo"]
30+
for kwargs in expand_kwargs(params)
31+
benchmark_mpo!(bench; kwargs...)
32+
end
33+
return nothing
34+
end
35+
function benchmark_mpo!(bench; sigmas=nothing, T="Float64", I="Trivial", dims)
36+
T_ = parse_type(T)
37+
I_ = parse_type(I)
38+
39+
Vs = generate_space.(I_, dims, sigmas)
40+
init() = init_mpo_tensors(T_, Vs)
41+
42+
bench[T, I, dims, sigmas] = @benchmarkable benchmark_mpo(A, M, FL, FR) setup = ((A, M, FL, FR) = $init())
43+
44+
return nothing
45+
end
46+
47+
if haskey(all_parameters, "mpo")
48+
g = addgroup!(SUITE, "mpo")
49+
for params in all_parameters["mpo"]
50+
benchmark_mpo!(g, params)
51+
end
52+
end
53+
54+
# pepo contraction
55+
# ----------------
56+
function init_pepo_tensors(T, (Vpeps, Vpepo, Vphys, Venv))
57+
A = Tensor(randn, T, Vpeps Vpeps Vphys Vpeps' Vpeps')
58+
P = Tensor(randn, T, Vpepo Vpepo Vphys Vphys' Vpepo' Vpepo')
59+
FL = Tensor(randn, T, Venv Vpeps Vpepo' Vpeps' Venv')
60+
FD = Tensor(randn, T, Venv Vpeps Vpepo' Vpeps' Venv')
61+
FR = Tensor(randn, T, Venv Vpeps Vpepo Vpeps' Venv')
62+
FU = Tensor(randn, T, Venv Vpeps Vpepo Vpeps' Venv')
63+
return A, P, FL, FD, FR, FU
64+
end
65+
66+
function benchmark_pepo(A, P, FL, FD, FR, FU)
67+
return @tensor FL[18, 7, 4, 2, 1] * FU[1, 3, 6, 9, 10] * A[2, 17, 5, 3, 11] *
68+
P[4, 16, 8, 5, 6, 12] * conj(A[7, 15, 8, 9, 13]) *
69+
FR[10, 11, 12, 13, 14] * FD[14, 15, 16, 17, 18]
70+
end
71+
72+
function benchmark_pepo!(benchgroup, params::Dict)
73+
haskey(benchgroup, "pepo") || addgroup!(benchgroup, "pepo")
74+
bench = benchgroup["pepo"]
75+
for kwargs in expand_kwargs(params)
76+
benchmark_pepo!(bench; kwargs...)
77+
end
78+
return nothing
79+
end
80+
function benchmark_pepo!(bench; sigmas=nothing, T="Float64", I="Trivial", dims)
81+
T_ = parse_type(T)
82+
I_ = parse_type(I)
83+
84+
Vs = generate_space.(I_, dims, sigmas)
85+
init() = init_pepo_tensors(T_, Vs)
86+
87+
bench[T, I, dims, sigmas] = @benchmarkable benchmark_pepo(A, P, FL, FD, FR, FU) setup = ((A, P, FL, FD, FR, FU) = $init())
88+
89+
return nothing
90+
end
91+
92+
if haskey(all_parameters, "pepo")
93+
g = addgroup!(SUITE, "pepo")
94+
for params in all_parameters["pepo"]
95+
benchmark_pepo!(g, params)
96+
end
97+
end
98+
99+
# mera contraction
100+
# ----------------
101+
function init_mera_tensors(T, V)
102+
u = Tensor(randn, T, V V V' V')
103+
w = Tensor(randn, T, V V V')
104+
ρ = Tensor(randn, T, V V V V' V' V')
105+
h = Tensor(randn, T, V V V V' V' V')
106+
return u, w, ρ, h
107+
end
108+
109+
function benchmark_mera(u, w, ρ, h)
110+
return @tensor (((((((h[9, 3, 4, 5, 1, 2] * u[1, 2, 7, 12]) * conj(u[3, 4, 11, 13])) *
111+
(u[8, 5, 15, 6] * w[6, 7, 19])) *
112+
(conj(u[8, 9, 17, 10]) * conj(w[10, 11, 22]))) *
113+
((w[12, 14, 20] * conj(w[13, 14, 23])) * ρ[18, 19, 20, 21, 22, 23])) *
114+
w[16, 15, 18]) * conj(w[16, 17, 21]))
115+
end
116+
117+
function benchmark_mera!(benchgroup, params::Dict)
118+
haskey(benchgroup, "mera") || addgroup!(benchgroup, "mera")
119+
bench = benchgroup["mera"]
120+
for kwargs in expand_kwargs(params)
121+
benchmark_mera!(bench; kwargs...)
122+
end
123+
return nothing
124+
end
125+
126+
function benchmark_mera!(bench; sigmas=nothing, T="Float64", I="Trivial", dims)
127+
T_ = parse_type(T)
128+
I_ = parse_type(I)
129+
130+
Vs = generate_space.(I_, dims, sigmas)
131+
init() = init_mera_tensors(T_, Vs)
132+
133+
bench[T, I, dims, sigmas] = @benchmarkable benchmark_mera(u, w, ρ, h) setup = ((u, w, ρ, h) = $init())
134+
135+
return nothing
136+
end
137+
138+
if haskey(all_parameters, "mera")
139+
g = addgroup!(SUITE, "mera")
140+
for params in all_parameters["mera"]
141+
benchmark_mera!(g, params)
142+
end
143+
end
144+
145+
end
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# MPO
2+
# ---
3+
# dims = [mps, mpo, phys]
4+
5+
[[mpo]]
6+
T = ["Float64"]
7+
I = "Trivial"
8+
dims = [[10, 4, 3], [40, 4, 3], [160, 4, 3], [640, 4, 3], [2560, 4, 3], [100, 10, 10], [200, 10, 10], [300, 20, 20]]
9+
10+
[[mpo]]
11+
T = ["Float64"]
12+
I = "Z2Irrep"
13+
dims = [[10, 4, 4], [40, 4, 4], [160, 4, 4], [640, 4, 4], [2560, 4, 4], [100, 10, 10], [200, 10, 10], [300, 20, 20]]
14+
sigmas = [0.5, 0.5, 0.5]
15+
16+
[[mpo]]
17+
T = ["Float64"]
18+
I = "U1Irrep"
19+
dims = [[40, 5, 3], [160, 5, 3], [640, 5, 3], [2560, 5, 3], [6120, 5, 3], [200, 20, 20], [400, 20, 20], [400, 40, 40]]
20+
sigmas = [0.5, 0.5, 0.5]
21+
22+
# PEPO
23+
# ----
24+
# dims = [peps, pepo, phys, env]
25+
26+
[[pepo]]
27+
T = ["Float64"]
28+
I = "Trivial"
29+
dims = [[3, 2, 2, 50], [3, 3, 3, 100], [4, 2, 2, 50], [4, 3, 3, 100], [5, 2, 2, 50], [5, 2, 3, 100], [6, 2, 2, 50], [6, 3, 2, 100]]
30+
31+
[[pepo]]
32+
T = ["Float64"]
33+
I = "Z2Irrep"
34+
dims = [[4, 2, 2, 50], [4, 4, 4, 100], [5, 2, 2, 50], [5, 3, 4, 100], [6, 2, 2, 50], [6, 2, 4, 100], [8, 2, 2, 50], [8, 3, 2, 100]]
35+
sigmas = [0.5, 0.5, 0.5, 0.5]
36+
37+
[[pepo]]
38+
T = ["Float64"]
39+
I = "U1Irrep"
40+
dims = [[4, 2, 2, 100], [4, 4, 4, 200], [6, 2, 2, 100], [6, 3, 4, 200], [8, 2, 2, 100], [8, 2, 4, 200], [10, 2, 2, 50], [10, 3, 2, 100]]
41+
sigmas = [0.5, 0.5, 0.5, 0.5]
42+
43+
# MERA
44+
# ----
45+
# dims = mera
46+
47+
[[mera]]
48+
T = ["Float64"]
49+
I = "Trivial"
50+
dims = [2, 3, 4, 8, 12, 16]
51+
52+
[[mera]]
53+
T = ["Float64"]
54+
I = "Z2Irrep"
55+
dims = [2, 4, 8, 12, 16, 20]
56+
sigmas = [0.5]
57+
58+
[[mera]]
59+
T = ["Float64"]
60+
I = "U1Irrep"
61+
dims = [4, 8, 12, 16, 22, 28]
62+
sigmas = [0.5]

0 commit comments

Comments
 (0)