quimb.linalg.slepc_linalg ========================= .. py:module:: quimb.linalg.slepc_linalg .. autoapi-nested-parse:: Interface to slepc4py for solving advanced eigenvalue problems. Attributes ---------- .. autoapisummary:: quimb.linalg.slepc_linalg._petsc_slepc_handler quimb.linalg.slepc_linalg._WHICH_SCIPY_TO_SLEPC Classes ------- .. autoapisummary:: quimb.linalg.slepc_linalg._PetscSlepcHandler quimb.linalg.slepc_linalg.PetscLinearOperatorContext Functions --------- .. autoapisummary:: quimb.linalg.slepc_linalg.get_default_comm quimb.linalg.slepc_linalg.get_petsc quimb.linalg.slepc_linalg.get_slepc quimb.linalg.slepc_linalg.linear_operator_2_petsc_shell quimb.linalg.slepc_linalg.slice_sparse_matrix_to_components quimb.linalg.slepc_linalg.convert_mat_to_petsc quimb.linalg.slepc_linalg.convert_vec_to_petsc quimb.linalg.slepc_linalg.new_petsc_vec quimb.linalg.slepc_linalg.gather_petsc_array quimb.linalg.slepc_linalg.normalize_real_part quimb.linalg.slepc_linalg._init_krylov_subspace quimb.linalg.slepc_linalg._init_spectral_inverter quimb.linalg.slepc_linalg._which_scipy_to_slepc quimb.linalg.slepc_linalg._init_eigensolver quimb.linalg.slepc_linalg.eigs_slepc quimb.linalg.slepc_linalg._init_svd_solver quimb.linalg.slepc_linalg.svds_slepc quimb.linalg.slepc_linalg.mfn_multiply_slepc quimb.linalg.slepc_linalg.lookup_ksp_error quimb.linalg.slepc_linalg.ssolve_slepc Module Contents --------------- .. py:function:: get_default_comm() Define the default communicator. .. py:class:: _PetscSlepcHandler Helper class for caching the PETSc and SLEPc imports and making sure that the MPI comm they use is aligned. .. py:attribute:: _comm :value: '__UNINITIALIZED__' .. py:method:: init_petsc_slepc(comm) .. py:method:: get_petsc(comm=None) .. py:method:: get_slepc(comm=None) .. py:data:: _petsc_slepc_handler .. py:function:: get_petsc(comm=None) .. py:function:: get_slepc(comm=None) .. py:class:: PetscLinearOperatorContext(lo) .. py:attribute:: lo .. py:attribute:: real .. py:method:: mult(_, xvec, yvec) .. py:method:: multHermitian(_, xvec, yvec) .. py:function:: linear_operator_2_petsc_shell(lo, comm=None) .. py:function:: slice_sparse_matrix_to_components(mat, ri, rf) Slice the matrix `mat` between indices `ri` and `rf` -- for csr or bsr. .. py:function:: convert_mat_to_petsc(mat, comm=None) Convert a matrix to the relevant PETSc type, currently only supports csr, bsr and dense matrices formats. :param mat: The operator to convert. :type mat: dense, sparse, LinearOperator or Lazy matrix. :param comm: The mpi communicator. :type comm: mpi4py.MPI.Comm instance :returns: **pmat** -- The matrix in petsc form - only the local part if running across several mpi processes. :rtype: petsc4py.PETSc.Mat .. py:function:: convert_vec_to_petsc(vec, comm=None) Convert a vector/array to the PETSc form. :param vec: Numpy array, will be unravelled to one dimension. :type vec: vector-like :param comm: The mpi communicator. :type comm: mpi4py.MPI.Comm instance :returns: **pvec** -- The vector in petsc form - only the local part if running across several mpi processes. :rtype: petsc4py.PETSc.Vec .. py:function:: new_petsc_vec(d, comm=None) Create an empty petsc vector of size `d`. :param d: Dimension of vector, i.e. the global size. :type d: int :param comm: The mpi communicator. :type comm: mpi4py.MPI.Comm instance :returns: **pvec** -- An empty vector in petsc form - only the local part if running across several mpi processes. :rtype: petsc4py.PETSc.Vec .. py:function:: gather_petsc_array(x, comm, out_shape=None) Gather the petsc vector/matrix `x` to a single array on the master process, assuming that owernership is sliced along the first dimension. :param x: Distributed petsc array to gather. :type x: petsc4py.PETSc Mat or Vec :param comm: MPI communicator :type comm: mpi4py.MPI.COMM :param out_shape: If not None, reshape the output array to this. :type out_shape: tuple, optional :returns: **gathered** :rtype: np.array master, None on workers (rank > 0) .. py:function:: normalize_real_part(vecs, transposed=False) Take the real part of a set of vectors and normalize it. This is used for returning real eigenvectors even when the PETSc scalar type is complex. .. py:function:: _init_krylov_subspace(comm=None, tol=None, maxiter=None, KSPType='preonly', PCType='lu', PCFactorSolverType='mumps') Initialise a krylov subspace and preconditioner. .. py:function:: _init_spectral_inverter(STType='sinvert', KSPType='preonly', PCType='lu', PCFactorSolverType='mumps', comm=None) Create a slepc spectral transformation object with specified solver. .. py:data:: _WHICH_SCIPY_TO_SLEPC .. py:function:: _which_scipy_to_slepc(which) .. py:function:: _init_eigensolver(k=6, which='LM', sigma=None, isherm=True, isgen=False, EPSType=None, st_opts=None, tol=None, A_is_linop=False, B_is_linop=False, maxiter=None, ncv=None, l_win=None, comm=None) Create an advanced eigensystem solver :param sigma: Target eigenvalue. :param isherm: Whether problem is hermitian or not. :rtype: SLEPc solver ready to be called. .. py:function:: eigs_slepc(A, k, *, B=None, which=None, sigma=None, isherm=True, P=None, v0=None, ncv=None, return_vecs=True, sort=True, EPSType=None, return_all_conv=False, st_opts=None, tol=None, maxiter=None, l_win=None, comm=None) Solve a matrix using the advanced eigensystem solver :param A: Operator to solve. :type A: dense-matrix, sparse-matrix, LinearOperator or callable :param k: Number of requested eigenpairs. :type k: int, optional :param B: The RHS operator defining a generalized eigenproblem. :type B: dense-matrix, sparse-matrix, LinearOperator or callable :param which: Which eigenpairs to target. See :func:`scipy.sparse.linalg.eigs`. :type which: {"LM": "SM", "LR", "LA", "SR", "SA", "LI", "SI", "TM", "TR", "TI"} :param sigma: Target eigenvalue, implies ``which='TR'`` if this is not set but ``sigma`` is. :type sigma: float, optional :param isherm: Whether problem is hermitian or not. :type isherm: bool, optional :param P: Perform the eigensolve in the subspace defined by this projector. :type P: dense-matrix, sparse-matrix, LinearOperator or callable :param v0: Initial iteration vector, e.g., informed guess at eigenvector. :type v0: 1D-array like, optional :param ncv: Subspace size, defaults to ``min(20, 2 * k)``. :type ncv: int, optional :param return_vecs: Whether to return the eigenvectors. :type return_vecs: bool, optional :param sort: Whether to sort the eigenpairs in ascending real value. :type sort: bool, optional :param EPSType: SLEPc eigensolver type to use, see slepc4py.EPSType. :type EPSType: {"krylovschur", 'gd', 'lobpcg', 'jd', 'ciss'}, optional :param return_all_conv: Whether to return converged eigenpairs beyond requested subspace size :type return_all_conv: bool, optional :param st_opts: options to send to the eigensolver internal inverter. :type st_opts: dict, optional :param tol: Tolerance. :type tol: float, optional :param maxiter: Maximum number of iterations. :type maxiter: int, optional :param comm: MPI communicator, defaults to ``COMM_SELF`` for a single process solve. :type comm: mpi4py communicator, optional :returns: * **lk** (*(k,) array*) -- The eigenvalues. * **vk** (*(m, k) array*) -- Corresponding eigenvectors (if ``return_vecs=True``). .. py:function:: _init_svd_solver(nsv=6, SVDType='cross', tol=None, maxiter=None, ncv=None, comm=None) .. py:function:: svds_slepc(A, k=6, ncv=None, return_vecs=True, SVDType='cross', return_all_conv=False, tol=None, maxiter=None, comm=None) Find the singular values for sparse matrix `a`. :param A: The matrix to solve. :type A: sparse matrix in csr format :param k: Number of requested singular values. :type k: int :param method: Solver method to use. :type method: {"cross", "cyclic", "lanczos", "trlanczos"} :returns: * **U** (*(m, k) array*) -- Left singular vectors (if ``return_vecs=True``) as columns. * **s** (*(k,) array*) -- Singular values. * **VH** (*(k, n) array*) -- Right singular vectors (if ``return_vecs=True``) as rows. .. py:function:: mfn_multiply_slepc(mat, vec, fntype='exp', MFNType='AUTO', comm=None, isherm=False) Compute the action of ``func(mat) @ vec``. :param mat: Operator to compute function action of. :type mat: operator :param vec: Vector to compute matrix function action on. :type vec: vector-like :param func: Function to use. :type func: {'exp', 'sqrt', 'log'}, optional :param MFNType: Method of computing the matrix function action, 'expokit' is only available for func='exp'. :type MFNType: {'krylov', 'expokit'}, optional :param comm: The mpi communicator. :type comm: mpi4py.MPI.Comm instance, optional :param isherm: If `mat` is known to be hermitian, this might speed things up in some circumstances. :type isherm: bool, optional :returns: **fvec** -- The vector output of ``func(mat) @ vec``. :rtype: array .. py:function:: lookup_ksp_error(i) Look up PETSc error to print when raising after not converging. .. py:function:: ssolve_slepc(A, y, isherm=True, comm=None, maxiter=None, tol=None, KSPType='preonly', PCType='lu', PCFactorSolverType='mumps')