+1 vote
asked by (420 points)

Dear Itensor

I am interested to check spin-1 thermodynamic behavior. Could any one know, how should I change the following sample code (taken from finiteT folder of Itensor's tutorial):

//
// Make initial 'wavefunction' which is a product
// of perfect singlets between neighboring sites
//
auto psi = MPS(sites);
for(int n = 1; n <= 2*N; n += 2)
{
auto s1 = sites(n);
auto s2 = sites(n+1);
auto wf = ITensor(s1,s2);
wf.set(s1(1),s2(2), ISqrt2);
wf.set(s1(2),s2(1), -ISqrt2);
ITensor D;
psi.ref(n) = ITensor(s1);
psi.ref(n+1) = ITensor(s2);
svd(wf,psi.ref(n),D,psi.ref(n+1));
psi.ref(n) *= D;

}

the above segmentation code works well for spin-1/2. But, seems it should be changed for spin-1, if so, any comments would be appreciated.

Regards
Javad

1 Answer

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

Hi Javad,
Good question. The part you would need to change are the lines of the form wf.set(…); These are the lines which initialize the tensor wf to be a “Bell pair” or some kind of perfectly entangled state between sites s1 and s2. For the case of a code that is not trying to conserve quantum numbers, it doesn’t matter which maximally entangled state you choose here, as the ‘ancilla’ sites get traced out anyway, so all you need to do is to work out some kind of maximally entangled state for a pair of S=1 spins on paper, then define the non-zero components of wf to put it into that state.

In the above code, the non-zero components are the |1>|2> and |2>|1> components, with amplitudes 1/sqrt(2) and -1/sqrt(2) respectively, making a S=1/2 singlet state. So you would need to adjust and generalize that code for a maximally entangled state of a pair of S=1 spins.

Best,
Miles

commented by (420 points)
Dear Miles

I only  changed these two lines

wf.set(s1(1),s2(2), ISqrt2);
        wf.set(s1(2),s2(1), -ISqrt2);

into the following lines :

// spin-1  maximally entagled state  ==> 1/sqrt(3)*(|11>-|00>+|-1,-1>)

wf.set(s1(1),s2(1),  1.0/sqrt(3.0));
wf.set(s1(2),s2(2), -1.0/sqrt(3.0));
 wf.set(s1(3),s2(3),  1.0/sqrt(3.0));

but unfortunately,  I am getting

"Segmentation fault (core dumped)"

on my Ubuntu os.

Regards
Javad
commented by (550 points)
#include "itensor/all.h"
#include "itensor/util/print_macro.h"
using namespace itensor;

int main()
    {
    int N =10;
    auto sites = SpinOne(N,{"ConserveQNs=",false}); //make a chain of N spin 1's

    auto psi = MPS(sites);
for(int n = 1; n <= N-1; n += 2)   
{
auto s1 = sites(n);
auto s2 = sites(n+1);
auto wf = ITensor(s1,s2);
wf.set(s1(1),s2(1),  1.0/sqrt(3.0));
wf.set(s1(2),s2(2), -1.0/sqrt(3.0));
 wf.set(s1(3),s2(3),  1.0/sqrt(3.0));
ITensor D;
psi.ref(n) = ITensor(s1);
psi.ref(n+1) = ITensor(s2);
svd(wf,psi.ref(n),D,psi.ref(n+1));
psi.ref(n) *= D;
}
Print(psi);
return 0;
    }

 I test the code,  which might be what you want!
commented by (70.1k points)
The code does look reasonable at a glance. Have you compiled your code in debug mode and run it that way? What line is the error coming from?

Thanks,
Miles
commented by (550 points)
edited by
My codes  was complied and  performed in my PC.  He/She only showed part of the program.  So I do not know  where  the error is.     I guess  the loop  "for(int n = 1; n <= 2*N; n += 2)"  and  system size "auto sites = SpinOne(N,{"ConserveQNs=",false});"  conflict each other.  Moreover   the loop  "for(int n = 1; n <= 2*N; n += 2)"   also confict with  ”auto s2 = sites(n+1);“ when n=2*N!

Best wishes!
JR
commented by (70.1k points)
Yes, it does look like those loops are written incorrectly and will go out of bounds. Please try adjusting the loop definitions and let me know if you are still having trouble.
commented by (420 points)
Dear Milles

I found the problem.

Indeed, to implement the "soft-edge" trick.
I use the following  flages:

SpinOne(2*N,{"SHalfEdge=",true,"ConserveQNs=",false});

although at compiling stage, I haven't had any errors, when the code is running, I noticed
the code pointing to

===>
~/itensor/mps/sites/spinhalf.h
insted of
~/itensor/mps/sites/spinone.h

so to acces ==> wf.set(s1(3),s2(3),  1.0/sqrt(3.0));
yields  "Segmentation fault (core dumped)"


then I removed flage ==> "SHalfEdge"
SpinOne(2*N,{"ConserveQNs=",false});

my code runs without a problem.  

But I need to soften the edges of the chain to mimic the infinite chain to be able to see the Haldane gap. Otherwise "susceptibility" diverges at low temperatures.  

Are there any tricks to solve this issue?

Regards
commented by (70.1k points)
Hi, I would say I am still not clear on what the issue is. Can you please compile your code in "debug mode" and then run it to get a better error message and/or run it in a debugger to see what line the code has reached before the error occurs?

How to compile code in "debug mode" when using the Makefiles provided with ITensor:
http://itensor.org/docs.cgi?vers=cppv3&page=formulas/debug_mode
commented by (70.1k points)
For example, when I modified the ancilla.cc code inside of the ITensor source code, under the tutorial/finiteT folder to use SpinOne(2*N,{"ConserveQNs=",false,"SHalfEdge",true});, it ran without any errors.

Did you check whether your for loop bounds were correct? They look incorrect to me, like they would go past the value of 2*N.
commented by (420 points)
I just tested the code on my mac, and it works without any problems!!!!

That is weird why on my pc (OS: Ubuntu), I am getting such a issu.
commented by (70.1k points)
Glad it works. I think at this point it's really a question about debugging C++ code and how to do that, versus ITensor itself. So if the issue recurs, please use a debugger to pinpoint which line of code the issue is coming from and that would help you to fix it. If the issue persists and  you do think it's a bug in ITensor, please share a minimal working example that reproduces the bug. Thanks!
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

...