6 return np.trace(rho.dot(rho)) 7 8 # Partial trace of bipartite systems 9 def PartialTrace(rho,d1,d2,system=1): 10 axis1,axis2 = 1,3 11 if system == 2: 12 axis1 -= 1 13 axis2 -= 1 14 return np.trace(rho.reshape(d1,d2,d1,d2), axis1=axis1, axis2=axis2) 15 16 d1,d2 = 2,2 # dimension of each subsystem 17 B1,B2 = np.eye(d1),np.eye(d2) # basis for each subssystem 18 thetas = np.linspace(0,np.pi/2,100) # angle for superposition coefficient 19 purity = [] # purity set 20 for theta在thetas:#超过theta 21 psi =(np.cos(theta)*np.kron(b1 [0],b2 [0]),b2 [0])+np.sin(theta)*np.kron(b1 [1],b2 [1],b2 [1],b2 [1])#状态矢量22 rho = np.outer(psi,psi,psi,psi conjate(PSI)#) parttrace(Rho,D1,D2,System = 1)#系统的边际状态1 24 PURITY.APPEND(PURITY(RHO1))#计算和附加纯度25 FIG,AX = PLT.Subplots(figsize =(6,2))26 AX.Plot(Thetas/Np.pi,np.pi,pureity,purity,purity,poletity,colority,colority,colory ='blue'); 27 AX.SET_XLABEL(r'ub \ theta/\ pi $',usetex = true,fontsize = 10); 28 AX.SET_YLABEL(r'purity $ \ Mathcal {p} [\ rho_1(\ theta)] $',usetex = true,fontsize = 10);