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: perform limited DAE initialization for null integrators/solutions #1070

Merged
merged 2 commits into from
Oct 7, 2024
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 Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ Printf = "1.9"
RecursiveArrayTools = "3"
Reexport = "1.0"
ReverseDiff = "1"
SciMLBase = "2.53.0"
SciMLBase = "2.56.0"
SciMLOperators = "0.3"
SciMLStructures = "1.5"
Setfield = "1"
Expand Down
10 changes: 9 additions & 1 deletion src/solve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,9 @@ end
function build_null_integrator(prob::AbstractDEProblem, args...;
kwargs...)
sol = solve(prob, args...; kwargs...)
# The DAE initialization in `build_null_solution` may change the parameter
# object `prob.p` via `@set!`, hence use the "new" prob instead of the "old" one.
prob = sol.prob
return NullODEIntegrator{
isinplace(prob), typeof(prob), eltype(prob.tspan), typeof(sol),
typeof(prob.f), typeof(prob.p)
Expand Down Expand Up @@ -675,7 +678,12 @@ function build_null_solution(prob::AbstractDEProblem, args...;
end

timeseries = [Float64[] for i in 1:length(ts)]


if SciMLBase.has_initializeprob(prob.f) && SciMLBase.has_initializeprobpmap(prob.f)
initializeprob = prob.f.initializeprob
nlsol = solve(initializeprob)
@set! prob.p = prob.f.initializeprobpmap(prob, nlsol)
Copy link
Member

Choose a reason for hiding this comment

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

isn't the map in-place?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah. I think I wrote this when it was out-of-place, and didn't update it. Will edit and check

Copy link
Member Author

Choose a reason for hiding this comment

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

No wait it's out of place 😅 with the idea that solving should not change the problem since then there's a chance for stateful errors where solving the same problem multiple times leads to different results

end
build_solution(prob, nothing, ts, timeseries, retcode = ReturnCode.Success)
end

Expand Down
Loading