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

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

Closed
hpc-dave opened this issue Jul 3, 2024 · 4 comments · Fixed by #2931
Closed
Labels

Comments

@hpc-dave
Copy link
Contributor

hpc-dave commented Jul 3, 2024

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
@hpc-dave hpc-dave added the bug label Jul 3, 2024
@ma-sadeghi
Copy link
Member

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

@hpc-dave
Copy link
Contributor Author

hpc-dave commented Jul 4, 2024

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
Copy link

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

@hpc-dave
Copy link
Contributor Author

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants