Skip to content

Commit d6195ee

Browse files
authored
Merge pull request #1758 from SciML/myb/scimlfun
Forward `sys` to `SciMLFunction`s
2 parents 5281b3f + 1ff6598 commit d6195ee

File tree

12 files changed

+15
-3
lines changed

12 files changed

+15
-3
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ NonlinearSolve = "0.3.8"
6868
RecursiveArrayTools = "2.3"
6969
Reexport = "0.2, 1"
7070
RuntimeGeneratedFunctions = "0.4.3, 0.5"
71-
SciMLBase = "1.26.2"
71+
SciMLBase = "1.49"
7272
Setfield = "0.7, 0.8, 1"
7373
SpecialFunctions = "0.7, 0.8, 0.9, 0.10, 1.0, 2"
7474
StaticArrays = "0.10, 0.11, 0.12, 1.0"

src/systems/diffeqs/abstractodesystem.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,7 @@ function DiffEqBase.ODEFunction{iip}(sys::AbstractODESystem, dvs = states(sys),
339339
nothing
340340
end
341341
ODEFunction{iip}(f,
342+
sys = sys,
342343
jac = _jac === nothing ? nothing : _jac,
343344
tgrad = _tgrad === nothing ? nothing : _tgrad,
344345
mass_matrix = _M,
@@ -427,6 +428,7 @@ function DiffEqBase.DAEFunction{iip}(sys::AbstractODESystem, dvs = states(sys),
427428
end
428429

429430
DAEFunction{iip}(f,
431+
sys = sys,
430432
jac = _jac === nothing ? nothing : _jac,
431433
syms = Symbol.(dvs),
432434
jac_prototype = jac_prototype,

src/systems/diffeqs/sdesystem.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,7 @@ function DiffEqBase.SDEFunction{iip}(sys::SDESystem, dvs = states(sys),
406406

407407
sts = states(sys)
408408
SDEFunction{iip}(f, g,
409+
sys = sys,
409410
jac = _jac === nothing ? nothing : _jac,
410411
tgrad = _tgrad === nothing ? nothing : _tgrad,
411412
Wfact = _Wfact === nothing ? nothing : _Wfact,

src/systems/discrete_system/discrete_system.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ function SciMLBase.DiscreteProblem(sys::DiscreteSystem, u0map, tspan,
198198
expression_module = eval_module)
199199
f_oop, _ = (@RuntimeGeneratedFunction(eval_module, ex) for ex in f_gen)
200200
f(u, p, iv) = f_oop(u, p, iv)
201-
fd = DiscreteFunction(f, syms = Symbol.(dvs))
201+
fd = DiscreteFunction(f; syms = Symbol.(dvs), sys = sys)
202202
DiscreteProblem(fd, u0, tspan, p; kwargs...)
203203
end
204204

src/systems/jumps/jumpsystem.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ function DiffEqBase.DiscreteProblem(sys::JumpSystem, u0map, tspan::Union{Tuple,
283283
end
284284
end
285285

286-
df = DiscreteFunction{true, true}(f, syms = Symbol.(states(sys)),
286+
df = DiscreteFunction{true, true}(f; syms = Symbol.(states(sys)), sys = sys,
287287
observed = observedfun)
288288
DiscreteProblem(df, u0, tspan, p; kwargs...)
289289
end

src/systems/nonlinear/nonlinearsystem.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ function SciMLBase.NonlinearFunction{iip}(sys::NonlinearSystem, dvs = states(sys
233233
end
234234

235235
NonlinearFunction{iip}(f,
236+
sys = sys,
236237
jac = _jac === nothing ? nothing : _jac,
237238
jac_prototype = sparse ?
238239
similar(calculate_jacobian(sys, sparse = sparse),

src/systems/optimization/optimizationsystem.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ function DiffEqBase.OptimizationProblem{iip}(sys::OptimizationSystem, u0map,
231231
end
232232

233233
_f = DiffEqBase.OptimizationFunction{iip}(f,
234+
sys = sys,
234235
SciMLBase.NoAD();
235236
grad = _grad,
236237
hess = _hess,
@@ -244,6 +245,7 @@ function DiffEqBase.OptimizationProblem{iip}(sys::OptimizationSystem, u0map,
244245
cons_expr = cons_expr)
245246
else
246247
_f = DiffEqBase.OptimizationFunction{iip}(f,
248+
sys = sys,
247249
SciMLBase.NoAD();
248250
grad = _grad,
249251
hess = _hess,

test/discretesystem.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ u0 = [S => 990.0, I => 10.0, R => 0.0]
3232
p ==> 0.05, c => 10.0, γ => 0.25, δt => 0.1, nsteps => 400]
3333
tspan = (0.0, ModelingToolkit.value(substitute(nsteps, p))) # value function (from Symbolics) is used to convert a Num to Float64
3434
prob_map = DiscreteProblem(sys, u0, tspan, p)
35+
@test prob_map.f.sys === sys
3536

3637
# Solution
3738
using OrdinaryDiffEq

test/nonlinearsystem.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ sH = calculate_hessian(ns)
7979
getfield.(sparse.(sH), :rowval)
8080

8181
prob = NonlinearProblem(ns, ones(3), ones(3))
82+
@test prob.f.sys === ns
8283
sol = solve(prob, NewtonRaphson())
8384
@test sol.u[1] sol.u[2]
8485

test/odesystem.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ p2 = (k₁ => 0.04,
213213
k₃ => 1e4)
214214
tspan = (0.0, 100000.0)
215215
prob1 = ODEProblem(sys, u0, tspan, p)
216+
@test prob1.f.sys === sys
216217
prob12 = ODEProblem(sys, u0, tspan, [0.04, 3e7, 1e4])
217218
prob13 = ODEProblem(sys, u0, tspan, (0.04, 3e7, 1e4))
218219
prob14 = ODEProblem(sys, u0, tspan, p2)

0 commit comments

Comments
 (0)