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

Conversation

jClugstor
Copy link
Member

Checklist

  • Appropriate tests were added
  • Any code changes were done in a way that does not break public API
  • All documentation related to code changes were updated
  • The new code follows the
    contributor guidelines, in particular the SciML Style Guide and
    COLPRAC.
  • Any new documentation only uses public API

Additional context

This adds support for using the NonlinearAliasSpecifier to specify if u0 is aliased or not.

The reason I want to put it here for now is because with the current way that NonlinearSolve is structured, it would take significant refactoring to do this in a similar way this was done in OrdinaryDiffEq, LinearSolve etc. as well as supporting aliasing other variables. alias_u0 is an argument to many of the internal NonlinearSolve functions, and it would take major changes to change it to using a NonlinearAliasSpecifier, if it even makes sense to do so. Additionally, the __init functions are spread out between the different solving algorithms, so there's no single place in NonlinearSolve to put this, like in the other packages.

This will deprecate the alias_u0 kwarg, and allow users to use a NonlinearAliasSpecifier to specify if u0 is aliased.
A Bool alias kwarg is supported as well.

@@ -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.

@ChrisRackauckas ChrisRackauckas merged commit e14115c into SciML:master Apr 5, 2025
31 of 43 checks passed
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 this pull request may close these issues.

2 participants