Skip to content

Commit

Permalink
Merge pull request #910 from AayushSabharwal/as/optional-iprobmap
Browse files Browse the repository at this point in the history
feat: allow `initializeprobmap` to be `nothing`
  • Loading branch information
ChrisRackauckas authored Jan 19, 2025
2 parents f4eb248 + c1be362 commit e910e4d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/initialization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ struct OverrideInitData{IProb, UIProb, IProbMap, IProbPmap}
update_initializeprob!::UIProb
"""
A function which takes the solution of `initializeprob` and returns
the state vector of the original problem.
the state vector of the original problem. If absent, the existing state vector
will be used.
"""
initializeprobmap::IProbMap
"""
Expand Down Expand Up @@ -260,7 +261,9 @@ function get_initial_values(prob, valp, f, alg::OverrideInit,
success = SciMLBase.successful_retcode(nlsol)
end

u0 = initdata.initializeprobmap(nlsol)
if initdata.initializeprobmap !== nothing
u0 = initdata.initializeprobmap(nlsol)
end
if initdata.initializeprobpmap !== nothing
p = initdata.initializeprobpmap(valp, nlsol)
end
Expand Down
15 changes: 15 additions & 0 deletions test/initialization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,21 @@ end
@test success
end

@testset "Solves without `initializeprobmap`" begin
initdata = SciMLBase.@set initialization_data.initializeprobmap = nothing
fn = ODEFunction(rhs2; initialization_data = initdata)
prob = ODEProblem(fn, [2.0, 0.0], (0.0, 1.0), 0.0)
integ = init(prob; initializealg = NoInit())

u0, p, success = SciMLBase.get_initial_values(
prob, integ, fn, SciMLBase.OverrideInit(),
Val(false); nlsolve_alg = NewtonRaphson(), abstol, reltol)

@test u0 [2.0, 0.0]
@test p 1.0
@test success
end

@testset "Solves without `initializeprobpmap`" begin
initdata = SciMLBase.@set initialization_data.initializeprobpmap = nothing
fn = ODEFunction(rhs2; initialization_data = initdata)
Expand Down

0 comments on commit e910e4d

Please sign in to comment.