0 votes
asked by (650 points)

I save the wave function given by dmrg using "writeToFile("output/psitest", psi)". And then I try to read it by using "readFromFile" and calculate correlation function, the error comes out. The code that reads psitest from file is

// this file tests spinless Bose-Hubbard model
#include "itensor/all.h"
#include <typeinfo>
#include <iostream>
#include <fstream>
#include <vector>
#include <stdlib.h>
#include <cmath>
#include <cstring>
#include <sstream>

using namespace itensor;
using namespace std;

int main()
{
  auto N = 40;
  auto sites = BH(N);

  auto psi = readFromFile<IQMPS>("psi_test");

  auto pos_i = int(N/4);
  auto pos_f = 3*int(N/4);
  auto AL = sites.op("Nb", pos_i);
  auto AR = sites.op("Nb", pos_f);
  psi.position(pos_i);

  auto C = psi.A(pos_i);
  C *= AL;
  auto iR = commonIndex(psi.A(pos_i), psi.A(pos_i+1), Link);
  C *= dag(prime(prime(psi.A(pos_i), Site), iR));
  for (int i = pos_i+1; i < pos_f; i++){
    C *= psi.A(i);
    C *= dag(prime(psi.A(i), Link));
  }
  C *= psi.A(pos_f);
  C *= AR;
  auto iL = commonIndex(psi.A(pos_f-1), psi.A(pos_f), Link);
  C *= dag(prime(prime(psi.A(pos_f), Site), iL));

  cout << C.real() << endl;

}  

In fact, there is no error if I do not use "C.real()" and this i should be the origin of the problem. I also try to calculated the same correlation function just after the "dmrg" immediately, that is, I do not save the "psi" and read it later. No problem appears.

1 Answer

+2 votes
answered by (650 points)

I have solved this question. Here I present the correct version.

// this file tests spinless Bose-Hubbard model
#include "itensor/all.h"
#include <typeinfo>
#include <iostream>
#include <fstream>
#include <vector>
#include <stdlib.h>
#include <cmath>
#include <cstring>
#include <sstream>

using namespace itensor;
using namespace std;

int main()
{
  auto N = 40;
  BH sites;
  readFromFile("sites_test", sites);
  IQMPS psi(sites);
  readFromFile("psi_test", psi);

  // long-range correlation
  auto pos_i = int(N/4);
  auto pos_f = 3*int(N/4);
  auto AL = sites.op("Ab", pos_i);
  auto AR = sites.op("Adagb", pos_f);
  psi.position(pos_i);

  auto C = psi.A(pos_i);
  C *= AL;
  auto iR = commonIndex(psi.A(pos_i), psi.A(pos_i+1), Link);
  C *= dag(prime(prime(psi.A(pos_i), Site), iR));
  for (int i = pos_i+1; i < pos_f; i++){
    C *= psi.A(i);
    C *= dag(prime(psi.A(i), Link));
  }
  C *= psi.A(pos_f);
  C *= AR;
  auto iL = commonIndex(psi.A(pos_f-1), psi.A(pos_f), Link);
  C *= dag(prime(prime(psi.A(pos_f), Site), iL));

  cout << C.real() << endl;  

}  
commented by (280 points)
Could you explain further what the error was and how you fixed it? Was it because you changed operators or because of the way you read the files?
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.

Categories

...