+1 vote
asked by (130 points)


I am new to C language and iTensor.
I want to perform a DMRG calculation on the SSH model with Hamiltonian

$H=-\sum\i (1+\eta) c{A,i}^\dagger c{B,i} +(1-\eta) c{B,i}^\dagger c_{A,i+1} + h.c.$

I considered the A site as odd index site and B site as even index in a 1D chain. This is the code I used

#include "itensor/all.h"
using namespace itensor;
int main()
int N = 20;
Real eta = 0.5;

auto sites = Spinless(N);     
auto ampo = AutoMPO(sites);
for(int j = 1; j <= N; ++j)
        if (j%2 == 1)
            ampo += -(1+eta),"Cdag",j,"C",j+1;
            ampo += -(1+eta),"Cdag",j+1,"C",j;
        else (j%2 ==0)
            ampo += -(1-eta),"Cdag",j,"C",j+1;
            ampo += -(1-eta),"Cdag",j+1,"C",j;
auto H = MPO(ampo);
auto psi = MPS(sites);

auto sweeps = Sweeps(5);
sweeps.maxm() = 10,20,100,100,200;
sweeps.cutoff() = 1E-10;
sweeps.niter() = 2;
sweeps.noise() = 1E-7,1E-8,0.0;

auto energy = dmrg(psi,H,sweeps,"Quiet");

printfln("\nGround State Energy = %.10f",energy);

return 0;

However, the Hamiltonian seems haven't been created properly. The program terminated at a line saying "Using approx/svd conversion of AutoMPO->MPO"... May someone suggests what's wrong in my code?

Thanks in advance.

1 Answer

0 votes
answered by (70.1k points)

Hi, so if you get a 'hard' error like that (a crash) then probably something was out of bounds i.e. an integer value like j took on too big or too small a value. That's the most common reason for crashes in computer programs.

So looking at your code, the loop index "j" runs from 1 up to and including N. Then in your AutoMPO construction you are putting operators at j+1, which would be N+1, which is past the edge of your system.

Please try changing the loop stopping condition to j < N and see if you get sensible results after that.


Welcome to ITensor Support Q&A, where you can ask questions and receive answers from other members of the community.

Formatting Tips:
  • To format code, indent by four spaces
  • To format inline LaTeX, surround it by @@ on both sides
  • To format LaTeX on its own line, surround it by $$ above and below
  • For LaTeX, it may be necessary to backslash-escape underscore characters to obtain proper formatting. So for example writing \sum\_i to represent a sum over i.
If you cannot register due to firewall issues (e.g. you cannot see the capcha box) please email Miles Stoudenmire to ask for an account.

To report ITensor bugs, please use the issue tracker.