Is `callback` really compatible with NonlinearProblem?

Hi everyone,

According to the documentation (Nonlinear Problems · NonlinearSolve.jl), “if you set a callback in the problem, then that callback will be added in every solve call”. So I tried to add a callback but nothing seems to happen, see the following example.

using NonlinearSolve

f(u, p) = u .* u .- p
u0 = [1.0, 1.0]
p = 2.0
prob = NonlinearProblem(f, u0, p; callback = x -> error("hello world"))
sol = solve(prob) # nothing special happens

condition(args...) = true
affect!(integrator) = error("hello world !")
cb = DiscreteCallback(condition, affect!;)
prob = NonlinearProblem(f, u0, p; callback = cb)
sol = solve(prob) # nothing special happens

I saw on discourse the use of termination_condition, do you recommend to tweak this callback to insert what I want to do and return a termination condition? Or should I use the step interface to take control of the iterations and insert my callback?

PS : I’m using NonlinearSolve version 4.12.0

Yeah, pretty sure that’s a doc bug. @ChrisRackauckas can you confirm?

yes that is a docs issue

Would it be a problem to append a callback(s) call right after the CommonSolve.step! call (I mean here : NonlinearSolve.jl/lib/NonlinearSolveBase/src/solve.jl at d47550f65edf7285368b4975ad44922f47841f3c · SciML/NonlinearSolve.jl · GitHub)?

I’m not confortable to open a PR since I’m not familiar with the project architecture (moreover, this feature may not be something you guys want).

it would need a proper interface based on the cache type, and that cache type would need to document its API. Doable, and something that should get done, but not in the library yet.