The full code is attached if necessary (without additional term @@\sum S^z\_i@@)
#include "itensor/all.h"
using namespace itensor;
using std::vector;
int main()
{
int N = 10; //number of sites
Real tstep = 0.1; //time step (smaller is generally more accurate)
Real ttotal = 1.0; //total time to evolve
Real cutoff = 1E-5; //truncation error cutoff when restoring MPS form
//Define a site set object "sites" which lets us
//easily obtain Site indices defining our Hilbert space
//and S=1/2 single-site operators
auto sites = SpinHalf(N);
auto state = InitState(sites,"Dn");//initial state
auto psi = MPS(state);
//Define the type "Gate" as a shorthand for BondGate<ITensor>
using Gate = BondGate<ITensor>;
//Create a std::vector (dynamically sizeable array)
//to hold the Trotter gates
auto gates = vector<Gate>();
//Create the gates exp(-i*tstep/2*hterm)
//and add them to gates
for(int b = 1; b <= N-1; ++b)
{
ITensor Sxb = sites.op("Sx",b); //Sx must be converted to an ITensor prior to usage
ITensor Sxb1 = sites.op("Sx",b+1);
auto hterm = Sxb*Sxb1;
hterm +=0.5*sites.op("Sz",b)+0.5*sites.op("Sz",b+1);
auto g = Gate(sites,b,b+1,Gate::tReal,tstep/2.,hterm);
gates.push_back(g);
}
//Create the gates exp(-i*tstep/2*hterm) in reverse
//order (to get a second order Trotter breakup which
//does a time step of "tstep") and add them to gates
for(int b = N-1; b >= 1; --b)
{
ITensor Sxb = sites.op("Sx",b);
ITensor Sxb1 = sites.op("Sx",b+1);
auto hterm = Sxb*Sxb1;
hterm +=0.5*sites.op("Sz",b)+0.5*sites.op("Sz",b+1);
auto g = Gate(sites,b,b+1,Gate::tReal,tstep/2.,hterm);
gates.push_back(g);
}
//Time evolve, overwriting psi when done
gateTEvol(gates,ttotal,tstep,psi,{"Cutoff=",cutoff,"Verbose=",true});
printfln("Maximum MPS bond dimension after time evolution is %d",maxM(psi));
//define an operator to find expactation value
auto ampo = AutoMPO(sites);
for(int j = 1; j <= N; ++j)
{
ampo += "Sz",j;
}
auto H1 = MPO(ampo);
//Print <psi_t|H1|psi_t>
//(Will be complex so using overlapC which can return complex);
Print(overlapC(psi,H1,psi).real());
return 0;
}