def _steadystate_svd_dense(L, ss_args): """ Find the steady state(s) of an open quantum system by solving for the nullspace of the Liouvillian. """ ss_args['info'].pop('weight', None) atol = 1e-12 rtol = 1e-12 if settings.debug: logger.debug('Starting SVD solver.') _svd_start = time.time() u, s, vh = svd(L.full(), full_matrices=False) tol = max(atol, rtol * s[0]) nnz = (s >= tol).sum() ns = vh[nnz:].conj().T _svd_end = time.time() ss_args['info']['solution_time'] = _svd_end - _svd_start if ss_args['all_states']: rhoss_list = [] for n in range(ns.shape[1]): rhoss = Qobj(vec2mat(ns[:, n]), dims=L.dims[0]) rhoss_list.append(rhoss / rhoss.tr()) if ss_args['return_info']: return rhoss_list, ss_args['info'] else: if ss_args['return_info']: return rhoss_list, ss_args['info'] else: return rhoss_list else: rhoss = Qobj(vec2mat(ns[:, 0]), dims=L.dims[0]) return rhoss / rhoss.tr()
def _steadystate_svd_dense(L, atol=1e-12, rtol=0, all_steadystates=False, verbose=False): """ Find the steady state(s) of an open quantum system by solving for the nullspace of the Liouvillian. """ if verbose: print('Starting SVD solver...') start_time = time.time() u, s, vh = svd(L.full(), full_matrices=False) tol = max(atol, rtol * s[0]) nnz = (s >= tol).sum() ns = vh[nnz:].conj().T if verbose: print('SVD solver time: ', time.time() - start_time) if all_steadystates: rhoss_list = [] for n in range(ns.shape[1]): rhoss = Qobj(vec2mat(ns[:, n]), dims=L.dims[0]) rhoss_list.append(rhoss / rhoss.tr()) return rhoss_list else: rhoss = Qobj(vec2mat(ns[:, 0]), dims=L.dims[0]) return rhoss / rhoss.tr()
def _steadystate_svd_dense(L, ss_args): """ Find the steady state(s) of an open quantum system by solving for the nullspace of the Liouvillian. """ ss_args['info'].pop('weight', None) atol = 1e-12 rtol = 1e-12 if settings.debug: logger.debug('Starting SVD solver.') _svd_start = time.time() u, s, vh = svd(L.full(), full_matrices=False) tol = max(atol, rtol * s[0]) nnz = (s >= tol).sum() ns = vh[nnz:].conj().T _svd_end = time.time() ss_args['info']['solution_time'] = _svd_end-_svd_start if ss_args['all_states']: rhoss_list = [] for n in range(ns.shape[1]): rhoss = Qobj(vec2mat(ns[:, n]), dims=L.dims[0]) rhoss_list.append(rhoss / rhoss.tr()) if ss_args['return_info']: return rhoss_list, ss_args['info'] else: if ss_args['return_info']: return rhoss_list, ss_args['info'] else: return rhoss_list else: rhoss = Qobj(vec2mat(ns[:, 0]), dims=L.dims[0]) return rhoss / rhoss.tr()
def _steadystate_svd_dense(L, ss_args): """ Find the steady state(s) of an open quantum system by solving for the nullspace of the Liouvillian. """ atol = 1e-12 rtol = 1e-12 if settings.debug: print('Starting SVD solver...') u, s, vh = svd(L.full(), full_matrices=False) tol = max(atol, rtol * s[0]) nnz = (s >= tol).sum() ns = vh[nnz:].conj().T if ss_args['all_states']: rhoss_list = [] for n in range(ns.shape[1]): rhoss = Qobj(vec2mat(ns[:, n]), dims=L.dims[0]) rhoss_list.append(rhoss / rhoss.tr()) return rhoss_list else: rhoss = Qobj(vec2mat(ns[:, 0]), dims=L.dims[0]) return rhoss / rhoss.tr()
def _steadystate_eigen(L, ss_args): """ Internal function for solving the steady state problem by finding the eigenvector corresponding to the zero eigenvalue of the Liouvillian using ARPACK. """ ss_args['info'].pop('weight', None) if settings.debug: logger.debug('Starting Eigen solver.') dims = L.dims[0] L = L.data.tocsc() if ss_args['use_rcm']: ss_args['info']['perm'].append('rcm') if settings.debug: old_band = sp_bandwidth(L)[0] logger.debug('Original bandwidth: %i' % old_band) perm = sp.csgraph.reverse_cuthill_mckee(L) rev_perm = np.argsort(perm) L = sp_permute(L, perm, perm, 'csc') if settings.debug: rcm_band = sp_bandwidth(L)[0] logger.debug('RCM bandwidth: %i' % rcm_band) logger.debug('Bandwidth reduction factor: %f' % (old_band / rcm_band)) _eigen_start = time.time() eigval, eigvec = eigs(L, k=1, sigma=1e-15, tol=ss_args['tol'], which='LM', maxiter=ss_args['maxiter']) _eigen_end = time.time() ss_args['info']['solution_time'] = _eigen_end - _eigen_start if ss_args['return_info']: ss_args['info']['residual_norm'] = la.norm(L * eigvec, np.inf) if ss_args['use_rcm']: eigvec = eigvec[np.ix_(rev_perm, )] _temp = vec2mat(eigvec) data = dense2D_to_fastcsr_fmode(_temp, _temp.shape[0], _temp.shape[1]) data = 0.5 * (data + data.H) out = Qobj(data, dims=dims, isherm=True) if ss_args['return_info']: return out / out.tr(), ss_args['info'] else: return out / out.tr()
def propagator_steadystate(U): """Find the steady state for successive applications of the propagator :math:`U`. Parameters ---------- U : qobj Operator representing the propagator. Returns ------- a : qobj Instance representing the steady-state density matrix. """ evals, evecs = la.eig(U.full()) ev_min, ev_idx = _get_min_and_index(abs(evals - 1.0)) evecs = evecs.T rho = Qobj(vec2mat(evecs[ev_idx]), dims=U.dims[0]) rho = rho * (1.0 / rho.tr()) rho = 0.5 * (rho + rho.dag()) # make sure rho is herm return rho
def _steadystate_eigen(L, ss_args): """ Internal function for solving the steady state problem by finding the eigenvector corresponding to the zero eigenvalue of the Liouvillian using ARPACK. """ if settings.debug: print('Starting Eigen solver...') dims = L.dims[0] shape = prod(dims[0]) L = L.data.tocsc() if ss_args['use_rcm']: if settings.debug: old_band = sp_bandwidth(L)[0] print('Original bandwidth:', old_band) perm = reverse_cuthill_mckee(L) rev_perm = np.argsort(perm) L = sp_permute(L, perm, perm, 'csc') if settings.debug: rcm_band = sp_bandwidth(L)[0] print('RCM bandwidth:', rcm_band) print('Bandwidth reduction factor:', round(old_band/rcm_band, 1)) eigval, eigvec = eigs(L, k=1, sigma=1e-15, tol=ss_args['tol'], which='LM', maxiter=ss_args['maxiter']) if ss_args['use_rcm']: eigvec = eigvec[np.ix_(rev_perm,)] data = vec2mat(eigvec) data = 0.5 * (data + data.conj().T) out = Qobj(data, dims=dims, isherm=True) return out/out.tr()
def _steadystate_eigen(L, ss_args): """ Internal function for solving the steady state problem by finding the eigenvector corresponding to the zero eigenvalue of the Liouvillian using ARPACK. """ ss_args['info'].pop('weight', None) if settings.debug: print('Starting Eigen solver...') dims = L.dims[0] shape = prod(dims[0]) L = L.data.tocsc() if ss_args['use_rcm']: ss_args['info']['perm'].append('rcm') if settings.debug: old_band = sp_bandwidth(L)[0] print('Original bandwidth:', old_band) perm = reverse_cuthill_mckee(L) rev_perm = np.argsort(perm) L = sp_permute(L, perm, perm, 'csc') if settings.debug: rcm_band = sp_bandwidth(L)[0] print('RCM bandwidth:', rcm_band) print('Bandwidth reduction factor:', round(old_band / rcm_band, 1)) _eigen_start = time.time() eigval, eigvec = eigs(L, k=1, sigma=1e-15, tol=ss_args['tol'], which='LM', maxiter=ss_args['maxiter']) _eigen_end = time.time() ss_args['info']['solution_time'] = _eigen_end - _eigen_start if ss_args['use_rcm']: eigvec = eigvec[np.ix_(rev_perm, )] data = vec2mat(eigvec) data = 0.5 * (data + data.conj().T) out = Qobj(data, dims=dims, isherm=True) if ss_args['return_info']: return out / out.tr(), ss_args['info'] else: return out / out.tr()
def _steadystate_eigen(L, ss_args): """ Internal function for solving the steady state problem by finding the eigenvector corresponding to the zero eigenvalue of the Liouvillian using ARPACK. """ ss_args['info'].pop('weight', None) if settings.debug: logger.debug('Starting Eigen solver.') dims = L.dims[0] L = L.data.tocsc() if ss_args['use_rcm']: ss_args['info']['perm'].append('rcm') if settings.debug: old_band = sp_bandwidth(L)[0] logger.debug('Original bandwidth: %i' % old_band) perm = reverse_cuthill_mckee(L) rev_perm = np.argsort(perm) L = sp_permute(L, perm, perm, 'csc') if settings.debug: rcm_band = sp_bandwidth(L)[0] logger.debug('RCM bandwidth: %i' % rcm_band) logger.debug('Bandwidth reduction factor: %f' % (old_band/rcm_band)) _eigen_start = time.time() eigval, eigvec = eigs(L, k=1, sigma=1e-15, tol=ss_args['tol'], which='LM', maxiter=ss_args['maxiter']) _eigen_end = time.time() ss_args['info']['solution_time'] = _eigen_end - _eigen_start if ss_args['return_info']: ss_args['info']['residual_norm'] = la.norm(L*eigvec, np.inf) if ss_args['use_rcm']: eigvec = eigvec[np.ix_(rev_perm,)] _temp = vec2mat(eigvec) data = dense2D_to_fastcsr_fmode(_temp, _temp.shape[0], _temp.shape[1]) data = 0.5 * (data + data.H) out = Qobj(data, dims=dims, isherm=True) if ss_args['return_info']: return out/out.tr(), ss_args['info'] else: return out/out.tr()
def test_tidyup(): small = Qobj([[1e-2, 0], [0, 1]]) small.tidyup(1e-1) assert small.tr() == 1