# Using Sx, Sy in SpinOne

edited

Hi all,

I'm new to Itensor so forgive me for asking this trivial question.. I'm currently working on a Heisenberg type Hamiltonian and I wish to calculate its ground state and local expectation value thereafter. (in Itensor V3)

FIrst, I'm having trouble with Sx Sx and Sy Sy terms in autoMPO.

auto sites = SpinOne(N)
auto ampo = AutoMPO(sites);
for (int i=1; i<N; ++i){
ampo += exc,"Sx",i,"Sx",i+1;
ampo += exc,"Sy",i,"Sy",i+1;
ampo += exc,"Sz",i,"Sz",i+1;
}
auto H = toMPO(ampo);


This lead to the runtime error: "In .set, cannot set element with flux different from ITensor flux".

Later I found this can be fixed by changing Sx, Sy to S+, S-:

ampo += 0.5*exc,"S+",i,"S-",i+1;
ampo += 0.5*exc,"S-",i,"S+",i+1;
ampo += exc,"Sz",i,"Sz",i+1;


which runs without error. I'm confused why this is happening, since I tried the former expression in Itensor v2 which worked out fine.

My second question is in the calculation of observables by the following code:

psi.position(j);
ITensor ket = psi.A(j);
ITensor bra = dag(prime(ket,"Site"));

// Sx must be converted to an ITensor prior to usage
ITensor Lxjop = sites.op("Sx",j);
ITensor Lyjop = sites.op("Sy",j);
ITensor Lzjop = sites.op("Sz",j);

// take an inner product
auto Lxj = (bra*Lxjop*ket).cplx();
auto Lyj = (bra*Lyjop*ket).cplx();
auto Lzj = (bra*Lzjop*ket).cplx();


This again gives the error: "In .set, cannot set element with flux different from ITensor flux". As I expected the problem is in the using of Sx and Sy, which, if commented out, will let the code run without error.

Can you plz help me understand what is the crux here, what is the "ITensor flux", or should I instead calculate expectation of Sx+iSy, which, however, looks pretty unatural.. Thank you!

pay attention to the codes:
auto sites = SpinOne(N);
if you use the above codes, it means {"ConserveQNs=",true}.
when you use Sx Sy in the Hamiltonian, Itensor can not work. Because Sx-Sx interaction does not have ConserveQNs algorithm.
You can change the codes like as
auto sites = SpinOne(N,{"ConserveQNs=",false});
but the speed of the program will be much lower.

commented by (250 points)
oh I see, thanks! :)
commented by (70k points)
Thank you for contributing a good answer JR