+3 votes
asked by (210 points)

Hello,
how we can calculate the entanglement entropy of an half chain with Julia?
I am trying to adapt the following lines of code which are given for C++

Thanks a lot!
Jacopo

auto b = 10;

//"Gauge" the MPS to site b
psi.position(b);

//SVD this wavefunction to get the spectrum
//of density-matrix eigenvalues
auto l = leftLinkIndex(psi,b);
auto s = siteIndex(psi,b);
auto [U,S,V] = svd(psi(b),{l,s});
auto u = commonIndex(U,S);

//Apply von Neumann formula
//to the squares of the singular values
Real SvN = 0.;
for(auto n : range1(dim(u)))
{
auto Sn = elt(S,n,n);
auto p = sqr(Sn);
if(p > 1E-12) SvN += -p*log(p);
}

1 Answer

+3 votes
answered by (14.1k points)
selected by
 
Best answer

Hi Jacopo,

Here's a code for computing the von Neumann entropy in Julia:

using ITensors

function entropy_von_neumann(psi::MPS, b::Int)
  s = siteinds(psi)  
  orthogonalize!(psi, b)
  _,S = svd(psi[b], (linkind(psi, b-1), s[b]))
  SvN = 0.0
  for n in 1:dim(S, 1)
    p = S[n,n]^2
    SvN -= p * log(p)
  end
  return SvN
end

N = 10
s = siteinds("S=1/2", N)
psi = randomMPS(s, 4)
SvN = entropy_von_neumann(psi, b)

Hopefully we will find time to create code formulas for common operations like this in Julia.

Cheers,
Matt

commented by (210 points)
thanks a lot!
Welcome to ITensor Support Q&A, where you can ask questions and receive answers from other members of the community.

Formatting Tips:
  • To format code, indent by four spaces
  • To format inline LaTeX, surround it by @@ on both sides
  • To format LaTeX on its own line, surround it by $$ above and below
  • For LaTeX, it may be necessary to backslash-escape underscore characters to obtain proper formatting. So for example writing \sum\_i to represent a sum over i.
If you cannot register due to firewall issues (e.g. you cannot see the capcha box) please email Miles Stoudenmire to ask for an account.

To report ITensor bugs, please use the issue tracker.

Categories

...