Skip to content

Commit

Permalink
Fix conceptual error in GMRES tolerance specification
Browse files Browse the repository at this point in the history
The relative tolerance for convergence was being set to a fraction
of the rhs norm, but the `tol` option is already a relative
tolerance.

This commit also fies a depracation warning, since the `tol`
parameter is deprecated in facor of `rtol`.
  • Loading branch information
btalamini committed Feb 27, 2024
1 parent 21b5f72 commit 6025ebd
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions optimism/NewtonSolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ def newton_step(residual, linear_op, x, settings=Settings(1e-2,100), precond=Non
# it is allowed to modify the output in place.
A = LinearOperator((sz,sz),
lambda v: onp.array(linear_op(v)))
r = residual(x)
rNorm = np.linalg.norm(r)
r = onp.array(residual(x))

numIters = 0
def callback(xk):
Expand All @@ -52,7 +51,7 @@ def callback(xk):
else:
M = None

dx, exitcode = gmres(A, onp.array(r), tol=relTol*rNorm, atol=0, M=M, callback_type='legacy', callback=callback, maxiter=maxIters)
dx, exitcode = gmres(A, r, rtol=relTol, atol=0, M=M, callback_type='legacy', callback=callback, maxiter=maxIters)
print('Number of GMRES iters = ', numIters)

return -dx, exitcode
Expand Down

0 comments on commit 6025ebd

Please sign in to comment.