Exemplo n.º 1
0
def get_opC(i,spaceconfig,index,ordering,dag=False):
    '''Get a C operator for site i and index index.'''
    #ZL=[opunit_Z(spaceconfig,siteindex=j) for j in xrange(nsite)]
    ci=opunit_C(spaceconfig,index=index,siteindex=i,dag=dag)
    ci=prod([ci]+[opunit_Z(spaceconfig=spaceconfig,siteindex=j) for j in where(ordering<ordering[i])[0]])
    if isinstance(ci,OpString):
        ci.compactify()
    return ci
Exemplo n.º 2
0
def sweep_fidelity_f(kets,spaceconfig,maxN=None,usvmode=False):
    '''
    Sweep fidelity from center to edge, the version with fermionic sign.

    Parameters:
        :kets: len-2 list, the kets to sweep fidelity.
        :maxN: int, the maximum retained singular value for usv mode, and the maximum retained states for direct mode.
        :usvmode: bool, use usv mode if True.
    '''
    nsite=kets[0].nsite
    bra=kets[0].tobra(labels=[kets[0].labels[0],kets[0].labels[1]+'\''])
    ket=kets[1]
    ordering=kets[0].forder
    assert(allclose(ordering,arange(nsite)[::-1]))

    if not usvmode and maxN is not None:
        #compress datas
        ket.compress(maxN=maxN)
        bra.compress(maxN=maxN)
    ket>>(nsite/2-ket.l,1e-8,Inf)
    bra>>(nsite/2-bra.l,1e-8,Inf)
    ket_bra=bra.toket()
    bra_ket=ket.tobra()

    #get SRLS(sign for right part) from right to left
    site_axis=ket.site_axis
    rlink_axis=ket.rlink_axis
    llink_axis=ket.llink_axis
    op=prod([opunit_Z(spaceconfig,siteindex=j) for j in xrange(nsite/2,nsite)])
    #op=prod([OpUnitI(hndim=spaceconfig.hndim,siteindex=j) for j in xrange(nsite/2,nsite)])
    SRLS=[]
    for kt,br in [(ket,bra_ket),(ket_bra,bra)]:
        if br is bra:
            kt.chlabel('site',br.labels[0]+'2')
            kt.chlabel('link',br.labels[1]+'2')
        else:
            br.chlabel('site',kt.labels[0]+'2')
            br.chlabel('link',kt.labels[1]+'2')
        SRL=[]
        res=None
        for i in xrange(nsite/2):
            sitei=nsite-i-1
            M=kt.get(sitei,attach_S='A')
            MH=br.get(sitei,attach_S='A')
            if i==0:
                MH.labels[rlink_axis]=M.labels[rlink_axis]

            opunit=op if isinstance(op,OpUnit) else op.query(sitei)[0]
            MH.labels[site_axis]=M.labels[site_axis]+'\''
            O=tensor.Tensor(opunit.get_data(),labels=[MH.labels[site_axis],M.labels[site_axis]])
            items=[MH,O,M]
            for item in items:
                res=tensor.contract(res,item) if res is not None else item
            SRL.append(res.diagonal())
            assert(sum(abs(res))-sum(abs(res.diagonal()))<1e-5)
        SRLS.append(SRL)
    SRLS=zip(SRLS)

    #calculation
    edge_labels_l=[bra.AL[-1].labels[rlink_axis],ket.AL[-1].labels[rlink_axis]]
    bra.BL[0].labels[llink_axis]+='@'
    ket.BL[0].labels[llink_axis]+='@'
    edge_labels_r=[bra.BL[0].labels[llink_axis],ket.BL[0].labels[llink_axis]]
    if usvmode:
        Ci=USVobj(U=tensor.Tensor(diag(bra.S)[:,newaxis,:],labels=[edge_labels_l[0],'null',edge_labels_r[0]]),S=None,\
                V=tensor.Tensor(diag(ket.S)[:,newaxis,:],labels=[edge_labels_l[1],'null',edge_labels_r[1]]))
    else:
        Ci=tensor.Tensor(diag(bra.S),labels=[edge_labels_l[0],edge_labels_r[0]])*tensor.Tensor(diag(ket.S),labels=[edge_labels_l[1],edge_labels_r[1]])
    fs=[1]
    SL=[]
    for i in xrange(ket.nsite/2):
        t0=time.time()
        site_l=nsite/2-i-1
        site_r=nsite/2+i
        if usvmode:
            t0=time.time()
            Li=USVobj(U=bra.get(site_l,attach_S='B'),S=None,V=ket.get(site_l,attach_S='B'))
            Ci=Li.join(Ci)
            print Ci
            Ci=Ci.compress(min(maxN,min(Ci.shape)))
            Ri=USVobj(U=bra.get(site_r,attach_S='A'),S=None,V=ket.get(site_r,attach_S='A'))
            Ci=Ci.join(Ri)
            print Ci
            t1=time.time()
            Ci=Ci.compress(min(maxN,min(Ci.shape)))
            t2=time.time()
            print 'Elapse -> %s, %s'%(t1-t0,t2-t1)
            fi=sum(Ci.S)
            print Ci,Ci.S.min()
            SL.append(Ci.S)
        else:
            #get the sign
            SK,SB=SRLS[nsite/2-i-1]
            pdb.set_trace()
            Ci=bra.get(site_l,attach_S='B')*(ket.get(site_l,attach_S='B')*Ci)*bra.get(site_r,attach_S='A')*ket.get(site_r,attach_S='A')
            pdb.set_trace()
            #Ci=tensor.contract(mpses)
            Ci=Ci.chorder(array([0,2,1,3]))
            S=svdvals(Ci.reshape([Ci.shape[0]*Ci.shape[1],-1]))
            fi=sum(S)
            SL.append(S)
        fs.append(fi)
        t1=time.time()
        print '%s F->%s, Elapse->%s'%(i,fi,t1-t0)
        save('data/SL.npy',SL)
    return fs