# Warning when using NonlinearSolve.jl with LinearSolve.jl and MINRES

**URL:** https://discourse.julialang.org/t/warning-when-using-nonlinearsolve-jl-with-linearsolve-jl-and-minres/119781
**Category:** General Usage
**Tags:** nonlinearsolve
**Created:** [September 24, 2024, 12:44am UTC](https://discourse.julialang.org/t/warning-when-using-nonlinearsolve-jl-with-linearsolve-jl-and-minres/119781 "2024-09-24T00:44:23Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![mpf01](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mpf01/32/8221_2.png) [@mpf01](https://discourse.julialang.org/u/mpf01)
#### Post date: [September 24, 2024, 12:44am UTC](https://discourse.julialang.org/t/warning-when-using-nonlinearsolve-jl-with-linearsolve-jl-and-minres/119781/1 "2024-09-24T00:44:23Z")

</div>

I am experimenting with [NonlinearSolve.jl](https://docs.sciml.ai/NonlinearSolve/stable/) to solve a nonlinear system of equations with a symmetric indefinite Jacobian. I am specifically interested in using MINRES to solve this system. In my code, I’ve not specified any preconditioner, yet I’m receiving the warning:

```julia
┌ Warning: minres! doesn't support right preconditioning.
└ @ LinearSolve ~/.julia/packages/LinearSolve/B82H3/src/iterative_wrappers.jl:275

```

The documentation for NonlinearSolve.jl suggests that [no preconditioner is the default](https://docs.sciml.ai/NonlinearSolve/stable/native/solvers/#General-Keyword-Arguments). Here is a minimal working example that triggers the warning:

```julia
using NonlinearSolve
using LinearSolve

# Yes, this is a linear system...
function f(du, u, p)
    du[1] = u[1] - 1
    du[2] = -u[2] + 1
end

function jvp(Jv, v, u, p)
    Jv .= [v[1]; -v[2]]
end

u0 = [0.0, 0.0]
p = nothing

ff = NonlinearFunction(f; jvp=jvp)
prob = NonlinearProblem(ff, u0, p)
sol = solve(prob, NewtonRaphson(linsolve = KrylovJL_MINRES()))

```

Why I am getting this warning even though I have not explicitly installed a preconditioner?

Thank you!

---

<div class="post-metadata">

### Author: ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)
#### Post date: [September 24, 2024, 9:21am UTC](https://discourse.julialang.org/t/warning-when-using-nonlinearsolve-jl-with-linearsolve-jl-and-minres/119781/2 "2024-09-24T09:21:31Z")

</div>

@Oscar_Smith is this from the latest changes?

---

<div class="post-metadata">

### Author: ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)
#### Post date: [September 24, 2024, 1:58pm UTC](https://discourse.julialang.org/t/warning-when-using-nonlinearsolve-jl-with-linearsolve-jl-and-minres/119781/3 "2024-09-24T13:58:13Z")

</div>

Yes. Will fix. It’s still getting the right answer, but the warning shouldn’t be triggering.

---

<div class="post-metadata">

### Author: ![mpf01](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mpf01/32/8221_2.png) [@mpf01](https://discourse.julialang.org/u/mpf01)
#### Post date: [September 24, 2024, 8:02pm UTC](https://discourse.julialang.org/t/warning-when-using-nonlinearsolve-jl-with-linearsolve-jl-and-minres/119781/4 "2024-09-24T20:02:15Z")

</div>

Thanks for confirming that the warning is spurious.

Looking into the code, I see that NonlineearSolve.jl uses the internal function [`__wrapprecs`](https://github.com/SciML/NonlinearSolve.jl/blob/e457a984e6d2b9e27580322cb7a2a2288119773e/src/internal/linear_solve.jl#L245), which is called by [`LinearSolverCache`](https://gitkraken.dev/link/dnNjb2RlOi8vZWFtb2Rpby5naXRsZW5zL2xpbmsvci9lZThmYjMyN2ZhMzA4YmI2ZWY2MmMwMjlmNmIzYWRkMzg3MjAzMTczL2Yvc3JjL2ludGVybmFsL2xpbmVhcl9zb2x2ZS5qbD91cmw9Z2l0JTQwZ2l0aHViLmNvbSUzQVNjaU1MJTJGTm9ubGluZWFyU29sdmUuamwuZ2l0JmxpbmVzPTcx?origin=gitlens) and installs default explicit identity preconditioners. Although these identity preconditioners mathematically provide no preconditioning, they inadvertently cause MINRES to incur [additional overhead](https://github.com/JuliaSmoothOptimizers/Krylov.jl/blob/main/src/minres.jl#L171). Would it be feasible to redefine these identity preconditioners as type `UniformScaling`, which does not result in this overhead?

In the meantime, instead of globally disabling all warnings, is there a way to call `solve` that would execute the following [line of code](https://github.com/SciML/NonlinearSolve.jl/blob/e457a984e6d2b9e27580322cb7a2a2288119773e/src/internal/linear_solve.jl#L88)?

```julia
        precs, Pl_, Pr_ = nothing, nothing, nothing

```

Would that solve the problem?

Thanks again!

---

<div class="post-metadata">

### Author: ![mpf01](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mpf01/32/8221_2.png) [@mpf01](https://discourse.julialang.org/u/mpf01)
#### Post date: [September 24, 2024, 8:04pm UTC](https://discourse.julialang.org/t/warning-when-using-nonlinearsolve-jl-with-linearsolve-jl-and-minres/119781/5 "2024-09-24T20:04:07Z")

</div>

I’m using NonlinearSolve.jl v3.14.0.

---

<div class="post-metadata">

### Author: ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)
#### Post date: [September 24, 2024, 9:26pm UTC](https://discourse.julialang.org/t/warning-when-using-nonlinearsolve-jl-with-linearsolve-jl-and-minres/119781/6 "2024-09-24T21:26:51Z")

</div>

> [@mpf01](#):
>
> Looking into the code, I see that [NonlineearSolve.jl](https://juliahub.com/ui/Packages/General/NonlineearSolve) uses the internal function [`__wrapprecs`](https://github.com/SciML/NonlinearSolve.jl/blob/e457a984e6d2b9e27580322cb7a2a2288119773e/src/internal/linear_solve.jl#L245), which is called by [`LinearSolverCache`](https://gitkraken.dev/link/dnNjb2RlOi8vZWFtb2Rpby5naXRsZW5zL2xpbmsvci9lZThmYjMyN2ZhMzA4YmI2ZWY2MmMwMjlmNmIzYWRkMzg3MjAzMTczL2Yvc3JjL2ludGVybmFsL2xpbmVhcl9zb2x2ZS5qbD91cmw9Z2l0JTQwZ2l0aHViLmNvbSUzQVNjaU1MJTJGTm9ubGluZWFyU29sdmUuamwuZ2l0JmxpbmVzPTcx?origin=gitlens) and installs default explicit identity preconditioners. Although these identity preconditioners mathematically provide no preconditioning, they inadvertently cause MINRES to incur [additional overhead](https://github.com/JuliaSmoothOptimizers/Krylov.jl/blob/main/src/minres.jl#L171). Would it be feasible to redefine these identity preconditioners as type `UniformScaling`, which does not result in this overhead?

We did this before for this reason in the wrappers. I didn’t catch that @Oscar_Smith 's latest PR removed it, but we should put that part back.

---

<div class="post-metadata">

### Author: ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)
#### Post date: [September 24, 2024, 11:22pm UTC](https://discourse.julialang.org/t/warning-when-using-nonlinearsolve-jl-with-linearsolve-jl-and-minres/119781/7 "2024-09-24T23:22:11Z")

</div>

I believe [use LinearSolve precs setup by oscardssmith · Pull Request #462 · SciML/NonlinearSolve.jl · GitHub](https://github.com/SciML/NonlinearSolve.jl/pull/462#issuecomment-2372436980) should fix this (although it still isn’t quite done yet)

---

<div class="post-metadata">

### Author: ![mpf01](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mpf01/32/8221_2.png) [@mpf01](https://discourse.julialang.org/u/mpf01)
#### Post date: [September 25, 2024, 6:03am UTC](https://discourse.julialang.org/t/warning-when-using-nonlinearsolve-jl-with-linearsolve-jl-and-minres/119781/8 "2024-09-25T06:03:36Z")

</div>

Thank you @Oscar_Smith for implementing this fix. I’ll apply your PR onto a fork.

Alternatively, is there a workaround for nullifying the default preconditioner that throws the warning?

---

<div class="post-metadata">

### Author: ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)
#### Post date: [September 25, 2024, 12:04pm UTC](https://discourse.julialang.org/t/warning-when-using-nonlinearsolve-jl-with-linearsolve-jl-and-minres/119781/9 "2024-09-25T12:04:21Z")

</div>

yeah I can add a fix on the LinearSolve side
