Skip to main content

KryPy

Build Status Documentation Status doi Pypi version Pypi downloads

KryPy 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.

Features

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:

  • 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 arguments M, Ml and Mr.
  • 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 argument store_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 argument explicit_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 argument exact_solution=x_exact to the LinearSystem.

Usage

Documentation

The documentation is hosted at krypy.readthedocs.org.

Example

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
import krypy

A = 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 residuals
import matplotlib.pyplot as plt
plt.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 adjust Gmres' parameters such as the residual tolerance.

Help

Help can be optained via Python's builtin help system. For example, you can use the ? in ipython:

from krypy.linsys import Gmres
?Gmres

Installing

pip / PyPi

Simply run pip install krypy.

Ubuntu

There's an Ubuntu PPA with packages for Python 2 and Python 3.

Installing from source

KryPy has the following dependencies:

  • NumPy
  • SciPy

Development

KryPy is currently maintained by André Gaul. Feel free to contact André. Please submit feature requests and bugs as github issues.

KryPy is developed with continuous integration. Current status: Build Status

Distribution

To create a new release

  1. bump the __version__ number,

  2. create a Git tag,

    $ git tag -a v0.3.1
    $ git push --tags
    

    and

  3. upload to PyPi:

    $ make upload
    

License

KryPy is free software licensed under the MIT License.

References

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:

Release files for krypy 2.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for krypy 2.2.0
File Size Uploaded
krypy-2.2.0.tar.gz 48.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for krypy 2.2.0
File Interpreter ABI Platform
krypy-2.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 97.4 kB

Release files / krypy-2.2.0.tar.gz

Download URL krypy-2.2.0.tar.gz
Size 48.0 kB
Tags Source
SHA-256 checksum
How to use checksums
957ae3e0076d73e3ca7c23dcc375b0485b3ff71127673be2160c5f560b9c2925
BLAKE2b-256 checksum
How to use checksums
7ff040ddca159f312b86435c4d96469844d5b0228fff5b8839c00829317465f3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.4.2 requests/2.21.0 setuptools/41.1.0 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.7.5

Release files / krypy-2.2.0-py3-none-any.whl

Download URL krypy-2.2.0-py3-none-any.whl
Size 49.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0aad87bced5afb1d2035920fae733b4858917d5254d4f67c4cf488290ac5a8cc
BLAKE2b-256 checksum
How to use checksums
db94e99d97e309ea1ca94d9271529f2ba5366c7c7aa935f3c016599df101ca52
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.4.2 requests/2.21.0 setuptools/41.1.0 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.7.5

Release history Release notifications | RSS feed

This release

2.2.0 This release

2 release files

2.1.7

1 release file

2.1.6

1 release file

2.1.5

1 release file

2.1.4

1 release file

2.1.3

1 release file

2.1.2

1 release file

2.1.1

1 release file

2.1.0

1 release file

2.0.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page