# How to compute the bipartite entanglement entropy with the first site as the subsystem us orthogonalize？？

**URL:** https://discourse.julialang.org/t/how-to-compute-the-bipartite-entanglement-entropy-with-the-first-site-as-the-subsystem-us-orthogonalize/107509
**Category:** Quantum
**Tags:** itensors
**Created:** [December 12, 2023, 3:42pm UTC](https://discourse.julialang.org/t/how-to-compute-the-bipartite-entanglement-entropy-with-the-first-site-as-the-subsystem-us-orthogonalize/107509 "2023-12-12T15:42:30Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![zipeilee](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zipeilee/32/205416_2.png) [@zipeilee](https://discourse.julialang.org/u/zipeilee)
#### Post date: [December 12, 2023, 3:42pm UTC](https://discourse.julialang.org/t/how-to-compute-the-bipartite-entanglement-entropy-with-the-first-site-as-the-subsystem-us-orthogonalize/107509/1 "2023-12-12T15:42:30Z")

</div>

I’m new to tensor networks. I understand that for an MPS state in the form of orthogonalization, the bipartite entanglement entropy of a subsystem is center site’s singular spectrum. I’ve found useful code on ITensors.jl 's example:

```Julia
orthogonalize!(psi, b)
U,S,V = svd(psi[b], (linkind(psi, b-1), siteind(psi,b)))
SvN = 0.0
for n=1:dim(S, 1)
  p = S[n,n]^2
  SvN -= p * log(p)
end

```

and have been using them without any issues still I needed to calculate the entropy for an open boundary condition MPS with the first site as the subsystem, there is no longer the ‘b-1’ index. How can I calculate the entropy for this system? Can I directly calculate singular spectrum for ‘psi[1]’? Additionally, is it possible to use the first lattice site as the center for orthogonalization?

---

<div class="post-metadata">

### Author: ![miles](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/miles/32/29112_2.png) [@miles](https://discourse.julialang.org/u/miles)
#### Post date: [December 12, 2023, 4:23pm UTC](https://discourse.julialang.org/t/how-to-compute-the-bipartite-entanglement-entropy-with-the-first-site-as-the-subsystem-us-orthogonalize/107509/2 "2023-12-12T16:23:15Z")

</div>

That’s the right code to be using. What it will do is compute the entanglement across the b’th bond, so between the sites (1,2,…,b) and (b+1,b+2, …, N).

But I see the issue you mean for the case of b=1, because the function `linkind(psi,b-1)` will fail in that case. So you will need to fix or generalize that part for that case. A fix could be:

```julia
if b==1
  U,S,V = svd(psi[b], (siteind(psi,b),))
else
  U,S,V = svd(psi[b], (linkind(psi, b-1), siteind(psi,b)))
end

```

and the rest of the code otherwise. Please give that a try and let us know if it doesn’t work for the b=1 case.

---

<div class="post-metadata">

### Author: ![miles](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/miles/32/29112_2.png) [@miles](https://discourse.julialang.org/u/miles)
#### Post date: [December 12, 2023, 4:49pm UTC](https://discourse.julialang.org/t/how-to-compute-the-bipartite-entanglement-entropy-with-the-first-site-as-the-subsystem-us-orthogonalize/107509/3 "2023-12-12T16:49:48Z")

</div>

Also there is a more specialized user support & discussion forum about ITensor here if you’d like to ask us questions there:  
[https://itensor.discourse.group](https://itensor.discourse.group)

---

<div class="post-metadata">

### Author: ![zipeilee](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zipeilee/32/205416_2.png) [@zipeilee](https://discourse.julialang.org/u/zipeilee)
#### Post date: [December 13, 2023, 3:17am UTC](https://discourse.julialang.org/t/how-to-compute-the-bipartite-entanglement-entropy-with-the-first-site-as-the-subsystem-us-orthogonalize/107509/4 "2023-12-13T03:17:54Z")

</div>

> [@miles](#):
>
> ```julia
> if b==1
> U,S,V = svd(psi[b], (siteind(psi,b),))
> else
> U,S,V = svd(psi[b], (linkind(psi, b-1), siteind(psi,b)))
> end
> 
> ```

Thanks, it worked.
