def Unitary2Chi(U, B = None): """ map unitary process U onto the according chi matrix option: provide an orthogonal basis B instead of the standard Pauli basis for the chi matrix """ NumberOfQubits = int(np.log2(U.shape[0])) chidim = 4**NumberOfQubits a = proctom.getopbase() A = a for k in xrange(NumberOfQubits-1): A = proctom.baseappend(A,a) lam = np.zeros(chidim, dtype=complex) for k in xrange(chidim): lam[k] = np.trace(np.dot(A[k].transpose().conjugate(),U))/2**NumberOfQubits chi = np.zeros((chidim,chidim), dtype=complex) for k in xrange(chidim): for l in xrange(chidim): chi[k,l]=lam[k]*lam[l].conjugate() return chi
def Unitary2Chi(U, B=None): """ map unitary process U onto the according chi matrix option: provide an orthogonal basis B instead of the standard Pauli basis for the chi matrix """ NumberOfQubits = int(np.log2(U.shape[0])) chidim = 4**NumberOfQubits a = proctom.getopbase() A = a for k in xrange(NumberOfQubits - 1): A = proctom.baseappend(A, a) lam = np.zeros(chidim, dtype=complex) for k in xrange(chidim): lam[k] = np.trace(np.dot(A[k].transpose().conjugate(), U)) / 2**NumberOfQubits chi = np.zeros((chidim, chidim), dtype=complex) for k in xrange(chidim): for l in xrange(chidim): chi[k, l] = lam[k] * lam[l].conjugate() return chi
import time import scipy.optimize as optimize import proctom expm = lnlg.expm from math import pi X = np.array([[0,1],[1,0]]) Y = np.array([[0,-1j],[1j,0]]) Z = np.array([[1,0],[0,-1]]) Id = np.array([[1,0],[0,1]]) #Paulis=[Id, X, Y, Z] Paulis = proctom.getopbase() # added 2010-07-26 by TM: to solve operator definition hickups def findoptimizedrot(ideal_chi, my_chi, return_chi=False, use_random=True, verbose = True): """Finds single qubit operations that maximize the overlap between an experimental chi matrix and an ideal chi matrix""" try: if ideal_chi.shape != my_chi.shape: raise RuntimeError("Matrices don't have the same dimensions") except AttributeError: my_chi = my_chi.chi nr_of_ions = np.log2(my_chi.shape[0]) / 2 # if nr_of_ions > 1: # raise NotImplementedError("Can only optimize one qubit by now") if use_random: p0 = np.random.random_sample(3*nr_of_ions) else: