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

[WIP] feat: add hooks for OverrideInit #517

Draft
wants to merge 29 commits into
base: master
Choose a base branch
from

Conversation

AayushSabharwal
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

Add any other context about the problem here.

kwargs...
)
return NonlinearSolveNoInitCache(prob, alg, args, kwargs)
cache = NonlinearSolveNoInitCache(
prob, alg, args, kwargs, initializealg, ReturnCode.Success)
Copy link
Member Author

Choose a reason for hiding this comment

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

Suggested change
prob, alg, args, kwargs, initializealg, ReturnCode.Success)
prob, alg, args, kwargs, initializealg, ReturnCode.Default)

Probably should be this

)
end

NonlinearSolveBase.run_initialization!(cache)
Copy link
Member Author

Choose a reason for hiding this comment

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

Should this be inside the @static_timeit?

Copy link
Member

Choose a reason for hiding this comment

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

yes

)
end

NonlinearSolveBase.run_initialization!(cache)
Copy link
Member Author

Choose a reason for hiding this comment

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

Again with the @static_timeit

)
end

NonlinearSolveBase.run_initialization!(cache)
Copy link
Member Author

Choose a reason for hiding this comment

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

@static_timeit

@avik-pal
Copy link
Member

Can you briefly mention the motivation behind this? I am not too familiar with the background (other PRs for DAEs and stuff)

@AayushSabharwal
Copy link
Member Author

Sure. MTK currently generates initialization problems for ODEs. SciML/ModelingToolkit.jl#3253 aims to expand this to all such problems. The basic use case is that users can specify initial conditions for variables that MTK eliminates from the system, and the initialization process solves for the states of the system. As a contrived example, consider:

y ~ x^3
x^2 + y^2 ~ 2

MTK will reduce this to a system with a single unknown x and a single equation (the latter). It will dynamically calculate y inside the f provided to NonlinearFunction. Currently, the user has to specify an initial condition for x. With OverrideInit, the user can specify an initial condition for y (say 3) and MTK will generate the following InitializationProblem (NonlinearProblem):

y ~ 3
y ~ x^3

and solve for x. As an added check, it ensures overspecified initial conditions are consistent. e.g. in the example above, if the initial condition [x => 3, y => 3] is specified, MTK generates a NonlinearLeastSquaresProblem:

x ~ 3
y ~ 3
y ~ x^3

This fails the nonlinear solve with ReturnCode.InitialFailure telling the user their initial conditions are inconsistent/unsatisfiable.

MTK can also potentially solve for parameters, such as if x + y ~ p^2 is an equation, the user can specify x and y and MTK will generate a NonlinearProblem to solve for p.

The core infrastructure is in SciMLBase, but all solver libraries need to hook into it. In most cases, this is a trivial change: https://github.com/SciML/StochasticDelayDiffEq.jl/pull/84/files. NonlinearSolve has a billion entry points, multiple different "integrators" (caches) and a whole host of other intricacies which make this PR more complicated.

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