Example #1
0
def get_solving_system(K1,K2,U,nsite,mu=0.,t=1.,evolutor_type='null',periodic=False,perturb=None):
    '''
    Set the parameters and get the solving system.

    Parameters:
        :K1,K2,U,mu,t: float, the parameters.
        :evolutor_type: str, 

            * 'null', do not perform any unitary and truncation during expansion of sites.
            * 'full', do blockize and unitary but no truncation is allowed.
            * 'masked', use kpmask to identify truncation.

    Return:
        tuple of (model, expander)
    '''
    assert(evolutor_type in ['null','full','masked'])
    model=BizardModel(K1=K1,K2=K2,U=U,t=t,mu=mu,nsite=nsite,periodic=periodic)
    if perturb is not None:
        if 'bSDW' in perturb.keys():
            model.perturb_bSDW(sites=perturb['bSDW'])
        elif 'mu' in perturb.keys():
            model.perturb_mu(sites=perturb['mu'][0],lamb=perturb['mu'][1])
    if evolutor_type=='null':
        return model,None
    else:
        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=evolutor_type)
        #ion()
        #H_serial.show_advanced()
        #pdb.set_trace()
        return model,expander
Example #2
0
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()
Example #3
0
def load_mps(alpha,Delta,Vz,mu,U,target_block,nsite,maxN=None,fixtail=True):
    '''
    Load Specific Matrix product state.

    Parameters:
        :which: tuple of dmu, target_block.
            
            * target_block, int, '+', '-'.
    Return:
        eng,mps
    '''
    suf=get_name(Vz,Delta,mu,alpha,nsite,periodic=False,resonance=False)
    spaceconfig1=SuperSpaceConfig(chorder([1,2,1,1]))
    suffix0=suf+'_%s'%target_block
    filename_mps0='data/mps_%s.dat'%suffix0
    filename_eng0='data/eng_%s.dat'%suffix0
    tblocks=(0,1)

    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

    if os.path.isfile(filename_mps0):
        eng,mps=get1(target_block)
        if maxN is not None:
            mps.compress(maxN=maxN)
        return eng,mps
    elif isinstance(target_block,str):
        eng,mps1=get1(tblocks[0])
        eng,mps2=get1(tblocks[1])
        if maxN is not None:
            mps1.compress(maxN=int(maxN/sqrt(2)))
            mps2.compress(maxN=int(maxN/sqrt(2)))
        if target_block=='+':
            mps=1./sqrt(2.)*(mps1+mps2)
        elif target_block=='-':
            mps=1./sqrt(2.)*(mps1-mps2)
        elif target_block=='+i':
            mps=1./sqrt(2.)*(mps1+1j*mps2)
        elif target_block=='-i':
            mps=1./sqrt(2.)*(mps1-1j*mps2)
        else:
            raise ValueError('')
        if maxN is None:
            mps.recanonicalize()
        else:
            mps.compress(maxN=maxN)
    else:
        raise Exception('File %s do not exist!'%filename_mps0)
    if not os.path.isfile(filename_mps0):
        mps.save(filename_mps0)
        savetxt(filename_eng0,[eng])
    return eng,mps
Example #4
0
def entanglement_spec(K1,K2,U,dmu,nsite,target_block,ibond,maxN=200):
    '''Get the entanglement spectrum of specific state.'''
    eng,mps=load_mps(K1=K1,K2=K2,U=U,which=(dmu,target_block),nsite=nsite,maxN=200)
    spaceconfig=SuperSpaceConfig(chorder([2,1,1]))
    mps>>ibond-mps.l
    spec=mps.S**2
    S=-sum(spec*log(spec)/log(2))
    print spec
    print 'Entropy =',S

    pdb.set_trace()
