-
-
Notifications
You must be signed in to change notification settings - Fork 211
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
Initialization on non-DAE models #2512
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#2508 pointed out that the heuristic of `implicit_dae || calculate_massmatrix(sys) !== I`, i.e. "only do initialization on DAEs", while sensible for the DAE model, doesn't quite fit in the MTK context. Instead, what we need to do is check whether the varmap is correct and consistent for the chosen ODE. If it's not consistent for the selected ODE, then we still need to run an initialization step for the resulting ODE solve. This needs a few changes in the ODE solver as though, since currently only DAE solvers will run the initialization step. Thus the test case: ```julia using ModelingToolkit, OrdinaryDiffEq, Test using ModelingToolkit: t_nounits as t, D_nounits as D function System(;name) vars = @variables begin dx(t), [guess=0] ddx(t), [guess=0] end eqs = [ D(dx) ~ ddx 0 ~ ddx + dx + 1 ] return ODESystem(eqs, t, vars, []; name) end @mtkbuild sys = System() prob = ODEProblem(sys, [sys.dx => 1], (0,1)) # OK prob = ODEProblem(sys, [sys.ddx => -2], (0,1), guesses = [sys.dx => 1]) sol = solve(prob, Rodas5P()) sol = solve(prob, Tsit5()) ``` gives an erroneous success as it skips initialization, using `prob.u0 == [0.0]`, the sentinel value since initialization is only run on DAEs. We will need to override that so that initialization is always run on any system that provides an initializeprob.
ChrisRackauckas
added a commit
to SciML/OrdinaryDiffEq.jl
that referenced
this pull request
Feb 29, 2024
This can come up from cases with ModelingToolkit, see SciML/ModelingToolkit.jl#2512
ChrisRackauckas
changed the title
WIP: Initialization on non-DAE models
Initialization on non-DAE models
Feb 29, 2024
This also coincidentally adds steady state initializations as almost a free piece, and late binding initialization_eqs |
Ran locally since CI is taken over by codecov bumps. Passes! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
#2508 pointed out that the heuristic of
implicit_dae || calculate_massmatrix(sys) !== I
, i.e. "only do initialization on DAEs", while sensible for the DAE model, doesn't quite fit in the MTK context. Instead, what we need to do is check whether the varmap is correct and consistent for the chosen ODE. If it's not consistent for the selected ODE, then we still need to run an initialization step for the resulting ODE solve.This needs a few changes in the ODE solver as though, since currently only DAE solvers will run the initialization step. Thus the test case:
gives an erroneous success as it skips initialization, using
prob.u0 == [0.0]
, the sentinel value since initialization is only run on DAEs. We will need to override that so that initialization is always run on any system that provides an initializeprob.Fixes #2508