def cattimepar(g,N,T,numt): kset=K(N)[0] kset=kset[(N/2):] u=np.zeros([numt,(N/2)],complex) v=np.zeros([numt,(N/2)],complex) poolsize=6 masterlist=[] for k in kset: list=[] list.append(k) list.append(g) list.append(T) list.append(numt) masterlist.append(list) pool=multiprocessing.Pool() pool_output=pool.map(getuvinflist,masterlist) pool.close() pool.join() for z in xrange(len(kset)): uv=pool_output[z] u[:,z]=uv[:,0] v[:,z]=uv[:,1] C=np.zeros([numt]) for q in xrange(numt): c=1. for kind in xrange(len(kset)): c=c*(np.sin(kset[kind]/2)*u[q,kind] + np.cos(kset[kind]/2)*v[q,kind])*(np.sin(kset[kind]/2)*u[q,kind] + np.cos(kset[kind]/2)*v[q,kind]).conj() C[q]=np.real(c) return C
def h1(g, N): kset = K(N)[0] kset = kset[(N / 2):] num = np.sin(kset) * np.sin(kset) den = ((g + np.cos(kset))**2) + (np.sin(kset) * np.sin(kset)) return 2. * np.sum(num / den) / (4. * N ) #2 is due to different time intervals
def dCdg(g,N,T,numt): # dgds=np.zeros([numt],complex) kset=K(N)[0] kset=kset[(N/2):] u=np.zeros([numt,len(kset)],complex) v=np.zeros([numt,len(kset)],complex) x=np.zeros([numt,len(kset)],complex) y=np.zeros([numt,len(kset)],complex) for kind in np.arange(len(kset)): uv=getuvinf(kset[kind],g,T,numt) u[:,kind]=uv[:,0] v[:,kind]=uv[:,1] ab=getabinf(kset[kind],g,T,numt) x[:,kind]=ab[:,0] y[:,kind]=ab[:,1] c=1. for kind in xrange(len(kset)): c=c*(np.sin(kset[kind]/2)*u[-1,kind] + np.cos(kset[kind]/2)*v[-1,kind])*(np.sin(kset[kind]/2)*u[-1,kind] + np.cos(kset[kind]/2)*v[-1,kind]).conj() c=np.real(c) summand=0. for kind in xrange(len(kset)): den=(np.sin(kset[kind]/2)*u[-1,kind] + np.cos(kset[kind]/2)*v[-1,kind])*(np.sin(kset[kind]/2)*u[-1,kind] + np.cos(kset[kind]/2)*v[-1,kind]).conj() fact1=np.sin(kset[kind]/2)*x[-1,kind]+np.cos(kset[kind]/2)*y[-1,kind] fact2=np.sin(kset[kind]/2)*u[-1,kind].conj() + np.cos(kset[kind]/2)*v[-1,kind].conj() fact3=y[:,kind].conj()*v[:,kind] - x[:,kind].conj()*u[:,kind] num=np.imag(fact1*fact2*fact3) summand=summand+(num/den) return np.real(-4*c*summand)
def defectstime(g,N,T,numt): kset=K(N)[0] kset=kset[(N/2):] u=np.zeros([numt,(N/2)],complex) v=np.zeros([numt,(N/2)],complex) for kind in np.arange(len(kset)): #this step parallelized uv=getuv(kset[kind],g,T,numt) u[:,kind]=uv[:,0] v[:,kind]=uv[:,1] D=np.zeros([numt]) kD=np.zeros([len(kset),numt],complex) for q in np.arange(numt): term1=u[q,:].conj()*v[q,:] + v[q,:].conj()*u[q,:] term1=-term1*np.sin(kset) term2=v[q,:].conj()*v[q,:] term2=-2*np.cos(kset)*term2 kD[:,q]=((1+term1+term2)/N) term1=np.sum(term1) term2=np.sum(term2) numdef=(N/2)+term1+term2 D[q]=np.real(numdef/N) #also calculate fidelity f=np.zeros([numt]) theta=np.zeros([len(kset)]) for q in np.arange(numt): for kind in np.arange(len(kset)): theta[kind]=gettheta(kset[kind],g[q]) fid=u[q,:]*np.cos(theta) + v[q,:]*np.sin(theta) f[q]=np.abs(fid.prod())**2 return D,f,kD
def dDdgpar(g,N,T,numt): dgds=np.zeros([numt],complex) kset=K(N)[0] kset=kset[(N/2):] u=np.zeros([numt,len(kset)],complex) v=np.zeros([numt,len(kset)],complex) x=np.zeros([numt,len(kset)],complex) y=np.zeros([numt,len(kset)],complex) poolsize=1 masterlist=[] for k in kset: list=[] list.append(k) list.append(g) list.append(T) list.append(numt) masterlist.append(list) pooluv=multiprocessing.Pool(processes=poolsize) pool_outputuv=pooluv.map(getuvlist,masterlist) pooluv.close() poolab=multiprocessing.Pool() pool_outputab=poolab.map(getablist,masterlist) poolab.close() pooluv.join() poolab.join() for z in xrange(len(kset)): uv=pool_outputuv[z] xy=pool_outputab[z] u[:,z]=uv[:,0] v[:,z]=uv[:,1] x[:,z]=xy[:,0] y[:,z]=xy[:,1] D=np.zeros([numt]) for q in np.arange(numt): term1=u[q,:].conj()*v[q,:] + v[q,:].conj()*u[q,:] term1=-term1*np.sin(kset) term2=v[q,:].conj()*v[q,:] term2=-2*np.cos(kset)*term2 term1=np.sum(term1) term2=np.sum(term2) numdef=(N/2)+term1+term2 D[q]=np.real(numdef/N) term1=u[-1,:].conj()*x[-1,:] + v[-1,:].conj()*y[-1,:] term2=u[-1,:].conj()*y[-1,:] + v[-1,:].conj()*x[-1,:] term2=-term2*np.sin(kset) term3=-2*np.cos(kset)*v[-1,:].conj()*y[-1,:] fact1=term1+term2+term3 for q in np.arange(numt): fact2=y[q,:].conj()*v[q,:]-x[q,:].conj()*u[q,:] dgds[q]=np.sum(fact1*fact2) return -8*np.imag(dgds),D
def dCdgpar(g,N,T,numt): # dgds=np.zeros([numt],complex) kset=K(N)[0] kset=kset[(N/2):] u=np.zeros([numt,len(kset)],complex) v=np.zeros([numt,len(kset)],complex) x=np.zeros([numt,len(kset)],complex) y=np.zeros([numt,len(kset)],complex) poolsize=1 masterlist=[] for k in kset: list=[] list.append(k) list.append(g) list.append(T) list.append(numt) masterlist.append(list) pooluv=multiprocessing.Pool() pool_outputuv=pooluv.map(getuvinflist,masterlist) pooluv.close() poolab=multiprocessing.Pool() pool_outputab=poolab.map(getabinflist,masterlist) poolab.close() pooluv.join() poolab.join() for z in xrange(len(kset)): uv=pool_outputuv[z] xy=pool_outputab[z] u[:,z]=uv[:,0] v[:,z]=uv[:,1] x[:,z]=xy[:,0] y[:,z]=xy[:,1] c=1. for kind in xrange(len(kset)): c=c*(np.sin(kset[kind]/2)*u[-1,kind] + np.cos(kset[kind]/2)*v[-1,kind])*(np.sin(kset[kind]/2)*u[-1,kind] + np.cos(kset[kind]/2)*v[-1,kind]).conj() c=np.real(c) summand=0. for kind in xrange(len(kset)): den=(np.sin(kset[kind]/2)*u[-1,kind] + np.cos(kset[kind]/2)*v[-1,kind])*(np.sin(kset[kind]/2)*u[-1,kind] + np.cos(kset[kind]/2)*v[-1,kind]).conj() fact1=np.sin(kset[kind]/2)*x[-1,kind]+np.cos(kset[kind]/2)*y[-1,kind] fact2=np.sin(kset[kind]/2)*u[-1,kind].conj() + np.cos(kset[kind]/2)*v[-1,kind].conj() fact3=y[:,kind].conj()*v[:,kind] - x[:,kind].conj()*u[:,kind] num=np.imag(fact1*fact2*fact3) summand=summand+(num/den) return np.real(-4*c*summand)
def dDdlambpar(g,lamb,N,T,numt): dgds=np.zeros([numt],complex) kset=K(N)[0] kset=kset[(N/2):] u=np.zeros([numt,len(kset)],complex) v=np.zeros([numt,len(kset)],complex) x=np.zeros([numt,len(kset)],complex) y=np.zeros([numt,len(kset)],complex) poolsize=5 masterlist=[] for k in kset: list=[] list.append(k) list.append(g) list.append(lamb) list.append(N) list.append(T) list.append(numt) masterlist.append(list) pooluv=multiprocessing.Pool(processes=poolsize) pool_outputuv=pooluv.map(getuvLlist,masterlist) pooluv.close() poolab=multiprocessing.Pool() pool_outputab=poolab.map(getabLlist,masterlist) poolab.close() pooluv.join() poolab.join() for z in xrange(len(kset)): uv=pool_outputuv[z] xy=pool_outputab[z] u[:,z]=uv[:,0] v[:,z]=uv[:,1] x[:,z]=xy[:,0] y[:,z]=xy[:,1] term1=u[-1,:].conj()*x[-1,:] + v[-1,:].conj()*y[-1,:] term2=u[-1,:].conj()*y[-1,:] + v[-1,:].conj()*x[-1,:] term2=-term2*np.sin(kset) term3=-2*np.cos(kset)*v[-1,:].conj()*y[-1,:] fact1=term1+term2+term3 for q in np.arange(numt): fact2=y[q,:].conj()*u[q,:]-x[q,:].conj()*v[q,:] fact2=-4*1j*h1(g[q],N)*np.sin(kset)*fact2 dgds[q]=np.sum(fact1*fact2) return -8*np.imag(dgds)
def defectstimeparerr(g,N,T,numt,err): kset=K(N)[0] kset=kset[(N/2):] u=np.zeros([numt,(N/2)],complex) v=np.zeros([numt,(N/2)],complex) poolsize=8 masterlist=[] for k in kset: list=[] list.append(k) list.append(g) list.append(T) list.append(numt) list.append(err) masterlist.append(list) pool=multiprocessing.Pool(processes=poolsize) pool_output=pool.map(getuverrlist,masterlist) pool.close() pool.join() for z in xrange(len(kset)): uv=pool_output[z] u[:,z]=uv[:,0] v[:,z]=uv[:,1] D=np.zeros([numt]) kD=np.zeros([len(kset),numt],complex) for q in np.arange(numt): term1=u[q,:].conj()*v[q,:] + v[q,:].conj()*u[q,:] term1=-term1*np.sin(kset) term2=v[q,:].conj()*v[q,:] term2=-2*np.cos(kset)*term2 kD[:,q]=((1+term1+term2)/N) term1=np.sum(term1) term2=np.sum(term2) numdef=(N/2)+term1+term2 D[q]=np.real(numdef/N) #also calculate fidelity f=np.zeros([numt]) theta=np.zeros([len(kset)]) for q in np.arange(numt): for kind in np.arange(len(kset)): theta[kind]=gettheta(kset[kind],g[q]) fid=u[q,:]*np.cos(theta) + v[q,:]*np.sin(theta) f[q]=np.abs(fid.prod())**2 return D,f,kD
def cattime(g,N,T,numt): kset=K(N)[0] kset=kset[(N/2):] u=np.zeros([numt,(N/2)],complex) v=np.zeros([numt,(N/2)],complex) for kind in np.arange(len(kset)): uv=getuvinf(kset[kind],g,T,numt) u[:,kind]=uv[:,0] v[:,kind]=uv[:,1] C=np.zeros([numt]) for q in xrange(numt): c=1. for kind in xrange(len(kset)): c=c*(np.sin(kset[kind]/2)*u[q,kind] + np.cos(kset[kind]/2)*v[q,kind])*(np.sin(kset[kind]/2)*u[q,kind] + np.cos(kset[kind]/2)*v[q,kind]).conj() C[q]=np.real(c) return C
def defects(g,N,T,numt): start=time.time() kset=K(N)[0] kset=kset[(N/2):] u=np.zeros([numt,(N/2)],complex) v=np.zeros([numt,(N/2)],complex) for kind in np.arange(len(kset)): uv=getuv(kset[kind],g,T,numt) u[:,kind]=uv[:,0] v[:,kind]=uv[:,1] term1=2*np.real(u[-1,:].conj()*v[-1,:]) term1=-term1*np.sin(kset) term2=np.absolute(v[-1,:])**2 term2=-2*np.cos(kset)*term2 term1=np.sum(term1) term2=np.sum(term2) numdef=(N/2)+term1+term2 end=time.time() print end-start return numdef/N
def defectsLtimepar(g,lamb,N,T,numt): kset=K(N)[0] kset=kset[(N/2):] u=np.zeros([numt,(N/2)],complex) v=np.zeros([numt,(N/2)],complex) poolsize=5 masterlist=[] for k in kset: list=[] list.append(k) list.append(g) list.append(lamb) list.append(T) list.append(numt) masterlist.append(list) pool=multiprocessing.Pool(processes=poolsize) pool_output=pool.map(getuvLlist,masterlist) pool.close() pool.join() for z in xrange(len(kset)): uv=pool_output[z] u[:,z]=uv[:,0] v[:,z]=uv[:,1] D=np.zeros([numt]) for q in np.arange(numt): term1=u[q,:].conj()*v[q,:] + v[q,:].conj()*u[q,:] term1=-term1*np.sin(kset) term2=v[q,:].conj()*v[q,:] term2=-2*np.cos(kset)*term2 term1=np.sum(term1) term2=np.sum(term2) numdef=(N/2)+term1+term2 D[q]=np.real(numdef/N) return D
def dDdg(g,N,T,numt): dgds=np.zeros([numt],complex) kset=K(N)[0] kset=kset[(N/2):] u=np.zeros([numt,len(kset)],complex) v=np.zeros([numt,len(kset)],complex) x=np.zeros([numt,len(kset)],complex) y=np.zeros([numt,len(kset)],complex) for kind in np.arange(len(kset)): uv=getuv(kset[kind],g,T,numt) u[:,kind]=uv[:,0] v[:,kind]=uv[:,1] ab=getab(kset[kind],g,T,numt) x[:,kind]=ab[:,0] y[:,kind]=ab[:,1] term1=u[-1,:].conj()*x[-1,:] + v[-1,:].conj()*y[-1,:] term2=u[-1,:].conj()*y[-1,:] + v[-1,:].conj()*x[-1,:] term2=-term2*np.sin(kset) term3=-2*np.cos(kset)*v[-1,:].conj()*y[-1,:] fact1=term1+term2+term3 for q in np.arange(numt): fact2=y[q,:].conj()*v[q,:]-x[q,:].conj()*u[q,:] dgds[q]=np.sum(fact1*fact2) return -8*np.imag(dgds)