Skip to content

Commit c1478ed

Browse files
committed
precompute contraction GL*A and A*GR in JordanMPO_AC and _AC2
1 parent ef1beb4 commit c1478ed

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

src/algorithms/derivatives/hamiltonian_derivatives.jl

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,12 @@ function AC_hamiltonian(
138138
finished = removeunit(GL[end], 2)
139139
end
140140

141-
# continuing
142-
A = W.A
143-
continuing = (GL[2:(end - 1)], A, GR[2:(end - 1)])
141+
if nonzero_length(W.A) > 0
142+
@tensor GLW[-1 -2 -3; -4 -5] ≔ GL[2:(end - 1)][-1 1; -4] * W.A[1 -2; -5 -3]
143+
continuing = (GLW, permute(GR[2:(end - 1)], (2, 1), (3,)))
144+
else
145+
continuing = missing
146+
end
144147

145148
return JordanMPO_AC_Hamiltonian(
146149
onsite, not_started, finished, starting, ending, continuing
@@ -287,7 +290,15 @@ function AC2_hamiltonian(
287290

288291
# continuing - continuing
289292
# TODO: MPODerivativeOperator code reuse + optimization
290-
AA = (GL[2:(end - 1)], W1.A, W2.A, GR[2:(end - 1)])
293+
# TODO: One should only calculate these operators if necessary. One can do this by checking nonzero_length(A1) > 0 && nonzero_length(A2) > 0 and then setting AA=missing or as we discussed via bit matrix multiplication.
294+
## TODO: Think about how one could and whether one should store these objects and use them for (a) advancing environments in iDMRG, (b) reuse ind backwards-sweep in IDMRG, (c) subspace expansion
295+
if nonzero_length(W1.A) > 0 && nonzero_length(W2.A) > 0
296+
@tensor GLW[-1 -2 -3; -4 -5] ≔ GL[2:(end -1)][-1 1; -4] * W1.A[1 -2; -5 -3]
297+
@tensor GWR[-1 -2 -3; -4 -5] ≔ W2.A[-1 -5; -3 1] * GR[2:(end -1)][-2 1; -4]
298+
AA = (GLW, GWR)
299+
else
300+
AA = missing
301+
end
291302

292303
return JordanMPO_AC2_Hamiltonian(II, IC, ID, CB, CA, AB, AA, BE, DE, EE)
293304
end
@@ -303,9 +314,9 @@ function (H::JordanMPO_AC_Hamiltonian)(x::MPSTensor)
303314
ismissing(H.C) || @plansor y[-1 -2; -3] += x[-1 2; 1] * H.C[-2 -3; 2 1]
304315
ismissing(H.B) || @plansor y[-1 -2; -3] += H.B[-1 -2; 1 2] * x[1 2; -3]
305316

306-
GL, A, GR = H.A
307-
if nonzero_length(A) > 0
308-
@plansor y[-1 -2; -3] += GL[-1 5; 4] * x[4 2; 1] * A[5 -2; 2 3] * GR[1 3; -3]
317+
if !ismissing(H.A)
318+
GLW, GR = H.A
319+
@tensor y[-1 -2; -3] += GLW[-1 -2 3; 1 2] * x[1 2; 4] * GR[3 4; -3]
309320
end
310321

311322
return y
@@ -323,11 +334,9 @@ function (H::JordanMPO_AC2_Hamiltonian)(x::MPOTensor)
323334
ismissing(H.DE) || @plansor y[-1 -2; -3 -4] += x[-1 1; -3 -4] * H.DE[-2; 1]
324335
ismissing(H.EE) || @plansor y[-1 -2; -3 -4] += x[1 -2; -3 -4] * H.EE[-1; 1]
325336

326-
GL, A1, A2, GR = H.AA
327-
if nonzero_length(A1) > 0 && nonzero_length(A2) > 0
328-
# TODO: there are too many entries here, this could be further optimized
329-
@plansor y[-1 -2; -3 -4] += GL[-1 7; 6] * x[6 5; 1 3] * A1[7 -2; 5 4] *
330-
A2[4 -4; 3 2] * GR[1 2; -3]
337+
if !ismissing(H.AA)
338+
GLW, GWR = H.AA
339+
@tensor y[-1 -2; -3 -4] += GLW[-1 -2 3; 1 2] * x[1 2; 4 5] * GWR[3 4 5; -3 -4]
331340
end
332341

333342
return y

0 commit comments

Comments
 (0)