Example #5
0
def measure_order(which,delta,t,mu,nsite,polarity,siteindices=None,usempi=True,anchor=None,**kwargs):
    '''
    Get order parameter from ground states.

    Parameters:
        :which: str, 

            * 'RHO', <N(i)>
        :nsite: int, the number of sites.
        :siteindices: list, the measure points.

    Return:
        number, the value of order parameter.
    '''
    if anchor is None:anchor=nsite/2
    if siteindices is None: siteindices=arange(nsite)
    siteindices=array(siteindices)
    spaceconfig=SuperSpaceConfig(chorder([1,1,1]))
    suffix=get_name(t=t,mu=mu,delta=delta,nsite=nsite)
    ofile='data/%s_%s_%s.dat'%(which,suffix,polarity)
    filename='data/mps_%s.dat'%suffix
    eng,ket=load_mps(t=t,mu=mu,delta=delta,nsite=nsite,polarity=polarity,maxN=200,fixtail=True)
    ml=[]
    ordering=arange(nsite)[::-1]
    def measure1(siteindex):
        if which=='RHO':
            op=opunit_N(spaceconfig,index=None,siteindex=siteindex)
        else:
            raise NotImplementedError()
        if isinstance(op,OpCollection):
            m=sum([get_expect(opi,ket=ket) for opi in op.ops])
        else:
            m=get_expect(op,ket=ket)#,bra=ket.tobra(labels=ket.labels))
        print 'Get %s for site %s = %s @RANK: %s'%(which,siteindex,m.item(),RANK)
        return m

    if usempi:
        ml=mpido(measure1,inputlist=siteindices)
    else:
        ml=[]
        for siteindex in siteindices:
            ml.append(measure1(siteindex))
    ml=array(ml)
    if RANK==0:
        savetxt(ofile,ml.real)
    return ml
Example #6
0
def get_solving_system(alpha,Vz,Delta,U,nsite,mu=0.,t=1.,evolutor_type='null',periodic=True):
    '''
    Set the parameters and get the solving system.

    Parameters:
        :alpha,Vz,Delta,U,mu,t: float, the parameters.
        :evolutor_type: str, 

            * 'null', do not perform any unitary and truncation during expansion of sites.
            * 'full', do blockize and unitary but no truncation is allowed.
            * 'masked', use kpmask to identify truncation.

    Return:
        tuple of (model, expander)
    '''
    assert(evolutor_type in ['null','full','masked'])
    model=RashbaModel(alpha=alpha,Vz=Vz,U=U,Delta=Delta,t=t,mu=mu,nsite=nsite,periodic=periodic,occ=True,kspace=False)
    spaceconfig=model.hgen.spaceconfig
    spaceconfig1=SuperSpaceConfig(chorder([1,spaceconfig.nspin,1,spaceconfig.norbit]))
    H_serial=op2collection(op=model.hgen.get_opH())
    expander=RGHGen(H=H_serial,spaceconfig=spaceconfig1,evolutor_type=evolutor_type,use_zstring=True)
    return model,expander
Example #7
0
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
Example #8
0
def load_mps(t,mu,delta,polarity,nsite,maxN=None,fixtail=True):
    '''
    Load Specific Matrix product state.

    Parameters:
        :which: tuple of dmu, polarity.
            
            * polarity, int, '+', '-'.
    Return:
        eng,mps
    '''
    suf=get_name(t=t,mu=mu,delta=delta,nsite=nsite)
    spaceconfig1=SuperSpaceConfig(chorder([1,1,1,1]))
    suffix0='%s_%s'%(suf,polarity)
    filename_mps0='data/mps_%s.dat'%suffix0
    filename_eng0='data/eng_%s.dat'%suffix0
    tblocks=('l','r')

    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

    if os.path.isfile(filename_mps0):
        eng,mps=get1(polarity)
        if maxN is not None:
            mps.compress(maxN=maxN)
        return eng,mps
    elif isinstance(polarity,str):
        eng,mps1=get1(tblocks[0])
        eng,mps2=get1(tblocks[1])
        if maxN is not None and maxN is not Inf:
            mps1.compress(maxN=int(maxN/sqrt(2)))
            mps2.compress(maxN=int(maxN/sqrt(2)))
        if polarity=='+i':
            mps=1./sqrt(2.)*(mps1+1j*mps2)
        elif polarity=='-i':
            mps=1./sqrt(2.)*(mps1-1j*mps2)
        elif polarity=='+':
            mps=1./sqrt(2.)*(mps1+mps2)
        elif polarity=='-':
            mps=1./sqrt(2.)*(mps1-mps2)
        elif polarity=='l':
            mps=mps1
        elif polarity=='r':
            mps=mps2
        else:
            raise ValueError('')
        mps.recanonicalize()
        if maxN is not None:
            mps.compress(maxN=maxN)
    else:
        raise Exception('File %s do not exist!'%filename_mps0)
    if not os.path.isfile(filename_mps0):
        mps.save(filename_mps0)
        savetxt(filename_eng0,[eng])
    return eng,mps
