Try changing the line:
_,S = svd(psi[b], (linkind(psi, b-1), s[b]))
to:
_,S = svd(psi[b], (linkinds(psi, b-1)..., s[b]))
Basically what is happening is that for b == 1
, you are trying to grab linkind(psi, 0)
, which doesn’t exist so it returns nothing
. linkinds(psi, b-1)
outputs a collection of link indices, so is either an empty collection ([]
) if b == 1
or a collection of length one containing the link index ([linkind(psi, b - 1)]
) if b > 1
(assuming there is only one link index, there could in principle be more than one link index though that is not standard and you would have to construct that yourself). Changing that line to (linkinds(psi, b-1)..., s[b])
means that if b == 1
it makes a collection of indices just containing the site index, (s[b],)
, while if b > 1
it makes the collection equal to (linkind(psi, b-1), s[b])
. For example:
julia> using ITensors
julia> s = siteinds("S=1/2", 4);
julia> psi = MPS(s, n -> isodd(n) ? "Up" : "Dn");
julia> linkind(psi, 0)
julia> (linkind(psi, 0), s[1])
(nothing, (dim=2|id=100|"S=1/2,Site,n=1"))
julia> (linkinds(psi, 0)..., s[1])
((dim=2|id=100|"S=1/2,Site,n=1"),)
julia> linkind(psi, 1)
(dim=1|id=471|"Link,l=1")
julia> (linkind(psi, 1), s[2])
((dim=1|id=471|"Link,l=1"), (dim=2|id=541|"S=1/2,Site,n=2"))
julia> (linkinds(psi, 1)..., s[2])
((dim=1|id=471|"Link,l=1"), (dim=2|id=541|"S=1/2,Site,n=2"))
The svd
code doesn’t understand when you input the indices (nothing, (dim=2|id=100|"S=1/2,Site,n=1"))
in the b == 1
case so it is throwing that opaque error.
I see this issue is coming up a lot (Entanglement Entropy Bug, About measuring entropy, etc.). I think everyone is copying the code from the docs here: MPS and MPO Examples · ITensors.jl which should be updated to the way I suggested. I’ll update that now.