def calground(sites,K1,K2,U,dmu=0,override=True): ''' The perturbation version of calculating fractional charge. ''' t=1. blkid=0 target_block=(0,0) solve_method=lambda nsite:solve1(K1,K2,U,dmu,target_block,nsite,override) mpido(solve_method,inputlist=sites,bcastouputmesh=False)
def order_scale(which,K1,K2,U,sites,dmu=0,target_block=(0,0),append=False,usempi=False): '''Get the scaling behavior of order parameters.''' suffix='W1%s_W2%s_U%s_NN%s_dmu%s_%s.dat'%(K1,K2,U,len(sites),dmu,target_block) filename='data/%s_%s'%(which,suffix) if append: f=open(filename,'r') mls=cPickle.load(f) f.close() else: t0=time.time() def solve1(nsite): ml=measure_order(which,siteindices=None,append=True,K1=K1,K2=K2,U=U,nsite=nsite,dmu=dmu,target_block=target_block,usempi=not usempi) return ml if usempi: mls=mpido(solve1,inputlist=sites,bcastouputmesh=False) else: mls=[] for nsite in sites: mls.append(solve1(nsite)) if RANK==0: t1=time.time() print 'Elapse -> %s, on RANK: %s'%(t1-t0,RANK) f=open(filename,'w') cPickle.dump(mls,f) f.close() if ONSV: return if which=='CDW': rfilename='data/%s_%s'%('RHO',suffix) if os.path.isfile(rfilename): rf=open(rfilename,'r') rhos=cPickle.load(rf) rf.close() mls=[ml+1-rho*rho[len(rho)/2] for ml,rho in zip(mls,rhos)] spl=[] for nsite,ml in zip(sites,mls): #ml=cos(arange(nsite)*pi) ml=array(ml).real mqsi=fft.fft(ml) spi=abs(mqsi[nsite/2]) #spi=abs(mqsi[nsite/2-1:nsite/2+1]) spl.append(spi) vsites=(sites[:-1]+sites[1:])/2. cindex=log(abs(diff(spl)/diff(sites)))/log(vsites) print 'The cirtical index is %s'%cindex pdb.set_trace() ion() x=log(vsites) y=log(abs(diff(spl)/diff(sites))) plot(x,y) #plot(log(vsites),log(abs(diff(spl)/diff(sites)))) pdb.set_trace()
def scan_nonlocality(J,h,nsite,angles1,angles2,maxN=140,append=False,token=''): ''' Scan the non locality on a block sphere. ''' sites=arange(nsite+1) suffix=get_name(J=J,h=h,nsite=nsite) ffile='data/scan_fidelity_%s_s%s%s.dat'%(suffix,len(angles1),token) def measure1(angles): (theta1,phi1),(theta2,phi2)=angles fs=bulk_edge_fidelity(J=J,h=h,nsite=nsite,target_blocks=({'theta':theta1,'phi':phi1},{'theta':theta2,'phi':phi2}),direction='->',maxN=maxN,append=append) y=fs[nsite/2] return y ml=mpido(measure1,inputlist=zip(angles1,angles2)) print 'Fin. ml = %s'%ml if RANK==0: savetxt(ffile,ml)
def measure_order(which,J,h,nsite,target_block,siteindices=None,usempi=True,anchor=None,**kwargs): ''' Get order parameter from ground states. Parameters: :which: str, * 'Sz', <Sz> :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=SpinSpaceConfig([2,1]) suffix=get_name(h=h,J=J,nsite=nsite) ofile='data/%s_%s.dat'%(which,suffix) filename='data/mps_%s.dat'%suffix eng,ket=load_mps(h=h,J=J,nsite=nsite,target_block=target_block,maxN=200) ml=[] ordering=arange(nsite)[::-1] def measure1(siteindex): if which=='Sz': op=opunit_S(which='z',siteindex=siteindex,spaceconfig=spaceconfig) 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
def smajorana4mps(spaceconfig,ket_even,ket_odd,theta=0): ''' Get wave function of spin-majorana fermion from ground states of even and odd spin-parity. Parameters: :spaceconfig: <SuperSpaceConfig>, the configuration of Hilbert space. :ket_even/ket_odd: <MPS>, the state of even and odd parities. :theta: number, the overall state. Return: tuple of (pl1,pl2), the wave functions of majorana fermions. ''' #construct spin parity operator. data=opunit_Sz(spaceconfig).get_data()+0.5*identity(spaceconfig.hndim) fill_diagonal(data,exp(1j*pi*data.diagonal())) sp=OpUnit(data=data,label='P') def measure1(i): print 'Measuring Majorana fermion at site %s'%i bra_even=ket_even.tobra(labels=[ket_odd.labels[0],ket_even.labels[1]+"'"]) bra_odd=ket_odd.tobra(labels=[ket_odd.labels[0],ket_odd.labels[1]+"'"]) signl=[] si=opunit_S(spaceconfig,which='+',siteindex=i) for j in xrange(i): spi=copy.copy(sp) spi.siteindex=j signl.append(spi) si=prod(signl+[si]) c01=get_expect(si,ket=ket_odd,bra=bra_even) c10=get_expect(si,ket=ket_even,bra=bra_odd) ph1=exp(1j*theta)*c10+exp(-1j*theta)*c01 ph2=1j*(exp(1j*theta)*c10-exp(-1j*theta)*c01) p1=ph1 p2=ph2 return p1,p2,c01,c10 res=mpido(func=measure1,inputlist=arange(ket_even.nsite),bcastouputmesh=True) res=array(res) return res[:,0],res[:,1],res[:,2],res[:,3]
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