Skip to content

Commit

Permalink
auto swap in addIntr4
Browse files Browse the repository at this point in the history
  • Loading branch information
qyli committed May 17, 2024
1 parent e336769 commit 1bd9f6a
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
31 changes: 31 additions & 0 deletions src/IntrTree/addIntr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,37 @@ function _addZ!(OR::LocalOperator{2, 2}, Z::AbstractTensorMap)
return OR
end

# swap two operators to deal with horizontal bond
_swap(A::LocalOperator{1, 1}, B::LocalOperator{1, 1}) = B, A
_swap(A::LocalOperator{1, 1}, B::LocalOperator{1, 2}) = B, A
_swap(A::LocalOperator{2, 1}, B::LocalOperator{1, 1}) = B, A
function _swap(A::LocalOperator{1, 2}, B::LocalOperator{2, 1})
return _swapOp(B), _swapOp(A)
end
function _swap(A::LocalOperator{1, 2}, B::LocalOperator{2, 2})
# | | | |
# A-- --B--va --> B-- --A--va
# | | | |

@tensor AB[d e; a b f] := A.A[a b c] * B.A[c d e f]
# QR
TA, TB = leftorth(AB)

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)
end
function _swap(A::LocalOperator{2, 2}, B::LocalOperator{2,1})
# | | | |
# va--A-- --B --> va--B-- --A
# | | | |

@tensor AB[a e f; b c] := A.A[a b c d] * B.A[d e f]
# QR
TA, TB = rightorth(AB)

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)
end





Expand Down
11 changes: 8 additions & 3 deletions src/IntrTree/addIntr4.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,25 @@ function addIntr4!(Root::InteractionTreeNode, O::NTuple{4,AbstractTensorMap}, si
(A, B, C, D) = map(1:4) do i
LocalOperator(O[i], name[i], si[i])
end
_addtag!(A, B, C, D)

# deal with the permutation 1<->2 and 3<->4
if si[1] > si[2]
A, B = _leftOp(B), _rightOp(A)
A, B = _swap(A, B)
si = (si[2], si[1], si[3], si[4])
!isnothing(Z) && (strength *= -1)
end
if si[3] > si[4]
C, D = _leftOp(D), _rightOp(C)
C, D = _swap(C, D)
si = (si[1], si[2], si[4], si[3])
!isnothing(Z) && (strength *= -1)
end

_addtag!(A, B, C, D)

# ============ reduce to 2-site term ===========
if A.si == B.si && C.si == D.si
return addIntr2!(Root, A * B, C * D, strength, nothing; value = value)
end
if A.si == C.si && B.si == D.si
# D
# C Z Z Z Z -BD
Expand Down

0 comments on commit 1bd9f6a

Please sign in to comment.