Example #9
0
def measure_order(which,dmu=0.01,target_block=(0,0),siteindices=None,append=False,usempi=True,anchor=None,**kwargs):
    '''
    Get order parameter from ground states.

    Parameters:
        :which: str, 

            * 'bSDW', 
            * 'bSDW1', 
            * 'SDW', 
            * 'triplet'
            * 'sPDW'.
            * 'TX'
            * 'CDW', <Rho*Rho>-<Rho>*<Rho>
            * 'Sx', <Sx>
            * 'SxSx0', <Sx*Sx(0)>
        :nsite: int, the number of sites.
        :siteindices: list, the measure points.

    Return:
        number, the value of order parameter.
    '''
    nsite=kwargs.get('nsite')
    if anchor is None:anchor=nsite/2
    if siteindices is None: siteindices=arange(nsite)
    siteindices=array(siteindices)
    spaceconfig=SuperSpaceConfig(chorder([2,1,1]))
    suffix='W1%s_W2%s_U%s_N%s_dmu%s_%s'%(kwargs.get('K1'),kwargs.get('K2'),kwargs.get('U'),kwargs.get('nsite'),dmu,target_block)
    ofile='data/%s_%s.dat'%(which,suffix)
    if kwargs.get('ket') is not None:
        ket=kwargs.get('ket')
    else:
        filename='data/mps_%s.dat'%suffix
        if append:
            #ket=MPS.load(filename)
            eng,ket=load_mps(K1=kwargs.get('K1'),K2=kwargs.get('K2'),U=kwargs.get('U'),which=(dmu,target_block),nsite=nsite,maxN=200)
        else:
            EG,ket=solve('dmrg',periodic=False,method_args={'target_block':target_block,'nlevel':1},**kwargs)
            ket.save(filename)
    ml=[]
    def measure1(siteindex):
        if which=='SDW':   #cj+ sx cj ~ (-1)^j*m
            op=opunit_S(which='x',spaceconfig=spaceconfig,siteindex=siteindex)
        elif which=='sPDW':   #cjup+ cjdn+ ~ (-1)^j*G
            cup_d=opunit_C(dag=True,index=0,spaceconfig=spaceconfig,siteindex=siteindex)
            cdn_d=opunit_C(dag=True,index=1,spaceconfig=spaceconfig,siteindex=siteindex)
            cup_0=opunit_C(dag=False,index=0,spaceconfig=spaceconfig,siteindex=anchor)
            cdn_0=opunit_C(dag=False,index=1,spaceconfig=spaceconfig,siteindex=anchor)
            op=(cup_0*cdn_0)*(cup_d*cdn_d)
            if isinstance(op,OpString):
                op.compactify()
        elif which=='bSDW':   #cj+ sx cj+1 + h.c. ~ (-1)^j*M
            opi=get_bsdw_op(spaceconfig,siteindex,nsite=nsite)
            op0=get_bsdw_op(spaceconfig,siteindex=anchor,nsite=nsite)
            op=(op0*opi).compactify()
            op.insert_Zs(spaceconfig)
        elif which=='bSDW1':
            op=get_bsdw_op2(spaceconfig,siteindex,nsite=nsite)
            op.insert_Zs(spaceconfig)
        elif which=='TX':  #<S_z^2> - <S_z>^2
            op_sz=opunit_S(which='z',spaceconfig=spaceconfig,siteindex=siteindex)
            op=op_sz*op_sz
        elif which=='CDW':
            op_n=opunit_N(spaceconfig,index=None,siteindex=siteindex)
            op_n0=opunit_N(spaceconfig,index=None,siteindex=anchor)
            op=op_n*op_n0
        elif which=='RHO':
            op=opunit_N(spaceconfig,index=None,siteindex=siteindex)
        elif which=='triplet': #cj+ sx isy (cj+1+)^t
            cup_d=opunit_C(dag=True,index=0,spaceconfig=spaceconfig,siteindex=siteindex)
            cup_dp=opunit_C(dag=True,index=0,spaceconfig=spaceconfig,siteindex=siteindex+1)
            op=cup_d*cup_dp
            #raise NotImplementedError()
        elif which=='Sx':
            op=opunit_S(which='x',spaceconfig=spaceconfig,siteindex=siteindex)
        elif which=='SxSx0':
            op_Sx=opunit_S(which='x',spaceconfig=spaceconfig,siteindex=siteindex)
            op_Sx=opunit_S(which='x',spaceconfig=spaceconfig,siteindex=anchor)
            op=op_Sx*op_Sx
        elif which=='DBL':
            op_n=opunit_N(spaceconfig,index=0,siteindex=siteindex)*opunit_N(spaceconfig,index=1,siteindex=siteindex)
            op_n0=opunit_N(spaceconfig,index=0,siteindex=nsite/2)*opunit_N(spaceconfig,index=1,siteindex=anchor)
            op=op_n*op_n0
        else:
            raise NotImplementedError()
        if isinstance(op,OpCollection):
            m=sum([get_expect(opi,ket=ket) for opi in op.ops])
        else:
            m=get_expect(op,ket=ket)#,bra=ket.tobra(labels=ket.labels))
        print 'Get %s for site %s = %s @RANK: %s'%(which,siteindex,m,RANK)
        return m

    if usempi:
        ml=mpido(measure1,inputlist=siteindices)
    else:
        ml=[]
        for siteindex in siteindices:
            ml.append(measure1(siteindex))
    ml=array(ml)
    if RANK==0:
        savetxt(ofile,ml.real)
    return ml
