예제 #1
0
파일: views.py 프로젝트: GiggleLiu/apps
def test_overlap(dmu_mag=0.01,target_block=(0,0),**kwargs):
    '''
    Show the fractional charge wave functions.
    '''
    model,expander=get_solving_system(evolutor_type='masked',periodic=False,**kwargs)
    filename='data/frac_W1%s_W2%s_U%s_N%s'%(kwargs.get('K1'),kwargs.get('K2'),kwargs.get('U'),kwargs.get('nsite'))
    filename_ket1='data/mps_W1%s_W2%s_U%s_N%s_dmu%s_%s.dat'%(kwargs.get('K1'),kwargs.get('K2'),kwargs.get('U'),kwargs.get('nsite'),dmu_mag,target_block)
    filename_ket2='data/mps_W1%s_W2%s_U%s_N%s_dmu%s_%s.dat'%(kwargs.get('K1'),kwargs.get('K2'),kwargs.get('U'),kwargs.get('nsite'),-dmu_mag,target_block)
    ket1=MPS.load(filename_ket1)
    ket2=MPS.load(filename_ket2)
    print ket1.tobra(labels=ket1.labels)*ket2
    pdb.set_trace()
예제 #2
0
파일: views.py 프로젝트: GiggleLiu/apps
 def get1(target_blocki,parityi):
     suffix='%s_%s%s'%(suf,target_blocki,parityi)
     filename_mps='data/mps_%s.dat'%suffix
     filename_eng='data/eng_%s.dat'%suffix
     mps=MPS.load(filename_mps)
     eng=loadtxt(filename_eng)
     return eng,mps
예제 #3
0
파일: views.py 프로젝트: GiggleLiu/apps
def measure_mjsx(K1,K2,U,nsite,dmu=0.01,usempi=True,append=False):
    suffix='W1%s_W2%s_U%s_N%s_dmu%s.dat'%(K1,K2,U,nsite,dmu)
    mlfile='data/mjsx_%s.npy'%suffix
    siteindices=arange(nsite)
    if not append:
        blocks=[(0,0),(0,1)]
        spaceconfig=SuperSpaceConfig(chorder([2,1,1]))
        kets=[]
        for target_block in blocks:
            suffix='W1%s_W2%s_U%s_N%s_dmu%s_%s.dat'%(K1,K2,U,nsite,dmu,target_block)
            filename='data/mps_'+suffix
            ket=MPS.load(filename)
            kets.append(ket)
        kets=[1./sqrt(2.)*(kets[0]+kets[1]),1./sqrt(2.)*(kets[0]-kets[1])]
        ml=[]
        for ket in kets:
            ket.compress()
            ml.append(measure_order(which='Sx',ket=ket,usempi=usempi,nsite=nsite))
        ml=array(ml)
        save(mlfile,ml)
    else:
        ml=load(mlfile)
    ion()
    plot(siteindices,ml.T.real)
    pdb.set_trace()
예제 #4
0
파일: views.py 프로젝트: GiggleLiu/apps
 def get1(polarityi):
     suffix='%s_%s'%(suf,polarityi)
     filename_mps='data/mps_%s.dat'%suffix
     filename_eng='data/eng_%s.dat'%suffix
     mps=MPS.load(filename_mps)
     eng=loadtxt(filename_eng)
     if polarityi==(1,0) and fixtail:
         mps=fix_tail(mps,spaceconfig=spaceconfig1,parity=-1)
     return eng,mps
예제 #5
0
파일: views.py 프로젝트: GiggleLiu/apps
 def get1(dmui,target_blocki):
     suffix='W1%s_W2%s_U%s_N%s_dmu%s_%s.dat'%(K1,K2,U,nsite,dmui,target_blocki)
     filename_mps='data/mps_'+suffix
     filename_eng='data/eng_'+suffix
     mps=MPS.load(filename_mps)
     if target_blocki in tblocks and dmui in dmus and fixtail:
         mps=fix_tail(mps,spaceconfig,0)
     eng=loadtxt(filename_eng)
     return eng,mps
