Package: krypy
KryPyKryPy is a Python 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.FeaturesKryPy gives you an easy-to-use yet flexible interface to Krylov subspace methods for linear algebraic systems. Compared to the implementations inSciPy(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:User-defined inner products- useful when solving a linear algebraic system whose operator is self-adjoined in a non-Euclidean inner-product. This way, CG or MINRES can be applied to self-adjoined (but non-symmetric/non-Hermitian) operators easily.Full control of preconditioners- the order of applying preconditioners matters. This is why you can supply two left preconditioners (one of whom implicitly changes the inner product and thus has to be positive definite) and one right preconditioner. Take a look at the argumentsM,MlandMr.Get the Arnoldi/Lanczos basis and Hessenberg matrix- you want to extract further information from the generated vectors (e.g. recycling)? Just pass the optional argumentstore_arnoldi=True.Explicitly computed residuals on demand- if you do research on Krylov subspace methods or preconditioners, then you sometimes want to know the explicitly computed residual in each iteration (in contrast to an updated residual which can be obtained implicitly). Then you should pass the optional argumentexplicit_residual=True.Compute errors- if you have (for research purposes) the exact solution at hand and want to monitor the error in each iteration instead of the residual, you can supply the optional argumentexact_solution=x_exactto theLinearSystem.UsageDocumentationThe documentation is hosted atkrypy.readthedocs.org.ExampleThe above convergence history is obtained with the following example where theGmresmethod is used to solve the linear systemA*x=bwith the diagonal matrixA=diag(1e-3,2,...,100)and right hand sideb=[1,...,1].importnumpyimportkrypyA=numpy.diag([1.0e-3]+list(range(2,101)))b=numpy.ones(100)# sol, out = krypy.cg(A, b)# sol, out = krypy.minres(A, b)sol,out=krypy.gmres(A,b)# sol is None if no solution has been found# out.resnorms the relative residual norms and some more data# plot residualsimportmatplotlib.pyplotaspltplt.semilogy(out.resnorms)plt.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 adjustGmres'
parameters such as the residual tolerance.HelpHelp can be optained via Python's builtin help system. For example, you can use
the?inipython:fromkrypy.linsysimportGmres?GmresInstallingpip / PyPiSimply runpip install krypy.UbuntuThere's anUbuntu PPAwith packages for Python 2 and Python 3.Installing from sourceKryPy has the following dependencies:NumPySciPyDevelopmentKryPy is currently maintained byAndré Gaul. Feel free to contact André. Please submit feature requests and bugs as github issues.KryPy is developed with continuous integration. Current status:DistributionTo create a new releasebump the__version__number,create a Git tag,$ git tag -a v0.3.1
$ git push --tagsandupload to PyPi:$ make uploadLicenseKryPy is free software licensed under theMIT License.ReferencesKryPy evolved from thePyNoshpackage (Python framework for nonlinear Schrödinger equations; joint work withNico 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