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.