Skip to content

BUG: LinearSolver convergence failures discard results #4143

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

Open
jrmaddison opened this issue Mar 21, 2025 · 2 comments · May be fixed by #4144
Open

BUG: LinearSolver convergence failures discard results #4143

jrmaddison opened this issue Mar 21, 2025 · 2 comments · May be fixed by #4144
Assignees
Labels

Comments

@jrmaddison
Copy link
Contributor

jrmaddison commented Mar 21, 2025

Describe the bug
If a linear solver failure is encountered and a firedrake.exceptions.ConvergenceError is raised, the solution value is unchanged.

Steps to Reproduce

from firedrake import *
import petsc4py.PETSc as PETSc

mesh = UnitIntervalMesh(10)
space = FunctionSpace(mesh, "CG", 1)
test, trial = TestFunction(space), TrialFunction(space)

solver = LinearSolver(assemble(inner(trial, test) * dx),
                      solver_parameters={"ksp_type": "cg",
                                         "pc_type": "none",
                                         "ksp_max_it": 1,
                                         "ksp_atol": 1.0e-2})
b = assemble(inner(Constant(1), test) * dx)

u = Function(space, name="u")

u.assign(-1)
try:
  solver.solve(u, b)
except firedrake.exceptions.ConvergenceError:
    assert solver.ksp.getConvergedReason() == PETSc.KSP.ConvergedReason.DIVERGED_MAX_IT
    print("ConvergenceError")
print(u.dat.data_ro)

displays

ConvergenceError
[-1. -1. -1. -1. -1. -1. -1. -1. -1. -1. -1.]

Expected behavior
The solution should be updated to the state obtained from the linear solve -- in the above after 1 CG iteration.

Additional Info
I think the behaviour changed in #4012

@jrmaddison jrmaddison added the bug label Mar 21, 2025
@jrmaddison jrmaddison changed the title BUG: LinearSolver convergence failures discards results BUG: LinearSolver convergence failures discard results Mar 21, 2025
@pbrubeck pbrubeck self-assigned this Mar 21, 2025
@pbrubeck
Copy link
Contributor

Oh, I see the issue. The ConvergenceError prevents the copy of the internal solution vector to the one provided as argument.

@pbrubeck pbrubeck linked a pull request Mar 21, 2025 that will close this issue
@jrmaddison
Copy link
Contributor Author

There's maybe a question whether this should update the result. I have one unit test which was relying on this behaviour, but I think a custom KSP convergence test can be used instead.

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.

2 participants