def liouvillian_fast(H, c_op_list): """Assembles the Liouvillian superoperator from a Hamiltonian and a ``list`` of collapse operators. Like liouvillian, but with an experimental implementation which avoids creating extra Qobj instances, which can be advantageous for large systems. Parameters ---------- H : qobj System Hamiltonian. c_op_list : array_like A ``list`` or ``array`` of collpase operators. Returns ------- L : qobj Louvillian superoperator. .. note:: Experimental. """ d = H.dims[1] L = Qobj() L.dims = [[H.dims[0][:], d[:]], [H.dims[1][:], d[:]]] L.shape = [prod(L.dims[0][0]) * prod(L.dims[0][1]), prod(L.dims[1][0]) * prod(L.dims[1][1])] L.data = -1j * ( sp.kron(sp.identity(prod(d)), H.data, format="csr") - sp.kron(H.data.T, sp.identity(prod(d)), format="csr") ) n_op = len(c_op_list) for m in range(0, n_op): L.data = L.data + sp.kron(sp.identity(prod(d)), c_op_list[m].data, format="csr") * sp.kron( c_op_list[m].data.T.conj().T, sp.identity(prod(d)), format="csr" ) cdc = c_op_list[m].data.T.conj() * c_op_list[m].data L.data = L.data - 0.5 * sp.kron(sp.identity(prod(d)), cdc, format="csr") L.data = L.data - 0.5 * sp.kron(cdc.T, sp.identity(prod(d)), format="csr") return L
def spre(A): """Superoperator formed from pre-multiplication by operator A. Parameters ---------- A : qobj Quantum operator for pre-multiplication. Returns -------- super :qobj Superoperator formed from input quantum object. """ if not isoper(A): raise TypeError("Input is not a quantum object") d = A.dims[1] S = Qobj() S.dims = [[A.dims[0][:], d[:]], [A.dims[1][:], d[:]]] S.shape = [prod(S.dims[0][0]) * prod(S.dims[0][1]), prod(S.dims[1][0]) * prod(S.dims[1][1])] S.data = sp.kron(sp.identity(prod(d)), A.data, format="csr") return S
def spost(A): """Superoperator formed from post-multiplication by operator A Parameters ---------- A : qobj Quantum operator for post multiplication. Returns ------- super : qobj Superoperator formed from input qauntum object. """ if not isoper(A): raise TypeError('Input is not a quantum object') d=A.dims[0] S=Qobj() S.dims=[[d[:],A.dims[1][:]],[d[:],A.dims[0][:]]] S.shape=[prod(S.dims[0][0])*prod(S.dims[0][1]),prod(S.dims[1][0])*prod(S.dims[1][1])] S.data=sp.kron(A.data.T,sp.identity(prod(d))) return Qobj(S)
def spre(A): """Superoperator formed from pre-multiplication by operator A. Parameters ---------- A : qobj Quantum operator for pre-multiplication. Returns -------- super :qobj Superoperator formed from input quantum object. """ if not isoper(A): raise TypeError('Input is not a quantum object') d=A.dims[1] S=Qobj() S.dims=[[A.dims[0][:],d[:]],[A.dims[1][:],d[:]]] S.shape=[prod(S.dims[0][0])*prod(S.dims[0][1]),prod(S.dims[1][0])*prod(S.dims[1][1])] S.data=sp.kron(sp.identity(prod(d)),A.data,format='csr') return S
def liouvillian_fast(H, c_op_list): """Assembles the Liouvillian superoperator from a Hamiltonian and a ``list`` of collapse operators. Like liouvillian, but with an experimental implementation which avoids creating extra Qobj instances, which can be advantageous for large systems. Parameters ---------- H : qobj System Hamiltonian. c_op_list : array_like A ``list`` or ``array`` of collpase operators. Returns ------- L : qobj Louvillian superoperator. .. note:: Experimental. """ d=H.dims[1] L=Qobj() L.dims=[[H.dims[0][:],d[:]],[H.dims[1][:],d[:]]] L.shape=[prod(L.dims[0][0])*prod(L.dims[0][1]),prod(L.dims[1][0])*prod(L.dims[1][1])] L.data = -1j *(sp.kron(sp.identity(prod(d)), H.data,format='csr') - sp.kron(H.data.T,sp.identity(prod(d)),format='csr')) n_op = len(c_op_list) for m in range(0, n_op): L.data = L.data + sp.kron(sp.identity(prod(d)), c_op_list[m].data,format='csr') * sp.kron(c_op_list[m].data.T.conj().T,sp.identity(prod(d)),format='csr') cdc = c_op_list[m].data.T.conj()*c_op_list[m].data L.data = L.data - 0.5 * sp.kron(sp.identity(prod(d)), cdc,format='csr') L.data = L.data - 0.5 * sp.kron(cdc.T,sp.identity(prod(d)),format='csr') return L
def steady(L,maxiter=100,tol=1e-6,method='solve'): """Steady state for the evolution subject to the supplied Louvillian. Parameters ---------- L : qobj Liouvillian superoperator. maxiter : int Maximum number of iterations to perform, default = 100. tol : float Tolerance used by iterative solver, default = 1e-6. method : str Method for solving linear equations. Direct solver 'solve' (default) or iterative biconjugate gradient method 'bicg'. Returns -------- ket : qobj Ket vector for steady state. Notes ----- Uses the inverse power method. See any Linear Algebra book with an iterative methods section. """ eps=finfo(float).eps if (not isoper(L)) & (not issuper(L)): raise TypeError('Steady states can only be found for operators or superoperators.') rhoss=Qobj() sflag=issuper(L) if sflag: rhoss.dims=L.dims[0] rhoss.shape=[prod(rhoss.dims[0]),prod(rhoss.dims[1])] else: rhoss.dims=[L.dims[0],1] rhoss.shape=[prod(rhoss.dims[0]),1] n=prod(rhoss.shape) L1=L.data+eps*_sp_inf_norm(L)*sp.eye(n,n,format='csr') v=randn(n,1) it=0 while (la.norm(L.data*v,np.inf)>tol) and (it<maxiter): if method=='bicg': v,check=bicg(L1,v,tol=tol) else: v=spsolve(L1,v,use_umfpack=False) v=v/la.norm(v,np.inf) it+=1 if it>=maxiter: raise ValueError('Failed to find steady state after ' + str(maxiter) +' iterations') #normalise according to type of problem if sflag: trow=sp.eye(rhoss.shape[0],rhoss.shape[0],format='lil') trow=trow.reshape((1,n)).tocsr() data=v/sum(trow.dot(v)) else: data=data/la.norm(v) data=reshape(data,(rhoss.shape[0],rhoss.shape[1])).T data=sp.csr_matrix(data) rhoss.data=0.5*(data+data.conj().T) #data=sp.triu(data,format='csr')#take only upper triangle #rhoss.data=0.5*sp.eye(rhoss.shape[0],rhoss.shape[1],format='csr')*(data+data.conj().T) #output should be hermitian, but not guarenteed using iterative meth if qset.auto_tidyup: return Qobj(rhoss).tidyup() else: return Qobj(rhoss)
def steady(L, maxiter=100, tol=1e-6, method='solve'): """Steady state for the evolution subject to the supplied Louvillian. Parameters ---------- L : qobj Liouvillian superoperator. maxiter : int Maximum number of iterations to perform, default = 100. tol : float Tolerance used by iterative solver, default = 1e-6. method : str Method for solving linear equations. Direct solver 'solve' (default) or iterative biconjugate gradient method 'bicg'. Returns -------- ket : qobj Ket vector for steady state. Notes ----- Uses the inverse power method. See any Linear Algebra book with an iterative methods section. """ eps = finfo(float).eps if (not isoper(L)) & (not issuper(L)): raise TypeError( 'Steady states can only be found for operators or superoperators.') rhoss = Qobj() sflag = issuper(L) if sflag: rhoss.dims = L.dims[0] rhoss.shape = [prod(rhoss.dims[0]), prod(rhoss.dims[1])] else: rhoss.dims = [L.dims[0], 1] rhoss.shape = [prod(rhoss.dims[0]), 1] n = prod(rhoss.shape) L1 = L.data + eps * sp_inf_norm(L) * sp.eye(n, n, format='csr') v = randn(n, 1) it = 0 while (la.norm(L.data * v, inf) > tol) and (it < maxiter): if method == 'bicg': v, check = bicg(L1, v, tol=tol) else: v = spsolve(L1, v, use_umfpack=False) v = v / la.norm(v, inf) it += 1 if it >= maxiter: raise ValueError('Failed to find steady state after ' + str(maxiter) + ' iterations') #normalise according to type of problem if sflag: trow = sp.eye(rhoss.shape[0], rhoss.shape[0], format='lil') trow = trow.reshape((1, n)).tocsr() data = v / sum(trow.dot(v)) else: data = data / la.norm(v) data = reshape(data, (rhoss.shape[0], rhoss.shape[1])).T data = sp.csr_matrix(data) rhoss.data = 0.5 * (data + data.conj().T) #data=sp.triu(data,format='csr')#take only upper triangle #rhoss.data=0.5*sp.eye(rhoss.shape[0],rhoss.shape[1],format='csr')*(data+data.conj().T) #output should be hermitian, but not guarenteed using iterative meth if qset.auto_tidyup: return Qobj(rhoss).tidyup() else: return Qobj(rhoss)