Hi Arnab, good question. So in the current version of ITensor you aren't allowed to set an element of an ITensor to a complex value if that ITensor was constructed having real storage internally. (We are thinking of lifting this restriction in the future.)
For now, you can fix this two ways:
1) in the first line of your op! function, you can put the line complex!(Op) which will switch the storage data in Op to be complex-valued, then you can successfully set your elements
2) you can use the other style of op function, which is op without the exclamation "!" mark. This version lets you construct the Op tensor any way you want and then you return it from that function. So like this:
Op = ITensor(ComplexF64,s',dag(s))
Op[s'=>1,s=>1] = cos(beta)-sin(beta)*im
Op[s'=>2,s=>2] = cos(beta)+sin(beta)*im
As you can see in that version, when I constructed Op I made its element type ComplexF64 from the beginning. So that version (2) is a bit faster than (1) which makes the elements to be real zeros then has to remake them to be complex zeros.