Skip to content

Commit 27e7efb

Browse files
fix: use remake to promote intialization problem
1 parent 59c6b31 commit 27e7efb

File tree

3 files changed

+36
-12
lines changed

3 files changed

+36
-12
lines changed

src/systems/diffeqs/abstractodesystem.jl

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -817,7 +817,9 @@ function DiffEqBase.ODEProblem{iip, specialize}(sys::AbstractODESystem, u0map =
817817
end
818818

819819
# Call `remake` so it runs initialization if it is trivial
820-
return remake(ODEProblem{iip}(f, u0, tspan, p, pt; kwargs1..., kwargs...))
820+
# Pass `u0` and `p` to run `ReconstructInitializeprob` which will promote
821+
# u0 and p of initializeprob
822+
return remake(ODEProblem{iip}(f, u0, tspan, p, pt; kwargs1..., kwargs...); u0, p)
821823
end
822824
get_callback(prob::ODEProblem) = prob.kwargs[:callback]
823825

@@ -1040,9 +1042,14 @@ function DiffEqBase.DAEProblem{iip}(sys::AbstractODESystem, du0map, u0map, tspan
10401042
end
10411043

10421044
# Call `remake` so it runs initialization if it is trivial
1043-
return remake(DAEProblem{iip}(
1044-
f, du0, u0, tspan, p; differential_vars = differential_vars,
1045-
kwargs..., kwargs1...))
1045+
# Pass `u0` and `p` to run `ReconstructInitializeprob` which will promote
1046+
# u0 and p of initializeprob
1047+
return remake(
1048+
DAEProblem{iip}(
1049+
f, du0, u0, tspan, p; differential_vars = differential_vars,
1050+
kwargs..., kwargs1...);
1051+
u0,
1052+
p)
10461053
end
10471054

10481055
function generate_history(sys::AbstractODESystem, u0; expression = Val{false}, kwargs...)
@@ -1088,7 +1095,9 @@ function DiffEqBase.DDEProblem{iip}(sys::AbstractODESystem, u0map = [],
10881095
kwargs1 = merge(kwargs1, (callback = cbs,))
10891096
end
10901097
# Call `remake` so it runs initialization if it is trivial
1091-
return remake(DDEProblem{iip}(f, u0, h, tspan, p; kwargs1..., kwargs...))
1098+
# Pass `u0` and `p` to run `ReconstructInitializeprob` which will promote
1099+
# u0 and p of initializeprob
1100+
return remake(DDEProblem{iip}(f, u0, h, tspan, p; kwargs1..., kwargs...); u0, p)
10921101
end
10931102

10941103
function DiffEqBase.SDDEProblem(sys::AbstractODESystem, args...; kwargs...)
@@ -1139,9 +1148,14 @@ function DiffEqBase.SDDEProblem{iip}(sys::AbstractODESystem, u0map = [],
11391148
noise_rate_prototype = zeros(eltype(u0), size(noiseeqs))
11401149
end
11411150
# Call `remake` so it runs initialization if it is trivial
1142-
return remake(SDDEProblem{iip}(f, f.g, u0, h, tspan, p;
1143-
noise_rate_prototype =
1144-
noise_rate_prototype, kwargs1..., kwargs...))
1151+
# Pass `u0` and `p` to run `ReconstructInitializeprob` which will promote
1152+
# u0 and p of initializeprob
1153+
return remake(
1154+
SDDEProblem{iip}(f, f.g, u0, h, tspan, p;
1155+
noise_rate_prototype =
1156+
noise_rate_prototype, kwargs1..., kwargs...);
1157+
u0,
1158+
p)
11451159
end
11461160

11471161
"""

src/systems/diffeqs/sdesystem.jl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -818,8 +818,13 @@ function DiffEqBase.SDEProblem{iip, specialize}(
818818
kwargs = filter_kwargs(kwargs)
819819

820820
# Call `remake` so it runs initialization if it is trivial
821-
return remake(SDEProblem{iip}(f, u0, tspan, p; callback = cbs, noise,
822-
noise_rate_prototype = noise_rate_prototype, kwargs...))
821+
# Pass `u0` and `p` to run `ReconstructInitializeprob` which will promote
822+
# u0 and p of initializeprob
823+
return remake(
824+
SDEProblem{iip}(f, u0, tspan, p; callback = cbs, noise,
825+
noise_rate_prototype = noise_rate_prototype, kwargs...);
826+
u0,
827+
p)
823828
end
824829

825830
function DiffEqBase.SDEProblem(sys::ODESystem, args...; kwargs...)

src/systems/nonlinear/nonlinearsystem.jl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,9 @@ function DiffEqBase.NonlinearProblem{iip}(sys::NonlinearSystem, u0map,
557557
check_length, kwargs...)
558558
pt = something(get_metadata(sys), StandardNonlinearProblem())
559559
# Call `remake` so it runs initialization if it is trivial
560-
return remake(NonlinearProblem{iip}(f, u0, p, pt; filter_kwargs(kwargs)...))
560+
# Pass `u0` and `p` to run `ReconstructInitializeprob` which will promote
561+
# u0 and p of initializeprob
562+
return remake(NonlinearProblem{iip}(f, u0, p, pt; filter_kwargs(kwargs)...); u0, p)
561563
end
562564

563565
function DiffEqBase.NonlinearProblem(sys::AbstractODESystem, args...; kwargs...)
@@ -591,7 +593,10 @@ function DiffEqBase.NonlinearLeastSquaresProblem{iip}(sys::NonlinearSystem, u0ma
591593
check_length, kwargs...)
592594
pt = something(get_metadata(sys), StandardNonlinearProblem())
593595
# Call `remake` so it runs initialization if it is trivial
594-
return remake(NonlinearLeastSquaresProblem{iip}(f, u0, p; filter_kwargs(kwargs)...))
596+
# Pass `u0` and `p` to run `ReconstructInitializeprob` which will promote
597+
# u0 and p of initializeprob
598+
return remake(
599+
NonlinearLeastSquaresProblem{iip}(f, u0, p; filter_kwargs(kwargs)...); u0, p)
595600
end
596601

597602
const TypeT = Union{DataType, UnionAll}

0 commit comments

Comments
 (0)