Skip to content

Revert "Make get_initial_values differentiate" #1030

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

Merged
merged 1 commit into from
May 20, 2025
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
13 changes: 9 additions & 4 deletions src/initialization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ function get_initial_values(prob, valp, f, alg::OverrideInit,
end

if is_trivial_initialization(initdata)
nlsol = initdata
nlsol = initprob
success = true
else
nlsolve_alg = something(nlsolve_alg, alg.nlsolve, Some(nothing))
Expand Down Expand Up @@ -295,13 +295,18 @@ function get_initial_values(prob, valp, f, alg::OverrideInit,
end

if initdata.initializeprobmap !== nothing
u0 = initdata.initializeprobmap(choose_branch(nlsol))
u02 = initdata.initializeprobmap(nlsol)
end
if initdata.initializeprobpmap !== nothing
p = initdata.initializeprobpmap(valp, choose_branch(nlsol))
p2 = initdata.initializeprobpmap(valp, nlsol)
end

return u0, p, success
# specifically needs to be written this way for Zygote
# See https://github.com/SciML/ModelingToolkit.jl/pull/3585#issuecomment-2883919162
u03 = isnothing(initdata.initializeprobmap) ? u0 : u02
p3 = isnothing(initdata.initializeprobpmap) ? p : p2

return u03, p3, success
end

"""
Expand Down
3 changes: 0 additions & 3 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,3 @@ Strips a SciMLSolution object and its interpolation of their functions to better
function strip_solution(sol::AbstractSciMLSolution)
sol
end

choose_branch(x::OverrideInitData) = x.initializeprob
choose_branch(sol::AbstractSciMLSolution) = sol
Loading