Hi!
I need to calculate the trace of the multiplication of two MPOs, namely tr(A::MPO, B::MPO)
. The naive procedure, e.g.,
using ITensors
sites = siteinds("SpinHalf", 3)
A = randomMPO(sites)
B = randomMPO(sites)
println("tr(A*B) = ", tr((A*prime(B)); plev=Pair(0,2)))
works well, but is highly inefficient. It first calculates all of the elements of A*B, while only the diagonals are needed.
Is there a way to contract only the relevant matrices and get the diagonal elements only?
I am using Julia v1.7.0 and ITensors v0.3.18
Many thanks in advance
-Lidia