Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove pypardiso as a hard dependency for arm64 support #2835

Merged
merged 3 commits into from
Oct 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ jobs:
pip install \
-r requirements.txt \
-r requirements/tests.txt
pip install pypardiso

- name: Running tests
run:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/gh-pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ jobs:
run: |
pip install -r requirements.txt
pip install -r requirements/docs.txt
pip install pypardiso

- name: Build the documentation
run: |
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ jobs:
-r requirements.txt \
-r requirements/tests.txt

- name: Install pypardiso on non-macOS
if: (matrix.os != 'macos-latest')
run: |
pip install pypardiso

- name: Running tests
run:
pytest . --color=yes
5 changes: 5 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ jobs:
-r requirements.txt \
-r requirements/tests.txt

- name: Install pypardiso on non-macOS
if: (matrix.os != 'macos-latest')
run: |
pip install pypardiso

- name: Disable numba JIT for codecov to include jitted methods
if: (matrix.python-version == 3.9) && (matrix.os == 'ubuntu-latest')
run: |
Expand Down
43 changes: 26 additions & 17 deletions openpnm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,34 @@

"""

from . import _skgraph
from . import utils
from . import core
from . import models
from . import topotools
from . import network
from . import phase
from . import algorithms
from . import solvers
from . import integrators
from . import io
from . import contrib
from . import visualization

from .utils import Workspace, Project
import logging

from rich.logging import RichHandler

FORMAT = "%(message)s"
logging.basicConfig(
format=FORMAT, datefmt="[%X]", handlers=[RichHandler(rich_tracebacks=True)]
)

import numpy as _np

from . import (
_skgraph,
algorithms,
contrib,
core,
integrators,
io,
models,
network,
phase,
solvers,
topotools,
utils,
visualization,
)
from .utils import Project, Workspace

_np.seterr(divide='ignore', invalid='ignore')

__version__ = utils._get_version()

utils._setup_logger_rich()
6 changes: 4 additions & 2 deletions openpnm/solvers/_pardiso.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from pypardiso import spsolve
from scipy.sparse import csc_matrix, csr_matrix

from openpnm.solvers import DirectSolver
from scipy.sparse import csr_matrix, csc_matrix

__all__ = ['PardisoSpsolve']

Expand All @@ -10,6 +10,8 @@ class PardisoSpsolve(DirectSolver):

def solve(self, A, b, **kwargs):
"""Solves the given linear system of equations Ax=b."""
from pypardiso import spsolve

if not isinstance(A, (csr_matrix, csc_matrix)):
A = A.tocsr()
return (spsolve(A, b), 0)
16 changes: 15 additions & 1 deletion openpnm/utils/_workspace.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import logging
import pickle
import re
import sys
from datetime import datetime
from uuid import uuid4

Expand Down Expand Up @@ -39,7 +40,20 @@ class WorkspaceSettings(SettingsAttr):
may be unable to continue running.
======= ==============================================================
"""
default_solver = 'PardisoSpsolve'
# Pardiso requires MKL, which is not available on new Apple chips
if sys.platform == 'darwin':
default_solver = 'ScipySpsolve'
else:
try:
import pypardiso
default_solver = 'PardisoSpsolve'
except ImportError:
default_solver = 'ScipySpsolve'
msg = (
'PARDISO solver not installed, run `pip install pypardiso`. '
'Otherwise, simulations will be slow. Apple M chips not supported.'
)
logger.error(msg)

@property
def loglevel(self):
Expand Down
8 changes: 4 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import os
import sys
import codecs
import os
import os.path
import sys
from distutils.util import convert_path
from setuptools import setup, find_packages

from setuptools import find_packages, setup

sys.path.append(os.getcwd())
ver_path = convert_path('openpnm/__version__.py')
Expand Down Expand Up @@ -59,7 +60,6 @@ def get_version(rel_path):
'numpy',
'pandas',
'pyamg',
'pypardiso',
'rich',
'scikit-image',
'scipy',
Expand Down
5 changes: 5 additions & 0 deletions tests/unit/algorithms/SolversTest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import sys

import numpy as np
import numpy.testing as nt
import pytest

import openpnm as op


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

@pytest.mark.skipif(sys.platform == 'darwin', reason="Pardiso not available on arm64")
def test_pardiso_spsolve(self):
solver = op.solvers.PardisoSpsolve()
self.alg.run(solver=solver)
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/algorithms/TransientMultiPhysicsTest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import numpy as np
import numpy.testing as nt

import openpnm as op
import openpnm.models.geometry.diffusive_size_factors as gd
import openpnm.models.physics as pm
Expand Down Expand Up @@ -48,7 +49,6 @@ def setup_class(self):
"cache_A": False,
"cache_b": False
}
self.pardiso = op.solvers.PardisoSpsolve()
self.rk45 = op.integrators.ScipyRK45(verbose=True)

# First algorithm, transient fourier conduction
Expand Down