# How to create the MPO of the transverse-field Ising model Hamiltonian with AutoMPO?

+1 vote

Dear Itensor,

I'm trying to create the MPO of the transverse-field Ising model Hamiltonian with AutoMPO. The piece of the code that Itensor reports an error is

int N = 8;
auto sites = SpinHalf(N);
auto ampo = AutoMPO(sites);
for(int j = 1; j <=N; ++j)
{ ampo += 2, "Sx", j;}
auto H = toMPO(ampo);

The error message is
"Trying to set element:
Index: (dim=2|id=13|"n=1,Site,S=1/2")
1: 1 QN({"Sz",1})
2: 1 QN({"Sz",-1}), Val: 2
Index: (dim=2|id=13|"n=1,Site,S=1/2")'
1: 1 QN({"Sz",1})
2: 1 QN({"Sz",-1}), Val: 1
Element flux is: QN({"Sz",2})
ITensor flux is: QN({"Sz",-2})
From line 327, file ~/itensor3/itensor/itensor_impl.h
In .set, cannot set element with flux different from ITensor flux"

It seems that ITensor is complaining that the Hamiltonian Sx is not block-spare with respect to the Sz basis. Is there any way to circumvent this difficulty?

More generally, it seems that indices with quantum numbers are automatically used in the Site classes. Is there anyway to tell ITensor that these quantum numbers are not important?

Thanks very much,
Yantao

commented by (310 points)
P.S., I'm using ITensor3. (I worked with ITensor2 before, and there didn't seem to be a problem like this)

answered by (1.1k points)

According to this page in the ITensor documentation (https://itensor.org/docs.cgi?vers=cppv3&page=upgrade2to3), physics-specific site sets (e.g. SpinHalf) carry QNs by default. You can see this point in the "Recommended, Optional Changes" section.

So all you need to do is put {"ConserveQNs=",false} when creating the sites object. In your case, you can do auto sites = SpinHalf(N, {"ConserveQNs=",false});.

As a side remark, I am only truly familiar with the Julia version of the ITensor code, and there they still have QNs as false by default, even for physics-specific site sets. I actually don't know whether this change will eventually be made in the Julia version of the code too.

commented by (310 points)
This solves the problem! Wonderful. Thank you very much!
commented by (56.3k points)
Thanks for a great answer Sujay. Yes we changed the default in Julia; sorry if that’s confusing to C++ users such as yourself, NianGao. If in doubt, always provide the conserve_qns (Julia) or ConserveQNs (C++) keyword argument with the value you want.

Miles