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
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
def measure_charge(K1,K2,U,nsite,usemps=True): ''' measure the particle number for 6 sites. ''' model,expander=get_solving_system(K1,K2,U=U,nsite=nsite,mu=0.,t=1.,evolutor_type='null',periodic=False) E,V=solve_direct(model,k=1) if usemps: ns=[opunit_N(spaceconfig=expander.spaceconfig,siteindex=i) for i in xrange(nsite)] mps=state2MPS(V[:,0],sitedim=expander.spaceconfig.hndim,l=0) dos=[expect_onsite(ket=mps,opunit=ns[i]) for i in xrange(nsite)] else: spaceconfig=model.hgen.spaceconfig vec=V[:,0] ns=[op_simple_onsite(spaceconfig=spaceconfig,label='n%s'%i,index=spaceconfig.c2ind(array([[0,i,0],[1,i,0]]))) for i in xrange(nsite)] dos=[vec.conj().dot(ns[i]().dot(vec)) for i in xrange(nsite)] ion() plot(dos) ylim(0,2) pdb.set_trace()
def dos4mps(spaceconfig,ket): ''' Get dos from ground states. Parameters: :spaceconfig: <SuperSpaceConfig>, the configuration of Hilbert space. :ket: <MPS>, the state. Return: tuple of (nup, ndn), the dos for up and down spin. ''' nl=[[],[]] for i in xrange(ket.nsite): bra=ket.tobra(labels=[ket.labels[0],ket.labels[1]+"'"]) for spin in xrange(2): ni=opunit_N(spaceconfig,index=spin,siteindex=i) #nn=get_expect(ni,ket=ket,bra=None) nn=expect_onsite(ni,ket=ket,bra=None) nl[spin].append(nn) print 'measure %s-th site -> %s.'%(i,nn) return array(nl)
def chmu(dmrgegn,dmu): '''Reset the hamiltonian.''' nsite=dmrgegn.hgen.nsite isweep,pos,direction=dmrgegn.status['isweep'],dmrgegn.status['pos'],dmrgegn.status['direction'] if isweep>1 or direction!='->' or pos!=1: return MAG=0.1 hgen=dmrgegn.hgen hchain=hgen.hchain dmu_opc=0 if dmu!=0 and isweep==0 and pos==1 and direction=='->': if dmu>0: MAG=-MAG for i in xrange(nsite): ouN=opunit_N(spaceconfig=hgen.spaceconfig,siteindex=i) opi=MAG*(-1)**i*ouN if isinstance(opi,OpUnit): opi.siteindex=i dmu_opc=dmu_opc+opi opcl=copy.deepcopy(hchain) opcl.insert_Zs(spaceconfig=hgen.spaceconfig) if not dmrgegn.reflect: opcr=copy.deepcopy(hchain) opcr=site_image(opcr,NL=0,NR=hgen.nsite,care_sign=True) opcr.insert_Zs(spaceconfig=hgen.spaceconfig) #add twisting parameters. if isweep==0 and pos==1 and direction=='->': if dmu_opc is not 0: opcr=opcr-dmu_opc opcl=opcl+dmu_opc for hgen in dmrgegn.LPART.values(): hgen.evolutees['H'].opc=opcl if not dmrgegn.reflect: for hgen in dmrgegn.RPART.values(): hgen.evolutees['H'].opc=opcr elif isweep==1 and pos==1 and direction=='->': for hgen in dmrgegn.LPART.values(): hgen.evolutees['H'].opc=opcl if not dmrgegn.reflect: for hgen in dmrgegn.RPART.values(): hgen.evolutees['H'].opc=opcr