예제 #6
0
파일: views.py 프로젝트: GiggleLiu/apps
 def get1(target_blocki):
     suffix=suf+'_%s'%target_blocki
     filename_mps='data/mps_%s.dat'%suffix
     filename_eng='data/eng_%s.dat'%suffix
     mps=MPS.load(filename_mps)
     eng=loadtxt(filename_eng)
     if target_blocki==1 and fixtail:
         mps=fix_tail(mps,spaceconfig=spaceconfig1,parity=-1)
     return eng,mps
예제 #7
0
파일: views.py 프로젝트: GiggleLiu/apps
def mf_wave(method,append=False,dmu=0.01,**kwargs):
    '''
    Get the majorana wave functions.
    '''
    even_block=(0,0)
    odd_block=(0,1)
    blocks=[even_block,odd_block]
    filenames=['data/mps_W1%s_W2%s_U%s_N%s_dmu%s_%s.dat'%(kwargs.get('K1'),kwargs.get('K2'),kwargs.get('U'),kwargs.get('nsite'),dmu,blocks[0]),
        'data/mps_W1%s_W2%s_U%s_N%s_dmu%s_%s.dat'%(kwargs.get('K1'),kwargs.get('K2'),kwargs.get('U'),kwargs.get('nsite'),dmu,blocks[1])]
    mjfile='data/mf_W1%s_W2%s_U%s_N%s_dmu%s.npy'%(kwargs.get('K1'),kwargs.get('K2'),kwargs.get('U'),kwargs.get('nsite'),dmu)
    #filenames2=['data/mps_W1%s_W2%s_U%s_N%s_dmu%s_%s.dat'%(kwargs.get('K1'),kwargs.get('K2'),kwargs.get('U'),kwargs.get('nsite'),-dmu,blocks[0]),
        #'data/mps_W1%s_W2%s_U%s_N%s_dmu%s_%s.dat'%(kwargs.get('K1'),kwargs.get('K2'),kwargs.get('U'),kwargs.get('nsite'),-dmu,blocks[1])]
    if method=='dmrg':
        kets=[]
        model,expander=get_solving_system(evolutor_type='masked',perturb={'mu':(0,dmu)},periodic=False,**kwargs)
        if not append:
            for target_block,filename in zip(blocks,filenames):
                EG,ket=solve_dmrg(model,expander,target_block=odd_block,nlevel=1)
                ket.save(filename)
                kets.append(ket)
            ket_even,ket_odd=kets
        else:
            ket_even=MPS.load(filenames[0])
            ket_odd=MPS.load(filenames[1])
            #ket_even=MPS.load(filenames[0])+MPS.load(filenames2[0])
            #ket_odd=MPS.load(filenames[1])+MPS.load(filenames2[1])
            #ket_even.compress()
            #ket_odd.compress()
    elif method=='direct':
        model,expander=get_solving_system(evolutor_type='full',periodic=False,**kwargs)
        EGs,EVs=solve_direct(model,k=2)
        EG_even,ket_even=EGs[1],state2MPS(EVs[:,1],sitedim=expander.spaceconfig.hndim,l=0)
        EG_odd,ket_odd=EGs[0],state2MPS(EVs[:,0],sitedim=expander.spaceconfig.hndim,l=0)

    pls=smajorana4mps(spaceconfig=expander.spaceconfig,ket_even=ket_even,ket_odd=ket_odd,theta=0)
    if RANK==0:
        pls=array(pls)
        #pls=majorana4vec(spaceconfig=model.hgen.spaceconfig,ket_even=ket_even.state,ket_odd=ket_odd.state)
        #pls=dos4mps(spaceconfig=expander.spaceconfig,ket=ket_even)
        #pls=dos4vec(spaceconfig=model.hgen.spaceconfig,ket=EVs[:,0])
        save(mjfile,pls)
        return pls
