PMEAL / OpenPNM

A Python package for performing pore network modeling of porous media
http://openpnm.org
MIT License
454 stars 174 forks source link

from scipy.optimize.nonlin import TerminationCondition invalid with scipy v >= 1.14 #2922

Closed hpc-dave closed 3 months ago

hpc-dave commented 4 months ago

Description With the update to scipy 1.14, the Termination condition is in scipy.optimize.linalg is removed. Subsequently, import of _reactive_transport.py fails, leading to a failure of importing openpnm as is

Reproduction Steps to reproduce the behavior, ideally a code snippet that only reproduces the bug:

import openpnm as op

Expected behavior Should import without error

Quick fix A quick fix for compatibility could be as follows:

# dirty hack for compatibility with scipy 1.14
try:
    from scipy.optimize.nonlin import TerminationCondition
except ImportError:
    class TerminationCondition:
        def __init__(self, f_tol: float, f_rtol: float, x_rtol: float, norm: float):
            self.f_tol = f_tol
            self.f_rtol = f_rtol
            self.x_rtol = x_rtol
            self.norm = norm

        def check(self, f_tol: float, f_rtol: float, x_rtol: float, norm: float) -> bool:
            return f_tol < self.f_tol and f_rtol < self.f_rtol and x_rtol < self.x_rtol and norm < self.norm
ma-sadeghi commented 4 months ago

Thanks for the bug report. Would you be willing to submit a PR with your fix?

hpc-dave commented 4 months ago

Sure! I looked a bit more into it and figured out that a better, yet still not so nice fix means to import from scipy.optimize._nonlin instead. The file still exists, however I do not know for how long. It might be worthwhile to consider a more durable alternative. I submitted PR #2923

AilsaZeng commented 4 months ago

Hi, did you work out how to solve this problem? I still cannot use the import porespy as ps.

hpc-dave commented 4 months ago

I don't think that is related to this issue. Importing porespy works for me with numpy 2.0.0 Maybe you can open another issue in the porespy repository (https://github.com/PMEAL/porespy/issues) and explain your problem in more details there!