+1 vote
asked by (160 points)

Dear ITensor

I need to compare the ground state "psi" output of itensor "DMRG" code, with my ED ground state!!

let's assume a chain with N=3 SpinHlaf=1/2 with dim=8. I save my ED result for these 8 numbers in an ascii file. I am looking a way to save DMRG "psi" result in a ascii file as ED ones.

Many thanks for any help or suggestion.

1 Answer

0 votes
answered by (41.2k points)
selected by
 
Best answer

Hi, good question. Here's a sample code that can do this for you where I chose the case of four sites generated like auto sites = SpinHalf(4);. In the code below, psi is an MPS which could be from a DMRG calculation, say:

auto T = ITensor(1.0);
for(auto j : range1(N))
    {
    T *= psi(j);
    }
auto P = permute(T,sites(1),sites(2),sites(3),sites(4));
Print(P);

for(auto n1 : range1(sites(1)))
for(auto n2 : range1(sites(2)))
for(auto n3 : range1(sites(3)))
for(auto n4 : range1(sites(4)))
    {
    printfln("%d %d %d %d %.12f",n1,n2,n3,n4,P.elt(n1,n2,n3,n4));
    }

Does the above code do what you are looking for?

commented by (41.2k points)
If you want to skip the permute step, you can also just get the elements of T directly, like this:

    T.elt(sites(1)(n1),sites(2)(n2),sites(3)(n3),sites(4)(n4));

and use that above piece of code in the printing statement instead. It's slower, though, because each time it has to check what order T's indices are in, whereas the call to permute guarantees that P's indices are in a certain order.
commented by (160 points)
Dear Miles
It is very useful and works well. Many thanks!!!
But the way to access bigger system size (e.g N=24) is tedious!!, Is there any trick to circumvent nested "for" loops?
commented by (41.2k points)
Yes, good question. So we have a feature called "iterInds" which is an iteration helper for iterating over ITensor elements. Here's how you can use it within the code above:

    for(auto it : iterInds(P))
        {
        printfln("%.12f",P.elt(it));
        }

What your question is making me realize we also need is:
(1) a version of T.permute which takes a site set such as the "sites" object above, or similar
(2) a way of printing  the "it" object in the iterInds loop above
commented by (160 points)
It is not working!!  please see below:
====================

dmrg.cc:220:20: error: use of undeclared identifier 'iterInds'; did you mean 'siteInds'?
     for(auto it : iterInds(P))
                   ^~~~~~~~
                   siteInds
/Users/javadvahedi/itensor3/itensor/itensor/mps/mps.h:745:1: note: 'siteInds' declared here
siteInds(MPSType const& W, int b);
^
dmrg.cc:220:20: error: no matching function for call to 'siteInds'
     for(auto it : iterInds(P))
                   ^~~~~~~~
/Users/javadvahedi/itensor3/itensor/itensor/mps/mps.h:745:1: note: candidate function template not viable: requires 2 arguments, but 1 was
      provided
siteInds(MPSType const& W, int b);
^
2 errors generated.
make: *** [dmrg.o] Error 1
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

...