Skip to content

Commit

Permalink
Merge pull request #49 from simpeg/pyproject_update
Browse files Browse the repository at this point in the history
Switch to pyproject.toml based install
  • Loading branch information
jcapriot authored Oct 11, 2024
2 parents 3297054 + 9d9b60f commit 32ade92
Show file tree
Hide file tree
Showing 23 changed files with 245 additions and 197 deletions.
3 changes: 0 additions & 3 deletions .bumpversion.cfg

This file was deleted.

9 changes: 0 additions & 9 deletions .coveragerc

This file was deleted.

4 changes: 4 additions & 0 deletions .git_archival.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node: $Format:%H$
node-date: $Format:%cI$
describe-name: $Format:%(describe:tags=true,match=*[0-9]*)$
ref-names: $Format:%D$
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.git_archival.txt export-subst
33 changes: 22 additions & 11 deletions .github/workflows/python-package-conda.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,17 @@ jobs:
run: |
make coverage
- name: Generate Source Distribution
if: ${{ (matrix.os == 'ubuntu-latest') && (matrix.python-version == '3.11') }}
run: |
pip install build twine
python -m build --sdist .
twine check dist/*
- name: Test Documentation
if: ${{ (matrix.os == 'ubuntu-latest') && (matrix.python-version == '3.11') }}
run: |
pip install -r requirements_docs.txt
pip install .[docs]
cd docs
make html
cd ..
Expand All @@ -79,38 +86,41 @@ jobs:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

distribute:
name: Distributing from 3.8
name: Distributing
needs: build-and-test
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
runs-on: ubuntu-latest
defaults:
run:
shell: bash -l {0}
env:
PYTHON_VERSION: '3.11'

steps:
- uses: actions/checkout@v4
- name: Setup Conda
uses: conda-incubator/setup-miniconda@v3
with:
auto-update-conda: true
activate-environment: dev
python-version: 3.8
channels: conda-forge
python-version: ${{ env.PYTHON_VERSION }}

- name: Install Env
- name: Install Base Env
run: |
conda info
conda list
conda config --show
conda install --quiet --yes -c conda-forge pip numpy scipy pydiso
pip install -r requirements_docs.txt
conda install --quiet --yes pip numpy scipy
- name: Install Our Package
run: |
pip install -v -e .
pip install -v -e .[docs]
- name: Generate Source Distribution
run: |
python setup.py sdist
pip install build twine
python -m build --sdist .
twine check dist/*
- name: Build Documentation
run: |
Expand All @@ -119,15 +129,16 @@ jobs:
cd ..
- name: GitHub Pages
uses: crazy-max/ghaction-github-pages@v2.5.0
uses: crazy-max/ghaction-github-pages@v4
with:
build_dir: docs/_build/html
jekyll: false
keep_history: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: pypi-publish
uses: pypa/gh-action-pypi-publish@v1.4.2
uses: pypa/gh-action-pypi-publish@v1
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.coverage
coverage.xml
coverage_html_report/
*.pyc
*.so
build/
Expand Down
5 changes: 5 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
prune .github
prune docs
prune tests
exclude .gitignore MANIFEST.in .pre-commit-config.yaml
exclude .git_archival.txt .gitattributes Makefile
23 changes: 3 additions & 20 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,28 +1,11 @@
.PHONY: build coverage lint graphs tests docs mumps mumps_mac mumps_install_mac

build:
python setup.py build_ext --inplace
.PHONY: coverage tests docs

coverage:
pytest --cov-config=.coveragerc --cov-report=xml --cov=pymatsolver -s -v

lint:
pylint --output-format=html pymatsolver > pylint.html

graphs:
pyreverse -my -A -o pdf -p pymatsolver pymatsolver/**.py pymatsolver/**/**.py
pytest --cov --cov-config=pyproject.toml -s -v
coverage xml

tests:
pytest

docs:
cd docs;make html

mumps:
cd pymatsolver/mumps;make build

mumps_mac:
cd pymatsolver/mumps;make build_mac

