Krylov subspace methods for linear systems
KryPy is a Python (versions 2 and 3) module for Krylov subspace methods for the solution of linear algebraic systems. This includes enhanced versions of CG, MINRES and GMRES as well as methods for the efficient solution of sequences of linear systems.
KryPy gives you an easy-to-use yet flexible interface to Krylov subspace methods for linear algebraic systems. Compared to the implementations in SciPy (or MATLAB), KryPy allows you to supply additional arguments that may help you to tune the solver for the specific problem you want to solve. The additional arguments may also be of interest if you are doing research on Krylov subspace methods.
Some features of KryPy are:
The documentation is hosted at krypy.readthedocs.org.
The above convergence history is obtained with the following example where the Gmres method is used to solve the linear system A*x=b with the diagonal matrix A=diag(1e-3,2,...,100) and right hand side b=[1,...,1].
import numpy from krypy.linsys import LinearSystem, Gmres # create linear system and solve linear_system = LinearSystem(A=numpy.diag([1e-3]+range(2, 101)), b=numpy.ones((100, 1))) sol = Gmres(linear_system) # plot residuals from matplotlib import pyplot pyplot.semilogy(sol.resnorms) pyplot.show()
Of course, this is just a toy example where you would not use GMRES in practice. KryPy can handle arbitrary large matrices - as long as the (hopefully sparse) matrices and the generated basis of the Krylov subspace fit into your memory. ;) Furthermore, in actual applications, you definitely want to adjust Gmres’ parameters such as the residual tolerance.
Help can be optained via Python’s builtin help system. For example, you can use the ? in ipython:
from krypy.linsys import Gmres ?Gmres
Simply run pip install krypy.
There’s an Ubuntu PPA with packages for Python 2 and Python 3.
KryPy has the following dependencies: * NumPy * SciPy
KryPy is currently maintained by André Gaul. Feel free to contact André. Please submit feature requests and bugs as github issues.
To create a new release
bump the __version__ number,
create a Git tag,
$ git tag -a v0.3.1 $ git push --tags
upload to PyPi:
$ make upload
KryPy is free software licensed under the MIT License.
KryPy evolved from the PyNosh package (Python framework for nonlinear Schrödinger equations; joint work with Nico Schlömer) which was used for experiments in the following publication: * Preconditioned Recycling Krylov subspace methods for self-adjoint problems, A. Gaul and N. Schlömer, arxiv: 1208.0264, 2012