Skip to content
Snippets Groups Projects
README.md 2.05 KiB
Newer Older
Joseph Weston's avatar
Joseph Weston committed

Anton Akhmerov's avatar
Anton Akhmerov committed
Python bindings for the [MUMPS](http://mumps-solver.org/): a parallel sparse direct solver.
Joseph Weston's avatar
Joseph Weston committed

Anton Akhmerov's avatar
Anton Akhmerov committed
## Scope

This package targets MUMPS packaged by conda-forge using Cython bindings. It
aims to provide a full wrapper of the MUMPS sequential API. Its primary target
OS is Linux.

Next steps include:

- Support for Windows and OSX
- Support for distributed (MPI) MUMPS

Anton Akhmerov's avatar
Anton Akhmerov committed
## Installation
Bas Nijholt's avatar
Bas Nijholt committed

`python-mumps` works with Python 3.10 and higher on Linux, Windows and Mac.
Bas Nijholt's avatar
Bas Nijholt committed

The recommended way to install `python-mumps` is using `mamba`/`conda`.
Anton Akhmerov's avatar
Anton Akhmerov committed

Joseph Weston's avatar
Joseph Weston committed
```bash
mamba install -c conda-forge python-mumps
Bas Nijholt's avatar
Bas Nijholt committed
```

`python-mumps` can also be installed from PyPI, however this is a more involved procedure
Joseph Weston's avatar
Joseph Weston committed
that requires separately installing the MUMPS library and a C compiler.

Anton Akhmerov's avatar
Anton Akhmerov committed
## Usage example
Joseph Weston's avatar
Joseph Weston committed

The following example shows how Python-MUMPS can be used to implement sparse diagonalization
Joseph Weston's avatar
Joseph Weston committed
with Scipy.

Bas Nijholt's avatar
Bas Nijholt committed
```python
import scipy.sparse.linalg as sla
from scipy.sparse import identity
Bas Nijholt's avatar
Bas Nijholt committed


def sparse_diag(matrix, k, sigma, **kwargs):
    """Call sla.eigsh with mumps support.

Joseph Weston's avatar
Joseph Weston committed
    See scipy.sparse.linalg.eigsh for documentation.
Bas Nijholt's avatar
Bas Nijholt committed
    """
    class LuInv(sla.LinearOperator):
        def __init__(self, A):
Bas Nijholt's avatar
Bas Nijholt committed
            inst.analyze(A, ordering='pord')
            inst.factor(A)
            self.solve = inst.solve
            sla.LinearOperator.__init__(self, A.dtype, A.shape)

        def _matvec(self, x):
            return self.solve(x.astype(self.dtype))

    opinv = LuInv(matrix - sigma * identity(matrix.shape[0]))
    return sla.eigsh(matrix, k, sigma=sigma, OPinv=opinv, **kwargs)
```
Anton Akhmerov's avatar
Anton Akhmerov committed

## Development

Anton Akhmerov's avatar
Anton Akhmerov committed
### Pixi

`python-mumps` recommends [pixi](https://pixi.sh/).

After installing pixi, use

```bash
pixi run test -v  # (Pytest arguments go after test)
```

This will also install the necessary dependencies.

### pre-commit

`python-mumps` uses [pre-commit](https://pre-commit.com/) to enforce code style. After installing it, run
Anton Akhmerov's avatar
Anton Akhmerov committed

```bash
Anton Akhmerov's avatar
Anton Akhmerov committed
pre-commit install
Anton Akhmerov's avatar
Anton Akhmerov committed
or if you want to use pre-commit provided by pixi, run
Anton Akhmerov's avatar
Anton Akhmerov committed

```bash
Anton Akhmerov's avatar
Anton Akhmerov committed
pixi run pre-commit install
Anton Akhmerov's avatar
Anton Akhmerov committed
```