Skip to content

Commit 3257b0e

Browse files
committed
Remove pypardiso as a hard dependency
1 parent 3aca748 commit 3257b0e

File tree

10 files changed

+64
-26
lines changed

10 files changed

+64
-26
lines changed

.github/workflows/examples.yml

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ jobs:
3636
pip install \
3737
-r requirements.txt \
3838
-r requirements/tests.txt
39+
pip install pypardiso
3940
4041
- name: Running tests
4142
run:

.github/workflows/gh-pages.yml

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ jobs:
3636
run: |
3737
pip install -r requirements.txt
3838
pip install -r requirements/docs.txt
39+
pip install pypardiso
3940
4041
- name: Build the documentation
4142
run: |

.github/workflows/nightly.yml

+5
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ jobs:
4949
-r requirements.txt \
5050
-r requirements/tests.txt
5151
52+
- name: Install pypardiso on non-macOS
53+
if: (matrix.os != 'macos-latest')
54+
run: |
55+
pip install pypardiso
56+
5257
- name: Running tests
5358
run:
5459
pytest . --color=yes

.github/workflows/tests.yml

+5
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ jobs:
4646
-r requirements.txt \
4747
-r requirements/tests.txt
4848
49+
- name: Install pypardiso on non-macOS
50+
if: (matrix.os != 'macos-latest')
51+
run: |
52+
pip install pypardiso
53+
4954
- name: Disable numba JIT for codecov to include jitted methods
5055
if: (matrix.python-version == 3.9) && (matrix.os == 'ubuntu-latest')
5156
run: |

openpnm/__init__.py

+26-17
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,34 @@
88
99
"""
1010

11-
from . import _skgraph
12-
from . import utils
13-
from . import core
14-
from . import models
15-
from . import topotools
16-
from . import network
17-
from . import phase
18-
from . import algorithms
19-
from . import solvers
20-
from . import integrators
21-
from . import io
22-
from . import contrib
23-
from . import visualization
24-
25-
from .utils import Workspace, Project
11+
import logging
12+
13+
from rich.logging import RichHandler
14+
15+
FORMAT = "%(message)s"
16+
logging.basicConfig(
17+
format=FORMAT, datefmt="[%X]", handlers=[RichHandler(rich_tracebacks=True)]
18+
)
2619

2720
import numpy as _np
21+
22+
from . import (
23+
_skgraph,
24+
algorithms,
25+
contrib,
26+
core,
27+
integrators,
28+
io,
29+
models,
30+
network,
31+
phase,
32+
solvers,
33+
topotools,
34+
utils,
35+
visualization,
36+
)
37+
from .utils import Project, Workspace
38+
2839
_np.seterr(divide='ignore', invalid='ignore')
2940

3041
__version__ = utils._get_version()
31-
32-
utils._setup_logger_rich()

openpnm/solvers/_pardiso.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1-
from pypardiso import spsolve
1+
from scipy.sparse import csc_matrix, csr_matrix
2+
23
from openpnm.solvers import DirectSolver
3-
from scipy.sparse import csr_matrix, csc_matrix
44

55
__all__ = ['PardisoSpsolve']
66

77

88
class PardisoSpsolve(DirectSolver):
99
"""Solves a linear system using ``pypardiso.spsolve``."""
10-
10+
1111
def solve(self, A, b, **kwargs):
1212
"""Solves the given linear system of equations Ax=b."""
13+
from pypardiso import spsolve
14+
1315
if not isinstance(A, (csr_matrix, csc_matrix)):
1416
A = A.tocsr()
1517
return (spsolve(A, b), 0)

openpnm/utils/_workspace.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import logging
22
import pickle
33
import re
4+
import sys
45
from datetime import datetime
56
from uuid import uuid4
67

@@ -39,7 +40,16 @@ class WorkspaceSettings(SettingsAttr):
3940
may be unable to continue running.
4041
======= ==============================================================
4142
"""
42-
default_solver = 'PardisoSpsolve'
43+
# Pardiso requires MKL, which is not available on new Apple chips
44+
if sys.platform == 'darwin':
45+
default_solver = 'ScipySpsolve'
46+
else:
47+
try:
48+
import pypardiso
49+
default_solver = 'PardisoSpsolve'
50+
except ImportError:
51+
default_solver = 'ScipySpsolve'
52+
logger.error('Pardiso not installed, run `pip install pypardiso`')
4353

4454
@property
4555
def loglevel(self):

setup.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import os
2-
import sys
31
import codecs
2+
import os
43
import os.path
4+
import sys
55
from distutils.util import convert_path
6-
from setuptools import setup, find_packages
6+
7+
from setuptools import find_packages, setup
78

89
sys.path.append(os.getcwd())
910
ver_path = convert_path('openpnm/__version__.py')
@@ -59,7 +60,6 @@ def get_version(rel_path):
5960
'numpy',
6061
'pandas',
6162
'pyamg',
62-
'pypardiso',
6363
'rich',
6464
'scikit-image',
6565
'scipy',

tests/unit/algorithms/SolversTest.py

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1+
import sys
2+
13
import numpy as np
24
import numpy.testing as nt
5+
import pytest
6+
37
import openpnm as op
48

59

@@ -25,6 +29,7 @@ def test_scipy_spsolve(self):
2529
x = self.alg['pore.x']
2630
nt.assert_allclose(x.mean(), 0.624134, rtol=1e-5)
2731

32+
@pytest.mark.skipif(sys.platform == 'darwin', reason="Pardiso not available on arm64")
2833
def test_pardiso_spsolve(self):
2934
solver = op.solvers.PardisoSpsolve()
3035
self.alg.run(solver=solver)

tests/unit/algorithms/TransientMultiPhysicsTest.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import numpy as np
22
import numpy.testing as nt
3+
34
import openpnm as op
45
import openpnm.models.geometry.diffusive_size_factors as gd
56
import openpnm.models.physics as pm
@@ -48,7 +49,6 @@ def setup_class(self):
4849
"cache_A": False,
4950
"cache_b": False
5051
}
51-
self.pardiso = op.solvers.PardisoSpsolve()
5252
self.rk45 = op.integrators.ScipyRK45(verbose=True)
5353

5454
# First algorithm, transient fourier conduction

0 commit comments

Comments
 (0)