예제 #8
0
파일: views.py 프로젝트: GiggleLiu/apps
def solve1(K1,K2,U,dmu,target_block,nsite,override,C2parity):
    '''Get and store the eigen vectors and eigen values for ground state.'''
    suffix='W1%s_W2%s_U%s_N%s_dmu%s_%s.dat'%(K1,K2,U,nsite,dmu,target_block)
    filename_mps='data/mps_'+suffix
    filename_eng='data/eng_'+suffix
    if not override and os.path.isfile(filename_mps):
        Ei=loadtxt(filename_eng)[0]
        return Ei,MPS.load(filename_mps)
    model,expander=get_solving_system(evolutor_type='masked',periodic=False,K1=K1,K2=K2,U=U,nsite=nsite)
    Ei,mpsi=solve_dmrg(model,expander,target_block=target_block,nlevel=1,call_before=lambda egn:chmu(egn,dmu),C2parity=C2parity)
    print 'FIN - CORE:%s'%RANK
    mpsi.save(filename_mps)
    savetxt(filename_eng,[Ei])
    return Ei,mpsi
예제 #9
0
def _get_mps(hgen_l, hgen_r, phi, direction, labels):
    '''Combining hgen_l and hgen_r to get the matrix product state.'''
    NL, NR = hgen_l.N, hgen_r.N
    phi = tensor.Tensor(phi, labels=['al', 'sl+1', 'al+2', 'sl+2'])  #l=NL-1
    if direction == '->':
        A = hgen_l.evolutor.A(NL - 1, dense=True)  #get A[sNL](NL-1,NL)
        A = tensor.Tensor(A, labels=['sl+1', 'al', 'al+1\''])
        phi = tensor.contract([A, phi])
        phi = phi.chorder([0, 2, 1])  #now we get phi(al+1,sl+2,al+2)
        #decouple phi into S*B, B is column-wise othorgonal
        U, S, V = svd(phi.reshape([phi.shape[0], -1]), full_matrices=False)
        U = tensor.Tensor(U, labels=['al+1\'', 'al+1'])
        A = (A * U)  #get A(al,sl+1,al+1)
        B = transpose(
            V.reshape([S.shape[0], phi.shape[1], phi.shape[2]]),
            axes=(1, 2, 0)
        )  #al+1,sl+2,al+2 -> sl+2,al+2,al+1, stored in column wise othorgonal format
    else:
        B = hgen_r.evolutor.A(NR - 1, dense=True)  #get B[sNR](NL+1,NL+2)
        B = tensor.Tensor(B, labels=['sl+2', 'al+2',
                                     'al+1\'']).conj()  #!the conjugate?
        phi = tensor.contract([phi, B])
        #decouple phi into A*S, A is row-wise othorgonal
        U, S, V = svd(phi.reshape([phi.shape[0] * phi.shape[1], -1]),
                      full_matrices=False)
        V = tensor.Tensor(V, labels=['al+1', 'al+1\''])
        B = (V * B).chorder([1, 2, 0]).conj(
        )  #al+1,sl+2,al+2 -> sl+2,al+2,al+1, for B is in transposed order by default.
        A = transpose(
            U.reshape([phi.shape[0], phi.shape[1], S.shape[0]]),
            axes=(1, 0, 2)
        )  #al,sl+1,al+1 -> sl+1,al,al+1, stored in column wise othorgonal format

    AL = hgen_l.evolutor.get_AL(dense=True)[:-1] + [A]
    BL = [B] + hgen_r.evolutor.get_AL(dense=True)[::-1][1:]

    AL = [transpose(ai, axes=(1, 0, 2)) for ai in AL]
    BL = [transpose(bi, axes=(1, 0, 2)).conj() for bi in BL]  #transpose
    mps = MPS(AL=AL,
              BL=BL,
              S=S,
              labels=labels,
              forder=range(NL) + range(NL, NL + NR)[::-1])
    return mps
예제 #10
0
파일: views.py 프로젝트: GiggleLiu/apps
def heisenberg_vmps(J,Jz,h,nsite,append=False):
    '''
    Run vMPS for Heisenberg model.
    '''
    filename='mps_heisenberg_%s.dat'%(nsite)
    model=HeisenbergModel(J=J,Jz=Jz,h=h,nsite=nsite)
    if append:
        mps=MPS.load(filename)
    else:
        #run dmrg to get the initial guess.
        hgen=RGHGen(spaceconfig=model.spaceconfig,H=model.H_serial,evolutor_type='masked')
        dmrgegn=DMRGEngine(hgen=hgen,tol=0)
        EG=dmrgegn.run_finite(endpoint=(1,'<-',0),maxN=10,tol=0)[-1]
        #hgen=dmrgegn.query('r',nsite-1)
        mps=dmrgegn.get_mps(direction='<-')  #right normalized initial state
        mps.save(filename)

    #run vmps
    vegn=VMPSEngine(H=model.H,k0=mps)
    vegn.run()
