0 votes
asked by (350 points)

Hello,

I'm attempting to read in a siteset and wavefunctions from a previous run, however I am running into some issues that I don't quite understand. From the documentation, I believe the code should look something like

int main()
{
    int N = 3;
    int dim = 10;

    auto sites = Exciton(N,{"on_site_dim", dim});
    readFromFile(format("sites_file_NB_%d",N),sites);
    auto psi = MPS(sites);
    readFromFile(format("psi_file_NB_%d",N),psi);

    auto ampo = AutoMPO(sites);

    ...

    auto H = toMPO(ampo);
}

where I define my Hamiltonian in the ellipses. However, the last line throws a segmentation fault. I have confirmed that if I don't try and read in a site file or wavefunction file, everything runs smoothly. Any ideas on what the problem might be? Thanks again for all of your help, Miles and Matt!

commented by (70.1k points)
Hi, I see. There's a strong chance this is causing problems. I would recommend redesigning op to analyze the tensor index (calling dim(s) on it) to figure out what dim is, not by using a global variable.

Also you could put a line Print(dim); inside the op function to check whether dim is being set to 22 or 21 or the correct value or not.
commented by (350 points)
This helped me better diagnose the problem, though I'm still not sure what the solution would be. The problem is that when I specify dim, typically dim=10, that creates an index with dimension 2*dim+1=21. Then, when that siteset is read back in, the code believes it's reading in an index with dim=21, and proceeds to try to access entries in s from 1 to 2*21+1.

So, long story short, my code might need some serious surgery in order to be able to use the read and write functions?
commented by (70.1k points)
Yes, that sounds like the problem. Why does the code think that when it's reading the indices back in, that it should interpret the dimension of the index as the number "n" that goes into the 2*n+1 formula? I don't think that's something ITensor is doing itself, but it likely a logical flaw in your code somewhere.

I think a much better design that would avoid this is to not have dim be defined in your ExcitonSite class itself. Rather, it just holds an index of some size, and knows how to extract the number you're calling dim from the size of this index (as  (dim(i)-1)/2 ). This would be used in the op function to set the for loop bounds, for example.

How does that sound?
commented by (350 points)
That solution works perfectly. As usual, thanks a million Miles.
commented by (70.1k points)
Glad to hear it!

1 Answer

0 votes
answered by (70.1k points)

Question is answered in above comments

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

...