Skip to content

Commit 11f2b76

Browse files
Merge pull request #956 from AayushSabharwal/as/steadystate-remake
feat: add dedicated `remake` method for `SteadyStateProblem`
2 parents fa81653 + dce911b commit 11f2b76

File tree

5 files changed

+59
-0
lines changed

5 files changed

+59
-0
lines changed

src/problems/problem_utils.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,3 +194,4 @@ Base.copy(p::SciMLBase.NullParameters) = p
194194

195195
SymbolicIndexingInterface.is_time_dependent(::AbstractDEProblem) = true
196196
SymbolicIndexingInterface.is_time_dependent(::AbstractNonlinearProblem) = false
197+
SymbolicIndexingInterface.is_time_dependent(::AbstractSteadyStateProblem) = true

src/problems/steady_state_problems.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,17 @@ function SteadyStateProblem(f, u0, p = NullParameters(); kwargs...)
113113
SteadyStateProblem(ODEFunction(f), u0, p; kwargs...)
114114
end
115115

116+
function ConstructionBase.constructorof(::Type{P}) where {P <: SteadyStateProblem}
117+
function ctor(f, u0, p, kw)
118+
if f isa AbstractODEFunction
119+
iip = isinplace(f)
120+
else
121+
iip = isinplace(f, 4)
122+
end
123+
return SteadyStateProblem{iip}(f, u0, p; kw...)
124+
end
125+
end
126+
116127
"""
117128
$(SIGNATURES)
118129

src/remake.jl

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,47 @@ function remake(prob::NonlinearProblem;
712712
return prob
713713
end
714714

715+
function remake(prob::SteadyStateProblem;
716+
f = missing,
717+
u0 = missing,
718+
p = missing,
719+
kwargs = missing,
720+
interpret_symbolicmap = true,
721+
use_defaults = false,
722+
lazy_initialization = nothing,
723+
build_initializeprob = true,
724+
_kwargs...)
725+
newu0, newp = updated_u0_p(prob, u0, p; interpret_symbolicmap, use_defaults)
726+
727+
if build_initializeprob
728+
if f !== missing && has_initialization_data(f)
729+
initialization_data = remake_initialization_data(
730+
prob.f.sys, f, u0, nothing, p, newu0, newp)
731+
else
732+
initialization_data = remake_initialization_data(
733+
prob.f.sys, prob.f, u0, nothing, p, newu0, newp)
734+
end
735+
else
736+
initialization_data = nothing
737+
end
738+
739+
f = coalesce(f, prob.f)
740+
f = remake(prob.f; f, initialization_data)
741+
742+
prob = if kwargs === missing
743+
SteadyStateProblem{isinplace(prob)}(f = f, u0 = newu0, p = newp; prob.kwargs...,
744+
_kwargs...)
745+
else
746+
SteadyStateProblem{isinplace(prob)}(f = f, u0 = newu0, p = newp; kwargs...)
747+
end
748+
749+
u0, p = maybe_eager_initialize_problem(prob, initialization_data, lazy_initialization)
750+
@reset prob.u0 = u0
751+
@reset prob.p = p
752+
753+
return prob
754+
end
755+
715756
"""
716757
remake(prob::NonlinearLeastSquaresProblem; f = missing, u0 = missing, p = missing,
717758
kwargs = missing, _kwargs...)

test/downstream/modelingtoolkit_remake.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ tspan = (0.0, 100.0)
3333
push!(syss, sys)
3434
push!(probs, ODEProblem(sys, u0, tspan, p, jac = true))
3535

36+
push!(syss, sys)
37+
push!(probs, SteadyStateProblem(ODEProblem(sys, u0, tspan, p, jac = true)))
38+
3639
noise_eqs = [0.1x, 0.1y, 0.1z]
3740
@named sdesys = SDESystem(sys, noise_eqs)
3841
sdesys = complete(sdesys)

test/remake_tests.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ fn = ODEFunction(lorenz!; sys)
2020
for T in containerTypes
2121
push!(probs, ODEProblem(fn, u0, tspan, T(p)))
2222
end
23+
for T in containerTypes
24+
push!(probs, SteadyStateProblem(fn, u0, T(p)))
25+
end
2326

2427
function ddelorenz!(du, u, h, p, t)
2528
du[1] = p[1] * (u[2] - u[1])

0 commit comments

Comments
 (0)