예제 #11
0
파일: views.py 프로젝트: GiggleLiu/apps
def spin1_vmps(J, Jz, h, nsite, append=False):
    """
    Run vMPS for Heisenberg model.
    """
    filename = "mps_heisenberg_%s.dat" % (nsite)
    model = Spin1Model(J=J, Jz=Jz, h=h, nsite=nsite)
    if append:
        mps = MPS.load(filename)
    else:
        # run dmrg to get the initial guess.
        hgen = RGHGen(spaceconfig=SpinSpaceConfig([2, 1]), H=model.H_serial, evolutor_type="masked")
        dmrgegn = DMRGEngine(hgen=hgen, tol=0)
        EG = dmrgegn.run_finite(endpoint=(1, "<-", 0), maxN=10, tol=0)[-1]
        # hgen=dmrgegn.query('r',nsite-1)
        mps = dmrgegn.get_mps(direction="<-")  # right normalized initial state
        mps.save(filename)

    # run vmps
    vegn = VMPSEngine(H=model.H, k0=mps)
    vegn.run()
예제 #12
0
파일: views.py 프로젝트: GiggleLiu/apps
def solve1(delta,target_block,nsite,override=True,C2parity=None,t=1.,mu=0.):
    '''Get and store the eigen vectors and eigen values for ground state.'''
    model=SSHModel(delta=delta,t=t,mu=mu,nsite=nsite,manybody=True)
    suffix='%s_%s.dat'%(model.get_str(),target_block)
    filename_mps='data/mps3_'+suffix
    filename_eng='data/eng3_'+suffix
    if not override and os.path.isfile(filename_mps):
        Ei=loadtxt(filename_eng)[0]
        return Ei,MPS.load(filename_mps)

    spaceconfig=SuperSpaceConfig(chorder([model.hgen.spaceconfig.nspin,1,model.hgen.spaceconfig.norbit]))
    H_serial=op2collection(op=model.hgen.get_opH())
    expander=RGHGen(spaceconfig=spaceconfig,H=H_serial,evolutor_type='masked')

    t0=time.time()
    dmrgegn=DMRGEngine(hgen=expander,tol=1e-7,reflect=False,eigen_solver='JD')   #we can not use reflect here, because SOC do not meet reflection condition!
    dmrgegn.use_U1_symmetry('PM',target_block=target_block)
    Emin,mps=dmrgegn.run_finite(endpoint=(5,'<-',0),maxN=[10,25,50,70,70,70,70],tol=1e-8)
    t1=time.time()
    print 'The Ground State Energy for %s: %s, Elapse %s.'%(model,Emin,t1-t0)
    print 'FIN - CORE:%s'%RANK
    mps.save(filename_mps)
    savetxt(filename_eng,Emin)
    return Emin,mps
예제 #13
0
파일: views.py 프로젝트: GiggleLiu/apps
def solve1(J,target_block,nsite,override=True,C2parity=None,h=0.):
    '''Get and store the eigen vectors and eigen values for ground state.'''
    model=IsingModel(J=J,h=h,nsite=nsite)
    suffix='%s_%s.dat'%(model.get_str(),target_block)
    filename_mps='data/mps_'+suffix
    filename_eng='data/eng_'+suffix
    if not override and os.path.isfile(filename_mps):
        Ei=loadtxt(filename_eng)[0]
        return Ei,MPS.load(filename_mps)

    spaceconfig=SpinSpaceConfig([2,1])
    H_serial=model.H_serial
    expander=RGHGen(spaceconfig=spaceconfig,H=H_serial,evolutor_type='masked')

    t0=time.time()
    dmrgegn=DMRGEngine(hgen=expander,tol=1e-7,reflect=False,eigen_solver='JD')   #we can not use reflect here, because SOC do not meet reflection condition!
    dmrgegn.use_U1_symmetry(model.qnumber,target_block=target_block)
    Emin,mps=dmrgegn.run_finite(endpoint=(5,'<-',0),maxN=[10,25,50,70,70,70,70],tol=1e-8)
    t1=time.time()
    print 'The Ground State Energy for %s: %s, Elapse %s.'%(model,Emin,t1-t0)
    print 'FIN - CORE:%s'%RANK
    mps.save(filename_mps)
    savetxt(filename_eng,Emin)
    return Emin,mps
