Hi,Miles,
This is my correct Trotter gate code(follow tutorial and I want to calculate imaginary time evolution: <g.s|exp(H\tau)S^{z}exp(-H\tau)S^{z}|g.s>):
int main()
{
ofstream outfile;
outfile.open("cor_t.dat",ios::app);
int length[7]={12,16,24,32,48,64,80};
for(int &N : length)
{
auto sites = SpinHalf(N);
auto state = InitState(sites);
for(int i = 1; i <= N; ++i)
{
//Neel state
state.set(i,i%2==1 ? "Up" : "Dn");
}
auto psi0 = MPS(state);
auto psi = MPS(state);
Complex tstep=-Cplx_i*0.02;
Complex ttotal=-Cplx_i*N/4;
Real cutoff=1E-10;
auto gates = vector<Gate>();
auto gates0 = vector<Gate>();
auto ampo = AutoMPO(sites);
//Make the Heisenberg Hamiltonian
for(int b = 1; b < N; ++b)
{
ampo += 0.5,"S+",b,"S-",b+1;
ampo += 0.5,"S-",b,"S+",b+1;
ampo += "Sz",b,"Sz",b+1;
auto g = Gate(sites,b,b+1,Gate::tCReal,tstep/2,ampo);
gates.push_back(g);
auto g0 = Gate(sites,b,b+1,Gate::tCReal,-tstep/2,ampo);
gates0.push_back(g0);
}
for(int b = N-1; b >= 1; --b)
{
ampo += 0.5,"S+",b,"S-",b+1;
ampo += 0.5,"S-",b,"S+",b+1;
ampo += "Sz",b,"Sz",b+1;
auto g = Gate(sites,b,b+1,Gate::tReal,tstep/2,ampo);
gates.push_back(g);
auto g0 = Gate(sites,b,b+1,Gate::Real,-tstep/2,ampo);
gates0.push_back(g0);
}
auto H = MPO(ampo);
auto sweeps = Sweeps(30);
sweeps.maxm() = 100,200,800,800,1000;
sweeps.cutoff() = 1E-10;
sweeps.niter() = 2;
sweeps.noise() = 1E-7,1E-8,1E-9;
println(sweeps);
//
// Begin the DMRG calculation
//
auto energy = dmrg(psi,H,sweeps,"Quiet");
//
auto energy0= dmrg(psi0,H,sweeps,"Quiet");
auto Sz_1=sites.op("Sz",1);
// Time evolve
gateTEvol(gates,ttotal,tstep,psi,{"Cutoff=",cutoff,"Verbose=",true});
auto newpsi= Sz_1*psi.A(1);
newpsi.noprime();
psi.setA(1,newpsi);
// Right part exp(-H\tau)*S^{z}|g.s>
auto newpsi0 = Sz_1*psi0.A(1);
newpsi0.noprime();
psi0.setA(1,newpsi0);
gateTEvol(gates0,ttotal,tstep,psi0,{"Cutoff=",cutoff,"Verbose=",true});
//Print(psi0);
auto result=overlapC(psi,psi0).real();
//Print(result);
outfile <<N<<" "<<abs(result)<< endl;
}
outfile.close();
return 0;
}