How to deal with entangled state of different quantum number?

Hi, I meet problem when I deal with entanglement state of different quantum number. For example, if I have 3 “S=1/2” sites in a state like this

|\downarrow\downarrow\downarrow\rang+|\uparrow\downarrow\downarrow\rang

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.

Definitely strange this error isn’t caught by the MPS addition code! We should add a check for that.

EDIT: I made an issue for this here: [ITensors] [BUG] Add check for flux when adding ITensors and MPS · Issue #908 · ITensor/ITensors.jl · GitHub