# entanglement entropy in tdvp calculation

**URL:** <https://itensor.discourse.group/t/entanglement-entropy-in-tdvp-calculation/1594>\
**Category:** ITensor Julia Questions\
**Tags:** julia, entanglement\
**Created:** [March 28, 2024, 9:26am UTC](https://itensor.discourse.group/t/entanglement-entropy-in-tdvp-calculation/1594 "2024-03-28T09:26:32Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![mtfishman](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/mtfishman/32/11_2.png) [@mtfishman](https://itensor.discourse.group/u/mtfishman)\
**Post date:** [March 28, 2024, 1:18pm UTC](https://itensor.discourse.group/t/entanglement-entropy-in-tdvp-calculation/1594/2 "2024-03-28T13:18:05Z")

</div>

Try changing the line:

```julia
      _,S = svd(psi[b], (linkind(psi, b-1), s[b]))

```

to:

```julia
      _,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
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](https://itensor.discourse.group/t/entanglement-entropy-bug/1296), [About measuring entropy](https://itensor.discourse.group/t/about-measuring-entropy/1323), etc.). I think everyone is copying the code from the docs here: [MPS and MPO Examples · ITensors.jl](https://itensor.github.io/ITensors.jl/stable/examples/MPSandMPO.html#Computing-the-Entanglement-Entropy-of-an-MPS) which should be updated to the way I suggested. I’ll update that now.

---

_[View the full topic](https://itensor.discourse.group/t/entanglement-entropy-in-tdvp-calculation/1594)._
