@@ -15,7 +15,7 @@ function _tomat(tto::TensorTrain{T,4}) where {T}
15
15
return mat
16
16
end
17
17
18
- function _tovec (tt:: TensorTrain{T, 3} ) where {T}
18
+ function _tovec (tt:: TensorTrain{T,3} ) where {T}
19
19
sitedims = TCI. sitedims (tt)
20
20
localdims1 = [s[1 ] for s in sitedims]
21
21
return evaluate .(Ref (tt), CartesianIndices (Tuple (localdims1))[:])
28
28
@test vec (reshape (permutedims (a, (2 , 1 , 3 )), 3 , :) * reshape (permutedims (b, (1 , 3 , 2 )), :, 5 )) ≈ vec (ab)
29
29
end
30
30
31
+ function _gen_testdata_TTO_TTO ()
32
+ N = 4
33
+ bonddims_a = [1 , 2 , 3 , 2 , 1 ]
34
+ bonddims_b = [1 , 2 , 3 , 2 , 1 ]
35
+ localdims1 = [2 , 2 , 2 , 2 ]
36
+ localdims2 = [3 , 3 , 3 , 3 ]
37
+ localdims3 = [2 , 2 , 2 , 2 ]
38
+
39
+ a = TensorTrain {ComplexF64,4} ([
40
+ rand (ComplexF64, bonddims_a[n], localdims1[n], localdims2[n], bonddims_a[n+ 1 ])
41
+ for n = 1 : N
42
+ ])
43
+ b = TensorTrain {ComplexF64,4} ([
44
+ rand (ComplexF64, bonddims_b[n], localdims2[n], localdims3[n], bonddims_b[n+ 1 ])
45
+ for n = 1 : N
46
+ ])
47
+ return N, a, b, localdims1, localdims2, localdims3
48
+ end
49
+
50
+ function _gen_testdata_TTO_TTS ()
51
+ N = 4
52
+ bonddims_a = [1 , 2 , 3 , 2 , 1 ]
53
+ bonddims_b = [1 , 2 , 3 , 2 , 1 ]
54
+ localdims1 = [3 , 3 , 3 , 3 ]
55
+ localdims2 = [3 , 3 , 3 , 3 ]
56
+
57
+ a = TensorTrain {ComplexF64,4} ([
58
+ rand (ComplexF64, bonddims_a[n], localdims1[n], localdims2[n], bonddims_a[n+ 1 ])
59
+ for n = 1 : N
60
+ ])
61
+ b = TensorTrain {ComplexF64,3} ([
62
+ rand (ComplexF64, bonddims_b[n], localdims2[n], bonddims_b[n+ 1 ])
63
+ for n = 1 : N
64
+ ])
65
+ return N, a, b, localdims1, localdims2
66
+ end
67
+
31
68
@testset " MPO-MPO contraction" for f in [nothing , x -> 2 * x], algorithm in [:TCI , :naive ]
69
+ #= =
32
70
N = 4
33
71
bonddims_a = [1, 2, 3, 2, 1]
34
72
bonddims_b = [1, 2, 3, 2, 1]
44
82
rand(ComplexF64, bonddims_b[n], localdims2[n], localdims3[n], bonddims_b[n+1])
45
83
for n = 1:N
46
84
])
85
+ ==#
86
+ N, a, b, localdims1, localdims2, localdims3 = _gen_testdata_TTO_TTO ()
47
87
48
88
if f != = nothing && algorithm === :naive
49
89
@test_throws ErrorException contract (a, b; f= f, algorithm= algorithm)
59
99
end
60
100
61
101
@testset " MPO-MPS contraction" for f in [nothing , x -> 2 * x], algorithm in [:TCI , :naive ]
102
+ #= =
62
103
N = 4
63
104
bonddims_a = [1, 2, 3, 2, 1]
64
105
bonddims_b = [1, 2, 3, 2, 1]
73
114
rand(ComplexF64, bonddims_b[n], localdims2[n], bonddims_b[n+1])
74
115
for n = 1:N
75
116
])
117
+ ==#
118
+ N, a, b, localdims1, localdims2 = _gen_testdata_TTO_TTS ()
76
119
77
120
if f != = nothing && algorithm === :naive
78
121
@test_throws ErrorException contract (a, b; f= f, algorithm= algorithm)
90
133
end
91
134
end
92
135
end
136
+
137
+
138
+ @testset " MPO-MPO contraction (zipup)" for method in [:SVD , :LU ]
139
+ N, a, b, localdims1, localdims2, localdims3 = _gen_testdata_TTO_TTO ()
140
+ ab = contract (a, b; algorithm= :zipup , method= method)
141
+ @test _tomat (ab) ≈ _tomat (a) * _tomat (b)
142
+ end
143
+
144
+ @testset " MPO-MPS contraction (zipup)" for method in [:SVD , :LU ]
145
+ N, a, b, localdims1, localdims2 = _gen_testdata_TTO_TTS ()
146
+ ab = contract (a, b; algorithm= :zipup , method= method)
147
+ @test _tovec (ab) ≈ _tomat (a) * _tovec (b)
148
+ end
0 commit comments