Entanglement entropy of an MPS

Hey all!
I have some question about the function of ITensor.
It seems that no matter how many sites I plug into the function it just brings me back 1 (I normalized with ln(2)), so I tried to see what I will get for a 4 qubits maximally entangled state and I got 1 when the answer should be 4 (because I have 4 qubits). Maybe someone knows why I get this result all the time ?

Thanks for all the helpers!

1 Like

Your entanglement function code is very nice! One improvement that’s needed is to check if p > 0.0 before plugging it into the entropy formula, just because otherwise you can sometimes get a NaN result if p==0.0.

I believe there’s nothing wrong with the code you posted, and I tested it, so the problems must be these:

  • the state psi you are passing may not be the state you were intending to make (may not have the entanglement you expect, and/or might not be correctly normalized)
  • for 4 qubits which are maximally entangled, the largest entropy possible is 2 \log(2) not 4 \log(2). This is because such a state will consist of two entangled pairs of qubits.

Here is a code I wrote to test your function on two representative states psiA and psiB which are as described in the comments below:

using ITensors

function entanglement(psi, b)
  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
    if p > 0.0
      SVN = (SVN - p * log(p) )
    end
  end
  SVN= SVN/log(2)
  return SVN
end

let
  N = 4
  s = siteinds("S=1/2",N)

  # Bell pair betweeen (2,3), 1 and 4 in a product state
  A = ITensor(s...)
  A[1,1,1,1] = 1/√2
  A[1,2,2,1] = 1/√2
  psiA = MPS(A,s)
  @show norm(psiA)
  @show entanglement(psiA,2)


  # Two Bell pairs (2,3), (1,4)
  B = ITensor(s...)
  B[1,1,1,1] = 1/2
  B[2,1,1,2] = 1/2
  B[1,2,2,1] = 1/2
  B[2,2,2,2] = 1/2
  psiB = MPS(B,s)
  @show norm(psiB)
  @show entanglement(psiB,2)

  return
end

Hey, thanks!
It is working nicely now… but I have a few questions about this.
what is the difference between construct an MPS with your method between to construct it when you are starting with the wave function |0 0 0 0> and then apply CNOT and Hadamard gates on them ? if there is at all. Because a few weeks ago I tried to construct an MPS with the way you showed me exactly, but I didn’t got nice results at all

Glad it’s working.

The method I used is to fully specify all of the tensor elements. Whereas acting with gates only “implicitly” specifies them. But if the gates are defined correctly and applied correctly to produce the state you want then it will certainly work to use the gate approach.

When you say you did not get nice results at all using the gate method, most likely there was a bug in your code somewhere, or an incorrect definition of the gates.

If you have a question about why a specific gate approach didn’t work, please let me know the specific thing you were trying and we could discuss.

1 Like

Ok, but why is that, that when I am using
B[1,1,1,1]=1/sqrt(2)
B[2,1,1,2]=1/sqrt(2)
I will get that the entanglement is just 1 ? although it is a system of 4 qubits

It is because for that state, only qubits 1 and 4 are (maximally) entangled, while qubits 2 and 3 are not entangled with each other nor with any of the other qubits.

Yes, you are correct.
But if I will apply this function on this state I should get a maximally mixed because my function is a function that apply the a Pauli gates with interaction between sites

Sorry for the questions I am just trying to understand what I am missing with the ITensor because I am new to it

Sorry, but I don’t understand your question. Could you be more specific and explain the steps you are trying to do and their purpose?

So the indices i,j represents the site on the chain and alpha, beta the Pauli matrix and J is a random vector.
The hj term is supposed to represent an interaction between all sites on the chain, and in theory when I apply this state above it should get maximally entangled in 2-3 time steps.
But, there is an upper limit for the entanglement and it is 1, so it only entangled one pair and not 2 pairs

I think I see - you are saying that the purpose of the code is to apply random gates to a wavefunction of four sites?

If so then I agree that the entanglement should be higher than 1 (in units of log(2). It should be closer to 2 in those units. So if it is not, then it likely means there is a bug or a conceptual error in your code (maybe your gates are not acting on all sites? maybe the gates have a special structure that prevents them from fully entangling the wavefunction?).