Skip to content

Commit b9b8dfc

Browse files
authored
Update benchmark suite to current TensorKit API (#477)
- Replace removed `Tensor(randn, T, space)` constructors with `randn(T, space)` - Replace removed `tsvd!` with `svd_compact!` (MatrixAlgebraKit API) - Drop removed `TensorOperations.enable_cache`/`cache` calls from the comparison runner
1 parent e3f6bd5 commit b9b8dfc

4 files changed

Lines changed: 29 additions & 40 deletions

File tree

benchmark/TensorKitBenchmarks/linalg/LinalgBenchmarks.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ function benchmark_svd!(bench; sigmas = nothing, T = "Float64", I = "Trivial", d
6767
I_ = parse_type(I)
6868
Vs = generate_space.(I_, dims, sigmas)
6969
init() = init_svd_tensor(T_, Vs)
70-
bench[T, I, dims, sigmas] = @benchmarkable tsvd!(A) setup = (A = $init())
70+
bench[T, I, dims, sigmas] = @benchmarkable svd_compact!(A) setup = (A = $init())
7171
return nothing
7272
end
7373

benchmark/TensorKitBenchmarks/tensornetworks/TensorNetworkBenchmarks.jl

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ const all_parameters = TOML.parsefile(joinpath(@__DIR__, "benchparams.toml"))
1313
# mpo contraction
1414
# ---------------
1515
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')
16+
A = randn(T, Vmps Vphys Vmps')
17+
M = randn(T, Vmpo Vphys Vphys' Vmpo')
18+
FL = randn(T, Vmps Vmpo' Vmps')
19+
FR = randn(T, Vmps Vmpo Vmps')
2020
return A, M, FL, FR
2121
end
2222

@@ -53,12 +53,12 @@ end
5353
# pepo contraction
5454
# ----------------
5555
function init_pepo_tensors(T, (Vpeps, Vpepo, Vphys, Venv))
56-
A = Tensor(randn, T, Vpeps Vpeps Vphys Vpeps' Vpeps')
57-
P = Tensor(randn, T, Vpepo Vpepo Vphys Vphys' Vpepo' Vpepo')
58-
FL = Tensor(randn, T, Venv Vpeps Vpepo' Vpeps' Venv')
59-
FD = Tensor(randn, T, Venv Vpeps Vpepo' Vpeps' Venv')
60-
FR = Tensor(randn, T, Venv Vpeps Vpepo Vpeps' Venv')
61-
FU = Tensor(randn, T, Venv Vpeps Vpepo Vpeps' Venv')
56+
A = randn(T, Vpeps Vpeps Vphys Vpeps' Vpeps')
57+
P = randn(T, Vpepo Vpepo Vphys Vphys' Vpepo' Vpepo')
58+
FL = randn(T, Venv Vpeps Vpepo' Vpeps' Venv')
59+
FD = randn(T, Venv Vpeps Vpepo' Vpeps' Venv')
60+
FR = randn(T, Venv Vpeps Vpepo Vpeps' Venv')
61+
FU = randn(T, Venv Vpeps Vpepo Vpeps' Venv')
6262
return A, P, FL, FD, FR, FU
6363
end
6464

@@ -97,10 +97,10 @@ end
9797
# mera contraction
9898
# ----------------
9999
function init_mera_tensors(T, V)
100-
u = Tensor(randn, T, V V V' V')
101-
w = Tensor(randn, T, V V V')
102-
ρ = Tensor(randn, T, V V V V' V' V')
103-
h = Tensor(randn, T, V V V V' V' V')
100+
u = randn(T, V V V' V')
101+
w = randn(T, V V V')
102+
ρ = randn(T, V V V V' V' V')
103+
h = randn(T, V V V V' V' V')
104104
return u, w, ρ, h
105105
end
106106

benchmark/comparisons/run_tensorkit.jl

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ include("tensorkit_timers.jl")
44
using LinearAlgebra: LinearAlgebra
55
LinearAlgebra.BLAS.set_num_threads(1)
66

7-
using TensorOperations: TensorOperations
8-
TensorOperations.enable_cache(; maxrelsize = 0.7)
97
using TensorKit: TensorKit
108
using TensorKit: ℂ, Z2Space, U1Space
119
using DelimitedFiles
@@ -32,7 +30,6 @@ for i in 1:N
3230
times, times_gc = mpo_timer(; outer = K)
3331
mpo_triv_times[:, i] = times
3432
mpo_triv_times_gc[:, i] = times_gc
35-
empty!(TensorOperations.cache)
3633

3734
tavg = sum(times) / K
3835

@@ -60,7 +57,6 @@ for i in 1:N
6057
times, times_gc = mpo_timer(; outer = K)
6158
mpo_z2_times[:, i] = times
6259
mpo_z2_times_gc[:, i] = times_gc
63-
empty!(TensorOperations.cache)
6460

6561
tavg = sum(times) / K
6662

@@ -88,7 +84,6 @@ for i in 1:N
8884
times, times_gc = mpo_timer(; outer = K)
8985
mpo_u1_times[:, i] = times
9086
mpo_u1_times_gc[:, i] = times_gc
91-
empty!(TensorOperations.cache)
9287

9388
tavg = sum(times) / K
9489

@@ -120,7 +115,6 @@ for i in 1:N
120115
times, times_gc = pepo_timer(; outer = K)
121116
pepo_triv_times[:, i] = times
122117
pepo_triv_times_gc[:, i] = times_gc
123-
empty!(TensorOperations.cache)
124118

125119
tavg = sum(times) / K
126120

@@ -150,7 +144,6 @@ for i in 1:N
150144
times, times_gc = pepo_timer(; outer = K)
151145
pepo_z2_times[:, i] = times
152146
pepo_z2_times_gc[:, i] = times_gc
153-
empty!(TensorOperations.cache)
154147

155148
tavg = sum(times) / K
156149

@@ -180,7 +173,6 @@ for i in 1:N
180173
times, times_gc = pepo_timer(; outer = K)
181174
pepo_u1_times[:, i] = times
182175
pepo_u1_times_gc[:, i] = times_gc
183-
empty!(TensorOperations.cache)
184176

185177
tavg = sum(times) / K
186178

@@ -207,7 +199,6 @@ for i in 1:N
207199

208200
mera_triv_times[:, i] = times
209201
mera_triv_times_gc[:, i] = times_gc
210-
empty!(TensorOperations.cache)
211202

212203
tavg = sum(times) / K
213204

@@ -232,7 +223,6 @@ for i in 1:N
232223

233224
mera_z2_times[:, i] = times
234225
mera_z2_times_gc[:, i] = times_gc
235-
empty!(TensorOperations.cache)
236226

237227
tavg = sum(times) / K
238228

@@ -257,7 +247,6 @@ for i in 1:N
257247

258248
mera_u1_times[:, i] = times
259249
mera_u1_times_gc[:, i] = times_gc
260-
empty!(TensorOperations.cache)
261250

262251
tavg = sum(times) / K
263252

benchmark/comparisons/tensorkit_timers.jl

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ module TensorKitTimers
44
using ..Timers: Timers
55

66
function mpo_timer(f = randn, T = Float64; Vmpo, Vmps, Vphys)
7-
A = Tensor(f, T, Vmps Vphys Vmps')
8-
M = Tensor(f, T, Vmpo Vphys Vphys' Vmpo')
9-
FL = Tensor(f, T, Vmps Vmpo' Vmps')
10-
FR = Tensor(f, T, Vmps Vmpo Vmps')
7+
A = f(T, Vmps Vphys Vmps')
8+
M = f(T, Vmpo Vphys Vphys' Vmpo')
9+
FL = f(T, Vmps Vmpo' Vmps')
10+
FR = f(T, Vmps Vmpo Vmps')
1111

1212
return Timers.Timer(A, M, FL, FR) do A, M, FL, FR
1313
@tensor C = FL[4, 2, 1] * A[1, 3, 6] * M[2, 5, 3, 7] * conj(A[4, 5, 8]) *
@@ -17,12 +17,12 @@ module TensorKitTimers
1717
end
1818

1919
function pepo_timer(f = randn, T = Float64; Vpepo, Vpeps, Venv, Vphys)
20-
A = Tensor(f, T, Vpeps Vpeps Vphys Vpeps' Vpeps')
21-
P = Tensor(f, T, Vpepo Vpepo Vphys Vphys' Vpepo' Vpepo')
22-
FL = Tensor(f, T, Venv Vpeps Vpepo' Vpeps' Venv')
23-
FD = Tensor(f, T, Venv Vpeps Vpepo' Vpeps' Venv')
24-
FR = Tensor(f, T, Venv Vpeps Vpepo Vpeps' Venv')
25-
FU = Tensor(f, T, Venv Vpeps Vpepo Vpeps' Venv')
20+
A = f(T, Vpeps Vpeps Vphys Vpeps' Vpeps')
21+
P = f(T, Vpepo Vpepo Vphys Vphys' Vpepo' Vpepo')
22+
FL = f(T, Venv Vpeps Vpepo' Vpeps' Venv')
23+
FD = f(T, Venv Vpeps Vpepo' Vpeps' Venv')
24+
FR = f(T, Venv Vpeps Vpepo Vpeps' Venv')
25+
FU = f(T, Venv Vpeps Vpepo Vpeps' Venv')
2626
return Timers.Timer(A, P, FL, FD, FR, FU) do A, P, FL, FD, FR, FU
2727
@tensor C = FL[18, 7, 4, 2, 1] * FU[1, 3, 6, 9, 10] *
2828
A[2, 17, 5, 3, 11] * P[4, 16, 8, 5, 6, 12] * conj(A[7, 15, 8, 9, 13]) *
@@ -32,10 +32,10 @@ module TensorKitTimers
3232
end
3333

3434
function mera_timer(f = randn, T = Float64; Vmera)
35-
u = Tensor(f, T, Vmera Vmera Vmera' Vmera')
36-
w = Tensor(f, T, Vmera Vmera Vmera')
37-
ρ = Tensor(f, T, Vmera Vmera Vmera Vmera' Vmera' Vmera')
38-
h = Tensor(f, T, Vmera Vmera Vmera Vmera' Vmera' Vmera')
35+
u = f(T, Vmera Vmera Vmera' Vmera')
36+
w = f(T, Vmera Vmera Vmera')
37+
ρ = f(T, Vmera Vmera Vmera Vmera' Vmera' Vmera')
38+
h = f(T, Vmera Vmera Vmera Vmera' Vmera' Vmera')
3939
return Timers.Timer(u, w, ρ, h) do u, w, ρ, h
4040
@tensor C = (
4141
(

0 commit comments

Comments
 (0)