def fidelity(statevec, dm, u_dm, ustatevec=np.array([0, 0])): ''' returns the fidelity (and its uncertainty) of the measured density matrix with a given state vector. ''' f = error.Formula() beta, a, x, b, alpha = sympy.symbols('beta,a,x,b,alpha') v = Matrix([alpha, beta]) rho = Matrix([[x, a + 1j * b], [a - 1j * b, 1 - x]]) f.formula = (v.conjugate().transpose() * rho * v)[0] f.values[alpha] = statevec[0] f.values[beta] = statevec[1] f.values[a] = float(np.real(dm[0, 1])) f.values[x] = float(dm[0, 0]) f.values[b] = float(np.imag(dm[0, 1])) f.uncertainties[alpha] = ustatevec[0] f.uncertainties[beta] = ustatevec[1] f.uncertainties[x] = u_dm[0, 0] f.uncertainties[a] = float(np.real(u_dm[0, 1])) f.uncertainties[b] = float(np.imag(u_dm[0, 1])) _fid, _ufid = f.num_eval() fid = float(_fid.as_real_imag()[0]) ufid = float(_ufid.as_real_imag()[0]) return (fid, ufid)
def fidelity(statevec, dm, u_dm, ustatevec=np.array([0,0])): ''' returns the fidelity (and its uncertainty) of the measured density matrix with a given state vector. ''' f = error.Formula() beta,a,x,b,alpha = sympy.symbols('beta,a,x,b,alpha') v = Matrix([alpha, beta]) rho = Matrix([[x,a+1j*b],[a-1j*b, 1-x]]) f.formula = (v.conjugate().transpose() * rho * v)[0] f.values[alpha] = statevec[0] f.values[beta] = statevec[1] f.values[a]=float(np.real(dm[0,1])) f.values[x]=float(dm[0,0]) f.values[b]=float(np.imag(dm[0,1])) f.uncertainties[alpha]=ustatevec[0] f.uncertainties[beta]=ustatevec[1] f.uncertainties[x]=u_dm[0,0] f.uncertainties[a]=float(np.real(u_dm[0,1])) f.uncertainties[b]=float(np.imag(u_dm[0,1])) _fid,_ufid = f.num_eval() fid = float(_fid.as_real_imag()[0]) ufid = float(_ufid.as_real_imag()[0]) return (fid,ufid)
def as_density_matrix(self): """ NOT USED ANYMORE (but works fine) Represent this pure state as density matrix. """ coeffs = self.get_coefficients_as_general_state() matrix = Matrix(coeffs) matrix = matrix * matrix.conjugate().transpose() coeff_comm = self.coeff_comm matrix = matrix * coeff_comm * coeff_comm return matrix