Skip to content

Commit 1bd9f6a

Browse files
author
qyli
committed
auto swap in addIntr4
1 parent e336769 commit 1bd9f6a

File tree

2 files changed

+39
-3
lines changed

2 files changed

+39
-3
lines changed

src/IntrTree/addIntr.jl

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,37 @@ function _addZ!(OR::LocalOperator{2, 2}, Z::AbstractTensorMap)
9898
return OR
9999
end
100100

101+
# swap two operators to deal with horizontal bond
102+
_swap(A::LocalOperator{1, 1}, B::LocalOperator{1, 1}) = B, A
103+
_swap(A::LocalOperator{1, 1}, B::LocalOperator{1, 2}) = B, A
104+
_swap(A::LocalOperator{2, 1}, B::LocalOperator{1, 1}) = B, A
105+
function _swap(A::LocalOperator{1, 2}, B::LocalOperator{2, 1})
106+
return _swapOp(B), _swapOp(A)
107+
end
108+
function _swap(A::LocalOperator{1, 2}, B::LocalOperator{2, 2})
109+
# | | | |
110+
# A-- --B--va --> B-- --A--va
111+
# | | | |
112+
113+
@tensor AB[d e; a b f] := A.A[a b c] * B.A[c d e f]
114+
# QR
115+
TA, TB = leftorth(AB)
116+
117+
return LocalOperator(permute(TA, (1,), (2, 3)), B.name, B.si, B.strength), LocalOperator(permute(TB, (1, 2), (3, 4)), A.name, A.si, A.strength)
118+
end
119+
function _swap(A::LocalOperator{2, 2}, B::LocalOperator{2,1})
120+
# | | | |
121+
# va--A-- --B --> va--B-- --A
122+
# | | | |
123+
124+
@tensor AB[a e f; b c] := A.A[a b c d] * B.A[d e f]
125+
# QR
126+
TA, TB = rightorth(AB)
127+
128+
return LocalOperator(permute(TA, (1, 2), (3, 4)), B.name, B.si, B.strength), LocalOperator(permute(TB, (1, 2), (3,)), A.name, A.si, A.strength)
129+
end
130+
131+
101132

102133

103134

src/IntrTree/addIntr4.jl

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,25 @@ function addIntr4!(Root::InteractionTreeNode, O::NTuple{4,AbstractTensorMap}, si
3838
(A, B, C, D) = map(1:4) do i
3939
LocalOperator(O[i], name[i], si[i])
4040
end
41-
_addtag!(A, B, C, D)
4241

4342
# deal with the permutation 1<->2 and 3<->4
4443
if si[1] > si[2]
45-
A, B = _leftOp(B), _rightOp(A)
44+
A, B = _swap(A, B)
4645
si = (si[2], si[1], si[3], si[4])
4746
!isnothing(Z) && (strength *= -1)
4847
end
4948
if si[3] > si[4]
50-
C, D = _leftOp(D), _rightOp(C)
49+
C, D = _swap(C, D)
5150
si = (si[1], si[2], si[4], si[3])
5251
!isnothing(Z) && (strength *= -1)
5352
end
5453

54+
_addtag!(A, B, C, D)
55+
56+
# ============ reduce to 2-site term ===========
57+
if A.si == B.si && C.si == D.si
58+
return addIntr2!(Root, A * B, C * D, strength, nothing; value = value)
59+
end
5560
if A.si == C.si && B.si == D.si
5661
# D
5762
# C Z Z Z Z -BD

0 commit comments

Comments
 (0)