예제 #14
0
파일: views.py 프로젝트: GiggleLiu/apps
def show_frac_charge(filename=None,bias=False,usevec=False,theta=0,dmu=0.01,target_block=(0,0),append=False,**kwargs):
    '''
    Show the fractional charge wave functions.
    '''
    model,expander=get_solving_system(evolutor_type='masked',periodic=False,**kwargs)
    if filename is None:
        filename='data/frac_W1%s_W2%s_U%s_N%s'%(kwargs.get('K1'),kwargs.get('K2'),kwargs.get('U'),kwargs.get('nsite'))
    if not bias:
        ket_even=MPS.load(filename+'-even.dat')
        ket_odd=MPS.load(filename+'-odd.dat')
        #ket_odd=ket_odd-(ket_even.tobra(labels=ket_even.labels)*ket_odd).item()*ket_even
        #combine to left-right edge states.
        if usevec:
            ket_odd,ket_even=ket_odd.state,ket_even.state
        #else:
            #ket_odd.recanonicalize(tol=1e-8)
        ket_left=ket_even#(ket_even+exp(1j*theta)*ket_odd)/sqrt(2.)
        ket_right=ket_odd#(ket_even-exp(1j*theta)*ket_odd)/sqrt(2.)
        if not usevec:
            ket_left.recanonicalize(tol=1e-8)   #we must recanonicalize it, for it is not canonical!!!
            ket_right.recanonicalize(tol=1e-8)
            print ket_left
            print ket_right
            pls=[dos4mps(spaceconfig=expander.spaceconfig,ket=ket) for ket in [ket_left,ket_right]]
        else:
            pls=[dos4vec(spaceconfig=model.hgen.spaceconfig,ket=ket) for ket in [ket_left,ket_right]]
    else:
        suffix='W1%s_W2%s_U%s_N%s_dmu%s_%s.dat'%(kwargs.get('K1'),kwargs.get('K2'),kwargs.get('U'),kwargs.get('nsite'),dmu,target_block)
        filename_mps='data/mps_'+suffix
        print filename_mps
        fname='data/fracdos_'+suffix
        #suffix2='W1%s_W2%s_U%s_N%s_dmu%s_%s.dat'%(kwargs.get('K1'),kwargs.get('K2'),kwargs.get('U'),kwargs.get('nsite'),dmu,(0,-1))
        #filename_mps2='data/mps_'+suffix2
        if append:
            pls=loadtxt(fname)[newaxis,:,:]
        else:
            ket_bias=MPS.load(filename_mps)
            #ket_bias=1./sqrt(2)*(MPS.load(filename_mps2)-1j*ket_bias)
            #ket_bias.compress()
            pls=[dos4mps(spaceconfig=expander.spaceconfig,ket=ket) for ket in [ket_bias]]
            savetxt(fname,pls[0].real)

    #pls=sum(pls,axis=1)
    pls=array(pls)-0.5
    nsite=pls.shape[-1]
    pls_left=pls[:,:,:nsite/2]
    pls_right=pls[:,:,nsite/2:]
    print 'occupation in left block -> %s, right block -> %s.'%(sum(pls_left,axis=(-1,-2)),sum(pls_right,axis=(-1,-2)))
    if ONSV: return pls
    ion()
    lw=2
    lc='r'
    for n in xrange(len(pls)):
        pln=pls[n]
        ax=subplot(101+n+10*len(pls))
        for s in xrange(2):
            color='b' if s==0 else 'r'
            lc=LineCollection([[(i,0),(i,pln[s,i].real.item())] for i in xrange(model.nsite)])
            lc.set_linewidth(lw)
            lc.set_color(color)
            lc.set_linestyle('--' if s==1 else '-')
            ax.add_collection(lc)

        ax.autoscale()
        ax.margins(0.1)
        xlabel('N')
        ylabel(r'$\rho-\bar{\rho}$')
    pdb.set_trace()