Example #10
0
def load_mps(K1,K2,U,which,nsite,maxN=None,fixtail=True):
    '''
    Load Specific Matrix product state.

    Parameters:
        :which: tuple of dmu, target_block.
            
            * dmu, 'E', 'O', float.
            * target_block, (int,int), '+', '-'.
    Return:
        eng,mps
    '''
    spaceconfig=SuperSpaceConfig(chorder([2,1,1]))
    dmu,target_block=which
    tblocks=[(0,0),(0,1)]
    dmus=[0.01,-0.01]
    suffix0='W1%s_W2%s_U%s_N%s_dmu%s_%s.dat'%(K1,K2,U,nsite,dmu,target_block)
    filename_mps0='data/mps_'+suffix0
    filename_eng0='data/eng_'+suffix0

    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

    if os.path.isfile(filename_mps0):
        eng,mps=get1(dmu,target_block)
        if maxN is not None:
            mps.compress(maxN=maxN)
            mps=mps/sqrt(sum(mps.S**2))
        return eng,mps
    elif isinstance(target_block,str):
        eng,mps1=load_mps(K1,K2,U,which=(dmu,tblocks[0]),nsite=nsite,maxN=maxN)
        eng,mps2=load_mps(K1,K2,U,which=(dmu,tblocks[1]),nsite=nsite,maxN=maxN)
        if target_block=='+':
            mps=1./sqrt(2.)*(mps1+mps2)
        elif target_block=='-':
            mps=1./sqrt(2.)*(mps1-mps2)
        elif target_block=='+i':
            mps=1./sqrt(2.)*(mps1+1j*mps2)
        elif target_block=='-i':
            mps=1./sqrt(2.)*(mps1-1j*mps2)
        elif target_block=='0':
            mps=mps1
        elif target_block=='1':
            mps=mps2
        else:
            print target_block
            raise ValueError('')
        mps.recanonicalize()
    elif isinstance(dmu,str):
        eng,mps1=load_mps(K1,K2,U,which=(dmus[0],target_block),nsite=nsite,maxN=maxN)
        eng,mps2=load_mps(K1,K2,U,which=(dmus[1],target_block),nsite=nsite,maxN=maxN)
        if dmu=='E':
            mps=1./sqrt(2.)*(mps1+mps2)
        elif dmu=='O':
            mps=1./sqrt(2.)*(mps1-mps2)
        elif dmu=='Ei':
            mps=1./sqrt(2.)*(mps1+1j*mps2)
        elif dmu=='Oi':
            mps=1./sqrt(2.)*(mps1-1j*mps2)
        elif dmu=='L':
            mps=mps1
        elif dmu=='R':
            mps=mps2
        else:
            print dmu
            raise ValueError('')
        mps.recanonicalize()
    if maxN is not None:
        mps.compress(maxN=maxN)
        mps=mps/sqrt(sum(mps.S**2))
    if not os.path.isfile(filename_mps0):
        mps.save(filename_mps0)
        savetxt(filename_eng0,[eng])
    return eng,mps