hi, here’s a bit of a tedious question regarding the more inner workings of ITensors and maybe NDTensors, there’s some backstory below but I guess in a nutshell it goes like:
is it normal that a function like
using ITensors, LinearAlgebra
function func1(it::ITensor)
it_a = array(it) #or equivalently(?) Array(it, inds(it))
u,s,vd = svd(it_a)
end
is type unstable (at least according to @code_warntype
/@descend_code_warntype
) ? And if so, is there a way to make it stable? (and should I worry about it at all?)
Long story short, I was playing around with tensor decompositions trying to find a way to speedup my code (always a bad idea it seems…) and realized that I could get a reasonable speed gain if I was replacing in one of my functions an ITensor by a julia array for the intermediate steps, using calls like
my_array = Array(my_itensor, inds(my_itensor))
I was a bit surprised by this, but in the end I decided to stop worrying and be happy with it. But then later on when I was inspecting my code for type stability issues I saw a bloodbath there, basically everything starting from the first inds(itensor)
was returning me ::Any
types, which I’m no super julia expert, but I’m told is really not good for performance.
After some looking around I stumbled upon this page
https://itensor.github.io/ITensors.jl/dev/AdvancedUsageGuide.html#NDTensors-and-ITensors
which to be honest I didn’t fully understand (I’m relatively new to julia’s magic inner workings), but if I get it right it basically says that some extent of type instability can come up when messing around with ITensors, and that maybe working directly with the underlying NDTensors could alleviate that.
So I started digging a bit into NDTensors but got a bit lost there, the documentation seems a bit more scarce than for ITensors (though I probably didn’t look hard enough), I was not sure what the relevant elements/functions for initialising an NDTensor are, I was even a bit puzzled since it seems that the SVD convention is different from the ITensor one (though I saw later a bug report in the archived NDtensor repo that perhaps explains it… ), anyway that got me a bit worried that maybe I was looking at something I wasn’t supposed to play with, so I wonder what’s the official take on this from the developers.
as always, thanks for developing itensors!