@@ -15,6 +15,12 @@ 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}
19
+ sitedims = TCI. sitedims (tt)
20
+ localdims1 = [s[1 ] for s in sitedims]
21
+ return evaluate .(Ref (tt), CartesianIndices (Tuple (localdims1))[:])
22
+ end
23
+
18
24
@testset " _contract" begin
19
25
a = rand (2 , 3 , 4 )
20
26
b = rand (2 , 5 , 4 )
51
57
end
52
58
end
53
59
end
60
+
61
+ @testset " MPO-MPS contraction" for f in [nothing , x -> 2 * x], algorithm in [:TCI , :naive ]
62
+ N = 4
63
+ bonddims_a = [1 , 2 , 3 , 2 , 1 ]
64
+ bonddims_b = [1 , 2 , 3 , 2 , 1 ]
65
+ localdims1 = [3 , 3 , 3 , 3 ]
66
+ localdims2 = [3 , 3 , 3 , 3 ]
67
+
68
+ a = TensorTrain {ComplexF64,4} ([
69
+ rand (ComplexF64, bonddims_a[n], localdims1[n], localdims2[n], bonddims_a[n+ 1 ])
70
+ for n = 1 : N
71
+ ])
72
+ b = TensorTrain {ComplexF64,3} ([
73
+ rand (ComplexF64, bonddims_b[n], localdims2[n], bonddims_b[n+ 1 ])
74
+ for n = 1 : N
75
+ ])
76
+
77
+ if f != = nothing && algorithm === :naive
78
+ @test_throws ErrorException contract (a, b; f= f, algorithm= algorithm)
79
+ @test_throws ErrorException contract (b, a; f= f, algorithm= algorithm)
80
+ else
81
+ ab = contract (a, b; f= f, algorithm= algorithm)
82
+ ba = contract (b, a; f= f, algorithm= algorithm)
83
+ @test sitedims (ab) == [[localdims1[i]] for i = 1 : N]
84
+ if f === nothing
85
+ @test _tovec (ab) ≈ _tomat (a) * _tovec (b)
86
+ @test transpose (_tovec (ba)) ≈ transpose (_tovec (b)) * _tomat (a)
87
+ else
88
+ @test _tovec (ab) ≈ f .(_tomat (a) * _tovec (b))
89
+ @test transpose (_tovec (ba)) ≈ f .(transpose (_tovec (b)) * _tomat (a))
90
+ end
91
+ end
92
+ end
0 commit comments