I use the expect() function to get the expect value of “Sz” operator in such state, then I will get trouble.
This is the most simply example to show this kind of problem. I also try to use other operator to act on a entangled state, I meet the same problem too.
Good question. So the problem here is actually not the expect function but really that you are adding two MPS with incompatible quantum numbers. It’s confusing in this case because the error isn’t happening until you call expect: ideally the error message would have already been printed from the line where you add the two states.
When you make your site indices with conserve_qns=trueit is saying that you want ITensor to conserve total S^z. However, the states you are trying to add have different total S^z, so that is not allowed.
Most likely what you’ll want to do is just to set conserve_qns=false since you are trying to mix states of different total S^z.