mumps_install_mac:
brew install mumps --with-scotch5 --without-mpi
68 changes: 21 additions & 47 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pymatsolver
:target: https://github.com/simpeg/pymatsolver/blob/master/LICENSE
:alt: MIT license.

.. image:: https://codecov.io/gh/simpeg/pymatsolver/branch/master/graph/badge.svg
.. image:: https://codecov.io/gh/simpeg/pymatsolver/branch/main/graph/badge.svg?token=8uQoxzxf3r
:target: https://codecov.io/gh/simpeg/pymatsolver
:alt: Coverage status

Expand All @@ -32,68 +32,42 @@ All solvers work with :code:`scipy.sparse` matricies, and a single or multiple r

* L/U Triangular Solves
* Wrapping of SciPy matrix solvers (direct and indirect)
* Pardiso solvers now that MKL comes with conda!
* Mumps solver with nice error messages
* Pardiso solvers
* Mumps solvers


Installing Mumps
================
Installing Solvers
==================
Often, there are faster solvers available for your system than the default scipy factorizations available.
pymatsolver provides a consistent interface to both MKL's ``Pardiso`` routines and the ``MUMPS`` solver package. To
make use of these we use intermediate wrappers for the libraries that must be installed separately.

We have not been able to get the pip install to work because of multiple dependencies on fortran libraries.
However, the linux and mac installs are relatively easy. Note that you must have mumps pre-installed,
currently we have only got this working for the sequential version, so when you are installing,
you will need to point to that one. You can also look at the `.travis.yml` file for how to get it working on TravisCI.
Pardiso
-------
The Pardiso interface is recommended for Intel processor based systems. The interface is enabled by
the ``pydiso`` python package, which can be installed through conda-forge as:

Linux
-----

From a clean install on Ubuntu:

.. code-block:: bash
apt-get update
apt-get -y install gcc gfortran git libopenmpi-dev libmumps-seq-dev libblas-dev liblapack-dev
# Install all the python you need!
wget http://repo.continuum.io/miniconda/Miniconda-3.8.3-Linux-x86_64.sh -O miniconda.sh;
chmod +x miniconda.sh
./miniconda.sh -b
export PATH=/root/anaconda/bin:/root/miniconda/bin:$PATH
conda update --yes conda
conda install --yes numpy scipy matplotlib cython ipython pytest coverage
git clone https://github.com/rowanc1/pymatsolver.git
cd pymatsolver
make mumps
.. code::
Mac
---
conda install -c conda-forge pydiso
This assumes that you have Brew and some python installed (numpy, scipy):

.. code-block:: bash
brew install mumps --with-scotch5 --without-mpi
git clone https://github.com/rowanc1/pymatsolver.git
cd pymatsolver
make mumps_mac
If you have problems you may have to go into the Makefile and update the pointers to Lib and Include for the various libraries.
Mumps
-----
Mumps is available for all platforms. The mumps interface is enabled by installing the ``python-mumps``
wrapper package. This can easily be installed through conda-forge with:

This command is helpful for finding dependencies. You should also take note of have happens when brew installs mumps.
.. code::
.. code-block:: bash
conda install -c conda-forge python-mumps
mpicc --showme
Code:
https://github.com/simpeg/pymatsolver


Tests:
https://travis-ci.org/simpeg/pymatsolver
https://github.com/simpeg/pymatsolver/actions


