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

feat: add fields to OverrideInit, better nlsolve_alg handling #857

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

AayushSabharwal
Copy link
Member

@AayushSabharwal AayushSabharwal commented Nov 11, 2024

This replaces default_nlsolve in OrdinaryDiffEq, and will have methods in NonlinearSolve which can then be leveraged by all libraries for initialization.

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

Add any other context about the problem here.

@AayushSabharwal AayushSabharwal changed the title feat: add override_init_get_nlsolve feat: add fields to OverrideInit, better nlsolve_alg handling Nov 11, 2024
throw(OverrideInitMissingAlgorithm())
end

if initdata.update_initializeprob! !== nothing
initdata.update_initializeprob!(initprob, valp)
end

nlsol = solve(initprob, nlsolve_alg)
nlsol = solve(initprob, nlsolve_alg; abstol = alg.abstol)
Copy link
Member

Choose a reason for hiding this comment

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

it should default to using the tolerance from the solver if not supplied elsewhere.

@@ -100,7 +100,8 @@ Check if the algebraic constraints are satisfied, and error if they aren't. Retu
the `u0` and `p` as-is, and is always successful if it returns. Valid only for
`ODEProblem` and `DAEProblem`. Requires a `DEIntegrator` as its second argument.
"""
function get_initial_values(prob::ODEProblem, integrator, f, alg::CheckInit,
function get_initial_values(
prob::AbstractDEProblem, integrator::DEIntegrator, f, alg::CheckInit,
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't handle DAEProblem?

Copy link
Member Author

Choose a reason for hiding this comment

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

There's an AbstractDAEProblem dispatch below

Copy link
Member

Choose a reason for hiding this comment

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

But then this one should just be for ODEProblem?

Copy link
Member Author

Choose a reason for hiding this comment

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

SDEProblem dispatches here too

@@ -109,7 +110,7 @@ function get_initial_values(prob::ODEProblem, integrator, f, alg::CheckInit,

algebraic_vars = [all(iszero, x) for x in eachcol(M)]
algebraic_eqs = [all(iszero, x) for x in eachrow(M)]
(iszero(algebraic_vars) || iszero(algebraic_eqs)) && return
(iszero(algebraic_vars) || iszero(algebraic_eqs)) && return u0, p, true
update_coefficients!(M, u0, p, t)
tmp = _evaluate_f_ode(integrator, f, isinplace, u0, p, t)
tmp .= ArrayInterface.restructure(tmp, algebraic_eqs .* _vec(tmp))
Copy link
Member

Choose a reason for hiding this comment

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

integrator.opts.internalnorm: This doesn't handle Sundials or ODEInterface?

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm... I didn't know that. Makes sense that SciMLBase can't make the same assumptions OrdinaryDiffEq did

Comment on lines 310 to 327
"""
$(TYPEDSIGNATURES)

Get the `abstol` for the solve stored in the cache. Required for caches of algorithms for
which `cache_stores_tolerances(alg) == true`.
"""
function cache_get_abstol(cache)
error("Cache does not store the `abstol`.")
end

"""
$(TYPEDSIGNATURES)

Get the `reltol` for the solve stored in the cache. Required for caches of algorithms for
which `cache_stores_tolerances(alg) == true`.
"""
function cache_get_reltol(cache)
error("Cache does not store the `reltol`.")
Copy link
Member

Choose a reason for hiding this comment

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

I thought we talked about passing it?

Copy link
Member Author

Choose a reason for hiding this comment

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

Didn't you also mention having a trait and throwing an error message? Right now it takes a keyword argument and falls back to this if not provided.

Copy link
Member Author

Choose a reason for hiding this comment

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

That said I'm more than happy to remove this trait since solvers have to individually opt-in to doing initialization anyway.

Copy link
Member

Choose a reason for hiding this comment

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

Let's simplify and just make it required.

@AayushSabharwal
Copy link
Member Author

A lot of our tests still use codecov, apparently 😅

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