Skip to content

Commit

Permalink
Small permute and contraction order changes in TRG and BTRG (#22)
Browse files Browse the repository at this point in the history
* get rid of unnecessary permutes in `TRG`

* implement the optimal contraction ordering for `BTRG`
  • Loading branch information
VictorVanthilt authored Feb 15, 2025
1 parent fccdcab commit 116d80a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
12 changes: 7 additions & 5 deletions src/schemes/btrg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,13 @@ function step!(scheme::BTRG, trunc::TensorKit.TruncationScheme)
S1 = scheme.S1
S2 = scheme.S2

@tensor opt = true scheme.T[-1 -2; -3 -4] := D[-1 1; 8] * S1[2; 1] * B[-2; 3 2] *
S2[3; 4] *
C[4; 5 -3] *
S1[5; 6] * A[7 6; -4] * S2[8; 7]

@tensor scheme.T[-1 -2; -3 -4] := D[-1 7; 4] *
S1[1; 7] *
B[-2; 3 1] *
S2[3; 2] *
C[2; 8 -3] *
S1[8; 5] *
A[6 5; -4] * S2[4; 6]
scheme.S1 = S1′
scheme.S2 = S2′
return scheme
Expand Down
11 changes: 3 additions & 8 deletions src/schemes/trg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,12 @@ function step!(scheme::TRG, trunc::TensorKit.TruncationScheme)

U, S, V, _ = tsvd(scheme.T, ((1, 4), (2, 3)); trunc=trunc)

# Flip legs to their original domain (to mitigate space mismatch at the end)
U = permute(U, ((1,), (2, 3)))
V = permute(V, ((1, 2), (3,)))

@plansor begin
C[-1; -2 -3] := U[-1; -2 1] * sqrt(S)[1; -3]
D[-1 -2; -3] := sqrt(S)[-1; 1] * V[1 -2; -3]
C[-1 -2; -3] := U[-1 -2; 1] * sqrt(S)[1; -3]
D[-1; -2 -3] := sqrt(S)[-1; 1] * V[1; -2 -3]
end

# @plansor complains here, not sure why
@tensor scheme.T[-1 -2; -3 -4] := D[-1 1; 4] * B[-2; 3 1] * C[3; 2 -3] * A[4 2; -4]
@tensor scheme.T[-1 -2; -3 -4] := D[-1; 1 4] * B[-2; 3 1] * C[3 2; -3] * A[4 2; -4]
return scheme
end

Expand Down

0 comments on commit 116d80a

Please sign in to comment.