Bugs & Issues:
Expand Down
58 changes: 35 additions & 23 deletions pymatsolver/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,6 @@
Mumps
"""

SolverHelp = {}
AvailableSolvers = {
"Diagonal": True,
"Solver": True,
"SolverLU": True,
"SolverCG": True,
"Triangle": True,
"Pardiso": False,
"Mumps": False
}

# Simple solvers
from .solvers import Diagonal, Triangle, Forward, Backward
from .wrappers import wrap_direct, WrapDirect
Expand All @@ -71,35 +60,58 @@
from .iterative import BiCGJacobi

# Scipy direct solvers
from .direct import Solver
from .direct import Solver, pardiso
from .direct import SolverLU

from .solvers import PymatsolverAccuracyError
from .solvers import SolverAccuracyError
from .direct import Pardiso, Mumps
from .direct.pardiso import _available as _pardiso_available
from .direct.mumps import _available as _mumps_available

SolverHelp = {}
AvailableSolvers = {
"Diagonal": True,
"Solver": True,
"SolverLU": True,
"SolverCG": True,
"Triangle": True,
"Pardiso": _pardiso_available,
"Mumps": _mumps_available,
}

BicgJacobi = BiCGJacobi # backwards compatibility
PardisoSolver = Pardiso # backwards compatibility

try:
from .direct import Pardiso
AvailableSolvers['Pardiso'] = True
PardisoSolver = Pardiso # backwards compatibility
except ImportError:
if not AvailableSolvers["Pardiso"]:
SolverHelp['Pardiso'] = """Pardiso is not working
Ensure that you have pydiso installed, which may also require Python
to be installed through conda.
"""

try:
from .direct import Mumps
AvailableSolvers['Mumps'] = True
except ImportError:
if not AvailableSolvers["Mumps"]:
SolverHelp['Mumps'] = """Mumps is not working.
Ensure that you have python-mumps installed, which may also require Python
to be installed through conda.
"""

__version__ = '0.2.0'
__author__ = 'SimPEG Team'
__license__ = 'MIT'
__copyright__ = '2013 - 2024, SimPEG Team, https://simpeg.xyz'

from importlib.metadata import version, PackageNotFoundError

# Version
try:
# - Released versions just tags: 0.8.0
# - GitHub commits add .dev#+hash: 0.8.1.dev4+g2785721
# - Uncommitted changes add timestamp: 0.8.1.dev4+g2785721.d20191022
__version__ = version("pymatsolver")
except PackageNotFoundError:
# If it was not installed, then we don't know the version. We could throw a
# warning here, but this case *should* be rare. discretize should be
# installed properly!
from datetime import datetime

__version__ = "unknown-" + datetime.today().strftime("%Y%m%d")
18 changes: 5 additions & 13 deletions pymatsolver/direct/__init__.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
from ..wrappers import WrapDirect
from scipy.sparse.linalg import spsolve, splu

from ..wrappers import WrapDirect
from .pardiso import Pardiso
from .mumps import Mumps

Solver = WrapDirect(spsolve, factorize=False, name="Solver")
SolverLU = WrapDirect(splu, factorize=True, name="SolverLU")

__all__ = ["Solver", "SolverLU"]
try:
from .pardiso import Pardiso
__all__ += ["Pardiso"]
except ImportError:
pass

try:
from .mumps import Mumps
__all__ += ["Mumps"]
except ImportError:
pass
__all__ = ["Solver", "SolverLU", "Pardiso", "Mumps"]
11 changes: 10 additions & 1 deletion pymatsolver/direct/mumps.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
from pymatsolver.solvers import Base
from mumps import Context
try:
from mumps import Context
_available = True
except ImportError:
Context = None
_available = False

class Mumps(Base):
"""The MUMPS direct solver.
Expand Down Expand Up @@ -33,6 +38,10 @@ class Mumps(Base):
_transposed = False

def __init__(self, A, ordering=None, is_symmetric=None, is_positive_definite=False, check_accuracy=False, check_rtol=1e-6, check_atol=0, accuracy_tol=None, **kwargs):
if not _available:
raise ImportError(
"The Mumps solver requires the python-mumps package to be installed."
)
is_hermitian = kwargs.pop('is_hermitian', False)
super().__init__(A, is_symmetric=is_symmetric, is_positive_definite=is_positive_definite, is_hermitian=is_hermitian, check_accuracy=check_accuracy, check_rtol=check_rtol, check_atol=check_atol, accuracy_tol=accuracy_tol, **kwargs)
if ordering is None:
Expand Down
Loading

0 comments on commit 32ade92

Please sign in to comment.