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

Remake defined but doesn't seem to do anything #168

Closed
aabills opened this issue Mar 21, 2023 · 2 comments · Fixed by SciML/SciMLBase.jl#569
Closed

Remake defined but doesn't seem to do anything #168

aabills opened this issue Mar 21, 2023 · 2 comments · Fixed by SciML/SciMLBase.jl#569

Comments

@aabills
Copy link

aabills commented Mar 21, 2023

MWE:

using NonlinearSolve

function mwe(out, u, p)
    out[1] = u[1] - p[1]
end

p = [5.0]

prob = NonlinearProblem(mwe, [5.2], p=p)
u = solve(prob, NewtonRaphson())

prob2 = remake(prob, p=[6.0])
u2 = solve(prob2, NewtonRaphson())

Results in:

julia> u
u: 1-element Vector{Float64}:
 5.0

julia> u2
u: 1-element Vector{Float64}:
 5.0

But when looking at ?remake:

 remake(prob::NonlinearProblem; f = missing, u0 = missing, p = missing,
      problem_type = missing, kwargs = missing, _kwargs...)

  Remake the given NonlinearProblem. If u0 or p are given as symbolic maps ModelingToolkit.jl has to be loaded.

I don't know if this is expected behavior (and maybe should result in an error or a warning) or should just be fixed, but I felt like it should be reported as it can result in a silent wrong answer.

@DanielVandH
Copy link
Member

DanielVandH commented Mar 25, 2023

The problem is that p is not a keyword argument for NonlinearProblem, so passing p as you are doing it gets pushed into prob.kwargs instead:

julia> prob = NonlinearProblem(mwe, [5.2], p=p)
NonlinearProblem with uType Vector{Float64}. In-place: true
u0: 1-element Vector{Float64}:
 5.2

julia> prob.p
SciMLBase.NullParameters()

julia> prob.kwargs
pairs(::NamedTuple) with 1 entry:
  :p => [5.0]

It works if you don't do this -

using NonlinearSolve

function mwe(out, u, p)
    out[1] = u[1] - p[1]
end

p = [5.0]

prob = NonlinearProblem(mwe, [5.2], p)
prob.p 
prob.kwargs 

u = solve(prob, NewtonRaphson())

prob2 = remake(prob, p=[6.0])
u2 = solve(prob2, NewtonRaphson())
julia> u
u: 1-element Vector{Float64}:
 5.0

julia> u2
u: 1-element Vector{Float64}:
 6.0

@ChrisRackauckas
Copy link
Member

We should probably catch and throw an error if someone does p = ....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants