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

Use NonlinearAliasSpecifier for NonlinearProblem #1138

Merged
merged 1 commit into from
Apr 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/DiffEqBase.jl
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ using SciMLBase: @def, DEIntegrator, AbstractDEProblem,
AbstractDAEIntegrator, unwrap_cache, has_reinit, reinit!,
postamble!, last_step_failed, islinear, has_stats,
initialize_dae!, build_solution, solution_new_retcode,
solution_new_tslocation, plot_indices,
solution_new_tslocation, plot_indices, NonlinearAliasSpecifier,
NullParameters, isinplace, AbstractADType, AbstractDiscretization,
DISCRETE_OUTOFPLACE_DEFAULT, DISCRETE_INPLACE_DEFAULT,
has_analytic, calculate_solution_errors!, AbstractNoiseProcess,
Expand Down
29 changes: 27 additions & 2 deletions src/solve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1089,13 +1089,38 @@ function solve(prob::NonlinearProblem, args...; sensealg = nothing,
sensealg = prob.kwargs[:sensealg]
end


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is now handled in nonlinearsolvebase?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The sensealg part?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, double check the stack trace during a nonlinearsolve solve? Does it hit here? I thought it was eliminated.

Copy link
Member Author

@jClugstor jClugstor Apr 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does hit here, unless you use the default solver, so with

using NonlinearSolve

f(u, p) = u .* u .- p
u0 = [1.0, 1.0]
p = 2.0
prob = NonlinearProblem(f, u0, p)
solve(prob)

it hits the __solve for the NonlinearSolvePolyAlgorithm here instead:
https://github.com/SciML/NonlinearSolve.jl/blob/b182ae1b8584763004392b335e094545d9f1be58/lib/NonlinearSolveBase/src/solve.jl#L124-L128

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh I guess we'll move that later.

if haskey(prob.kwargs, :alias_u0)
@warn "The `alias_u0` keyword argument is deprecated. Please use a NonlinearAliasSpecifier, e.g. `alias = NonlinearAliasSpecifier(alias_u0 = true)`."
alias_spec = NonlinearAliasSpecifier(alias_u0 = prob.kwargs[:alias_u0])
elseif haskey(kwargs, :alias_u0)
@warn "The `alias_u0` keyword argument is deprecated. Please use a NonlinearAliasSpecifier, e.g. `alias = NonlinearAliasSpecifier(alias_u0 = true)`."
alias_spec = NonlinearAliasSpecifier(alias_u0 = kwargs[:alias_u0])
end

if haskey(prob.kwargs, :alias) && prob.kwargs[:alias] isa Bool
alias_spec = NonlinearAliasSpecifier(alias = prob.kwargs[:alias])
elseif haskey(kwargs, :alias) && kwargs[:alias] isa Bool
alias_spec = NonlinearAliasSpecifier(alias = kwargs[:alias])
end

if haskey(prob.kwargs, :alias) && prob.kwargs[:alias] isa NonlinearAliasSpecifier
alias_spec = prob.kwargs[:alias]
elseif haskey(kwargs, :alias) && kwargs[:alias] isa NonlinearAliasSpecifier
alias_spec = kwargs[:alias]
else
alias_spec = NonlinearAliasSpecifier(alias_u0 = false)
end

alias_u0 = alias_spec.alias_u0

u0 = u0 !== nothing ? u0 : prob.u0
p = p !== nothing ? p : prob.p

if wrap isa Val{true}
wrap_sol(solve_up(prob, sensealg, u0, p, args...; kwargs...))
wrap_sol(solve_up(prob, sensealg, u0, p, args...; alias_u0 = alias_u0, kwargs...))
else
solve_up(prob, sensealg, u0, p, args...; kwargs...)
solve_up(prob, sensealg, u0, p, args...; alias_u0 = alias_u0, kwargs...)
end
end

Expand Down
Loading