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

Fix tol option deprecation in scipy solvers #568

Merged
merged 1 commit into from
May 22, 2024
Merged
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
26 changes: 23 additions & 3 deletions smt/utils/linear_solvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,24 +264,44 @@ def _setup(self, mtx, printer, mg_matrices=[]):
self.callback_func = self.callback._print_sol
self.solver_kwargs = {
"atol": 0.0,
"tol": self.options["atol"],
"rtol": self.options["atol"],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@relf : Is there a typo here? You're assigning a absolute tolerance to a relative tolerance.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in commit 0605476. Forgot this one, thanks! (I think we never use/change these options at all in SMT)

"maxiter": self.options["ilimit"],
}
elif self.options["solver"] == "bicgstab":
self.solver = scipy.sparse.linalg.bicgstab
self.callback_func = self.callback._print_sol
self.solver_kwargs = {
"tol": self.options["atol"],
"rtol": self.options["rtol"],
"maxiter": self.options["ilimit"],
}
elif self.options["solver"] == "gmres":
self.solver = scipy.sparse.linalg.gmres
self.callback_func = self.callback._print_res
self.solver_kwargs = {
"tol": self.options["atol"],
"rtol": self.options["rtol"],
"maxiter": self.options["ilimit"],
"restart": min(self.options["ilimit"], mtx.shape[0]),
}
self._patch_when_scipy_lessthan_v111()

def _patch_when_scipy_lessthan_v111(self):
"""
From scipy 1.11.0 release notes
The tol argument of scipy.sparse.linalg.{bcg,bicstab,cg,cgs,gcrotmk,gmres,lgmres,minres,qmr,tfqmr}
is now deprecated in favour of rtol and will be removed in SciPy 1.14.
Furthermore, the default value of atol for these functions is due to change to 0.0 in SciPy 1.14.
"""
import scipy

scipy_version = scipy.__version__
version_tuple = tuple(map(int, scipy_version.split(".")))
is_greater_than_1_11 = version_tuple[0] > 1 or (
version_tuple[0] == 1 and version_tuple[1] >= 11
)

if not is_greater_than_1_11:
self.solver_kwargs["tol"] = self.solver_kwargs["rtol"]
del self.solver_kwargs["rtol"]

def _solve(self, rhs, sol=None, ind_y=0):
with self._active(self.options["print_solve"]) as printer:
Expand Down