A Julia package collecting a number of Krylov-based algorithms for linear problems, singular value and eigenvalue problems and the application of functions of linear maps or operators to vectors.
KrylovKit.jl accepts general functions or callable objects as linear maps, and general Julia objects with vector like behavior (see below) as vectors.
The high level interface of KrylovKit is provided by the following functions:
linsolve: solve linear systems
A*x = b
eigsolve: find a few eigenvalues and corresponding eigenvectors of an eigenvalue problem
A*x = λ x
geneigsolve: find a few eigenvalues and corresponding vectors of a generalized eigenvalue problem
A*x = λ*B*x
svdsolve: find a few singular values and corresponding left and right singular vectors
A*x = σ * yand
A'*y = σ*x.
exponentiate: apply the exponential of a linear map to a vector
expintegrator: exponential integrator for a linear non-homogeneous ODE, generalization of
This section could also be titled "Why did I create KrylovKit.jl"?
There are already a fair number of packages with Krylov-based or other iterative methods, such as
- IterativeSolvers.jl: part of the JuliaMath organisation, solves linear systems and least square problems, eigenvalue and singular value problems
- Krylov.jl: part of the JuliaSmoothOptimizers organisation, solves linear systems and least square problems, specific for linear operators from LinearOperators.jl.
- KrylovMethods.jl: specific for sparse matrices
- Expokit.jl: application of the matrix exponential to a vector
- ArnoldiMethod.jl: Implicitly restarted Arnoldi method for eigenvalues of a general matrix
- JacobiDavidson.jl: Jacobi-Davidson method for eigenvalues of a general matrix
- ExponentialUtilities.jl: Krylov subspace methods for matrix exponentials and
phivexponential integrator products. It has specialized methods for subspace caching, time stepping, and error testing which are essential for use in high order exponential integrators.
- OrdinaryDiffEq.jl: contains implementations of high order exponential integrators with adaptive Krylov-subspace calculations for solving semilinear and nonlinear ODEs.
These packages have certainly inspired and influenced the development of KrylovKit.jl. However, KrylovKit.jl distinguishes itself from the previous packages in the following ways:
KrylovKit accepts general functions to represent the linear map or operator that defines the problem, without having to wrap them in a
LinearOperatortype. Of course, subtypes of
AbstractMatrixare also supported. If the linear map (always the first argument) is a subtype of
AbstractMatrix, matrix vector multiplication is used, otherwise it is applied as a function call.
KrylovKit does not assume that the vectors involved in the problem are actual subtypes of
AbstractVector. Any Julia object that behaves as a vector is supported, so in particular higher-dimensional arrays or any custom user type that supports the following functions (with
wtwo instances of this type and
α, βscalars (i.e.
Base.:*(α, v): multiply
vwith a scalar
α, which can be of a different scalar type; in particular this method is used to create vectors similar to
vbut with a different type of underlying scalars.
Base.similar(v): a way to construct vectors which are exactly similar to
LinearAlgebra.mul!(w, v, α): out of place scalar multiplication; multiply vector
αand store the result in
LinearAlgebra.rmul!(v, α): in-place scalar multiplication of
α; in particular with
α = false,
vis the corresponding zero vector
LinearAlgebra.axpy!(α, v, w): store in
wthe result of
α*v + w
LinearAlgebra.axpby!(α, v, β, w): store in
wthe result of
α*v + β*w
LinearAlgebra.dot(v,w): compute the inner product of two vectors
LinearAlgebra.norm(v): compute the 2-norm of a vector
Algorithms in KrylovKit.jl are tested against such a minimal implementation (named
MinimalVec) in the test suite. This type is only defined in the tests. However, KrylovKit provides two types implementing this interface and slightly more, to make them behave more like
Base.:+etc), which can facilitate certain applications:
RecursiveVeccan be used for grouping a set of vectors into a single vector like structure (can be used recursively). This is more robust than trying to use nested
InnerProductVeccan be used to redefine the inner product (i.e.
dot) and corresponding norm (
norm) of an already existing vector like object. The latter should help with implementing certain type of preconditioners.
The following algorithms are currently implemented
eigsolve: a Krylov-Schur algorithm (i.e. with tick restarts) for extremal eigenvalues of normal (i.e. not generalized) eigenvalue problems, corresponding to
Lanczosfor real symmetric or complex hermitian linear maps, and to
Arnoldifor general linear maps.
geneigsolve: an customized implementation of the inverse-free algorithm of Golub and Ye for symmetric / hermitian generalized eigenvalue problems with positive definite matrix
Bin the right hand side of the generalized eigenvalue problem $A v = B v λ$. The Matlab implementation was described by Money and Ye and is known as
EIGIFP; in particular it extends the Krylov subspace with a vector corresponding to the step between the current and previous estimate, analogous to the locally optimal preconditioned conjugate gradient method (LOPCG). In particular, with Krylov dimension 2, it becomes equivalent to the latter.
svdsolve: finding largest singular values based on Golub-Kahan-Lanczos bidiagonalization (see
Lanczosbased algorithm for the action of the exponential of a real symmetric or complex hermitian linear map.
expintegrator: exponential integrator for a linear non-homogeneous ODE, computes a linear combination of the
ϕⱼfunctions which generalize
ϕ₀(z) = exp(z).
Here follows a wish list / to-do list for the future. Any help is welcomed and appreciated.
- More algorithms, including biorthogonal methods:
linsolve: MINRES, BiCG, BiCGStab(l), IDR(s), ...
eigsolve: BiLanczos, Jacobi-Davidson JDQR/JDQZ, subspace iteration (?), ...
geneigsolve: trace minimization, ...
- Support both in-place / mutating and out-of-place functions as linear maps
- Reuse memory for storing vectors when restarting algorithms (related to previous)
- Support non-BLAS scalar types using GeneralLinearAlgebra.jl and GeneralSchur.jl
- Least square problems
- Nonlinear eigenvalue problems
- Refined Ritz vectors, Harmonic Ritz values and vectors
- Block versions of the algorithms
- More relevant matrix functions
- Improved efficiency for the specific case where
Vector(i.e. BLAS level 2 operations): any vector
IndexStyle(v) == IndexLinear()now benefits from a multithreaded (use
export JULIA_NUM_THREADS = xwith
xthe number of threads you want to use) implementation that resembles BLAS level 2 style for the vector operations, provided
ClassicalGramSchmidtIR()is chosen as orthogonalization routine.