Skip to content

Commit 62e0bd2

Browse files
Merge pull request #2564 from AayushSabharwal/as/fix-jumpprob-no-params
fix: fix creation of JumpProblems with no parameters
2 parents 9ed933a + d21883e commit 62e0bd2

File tree

3 files changed

+46
-2
lines changed

3 files changed

+46
-2
lines changed

src/systems/jumps/jumpsystem.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ end
508508
function JumpSysMajParamMapper(js::JumpSystem, p; jseqs = nothing, rateconsttype = Float64)
509509
eqs = (jseqs === nothing) ? equations(js) : jseqs
510510
paramexprs = [maj.scaled_rates for maj in eqs.x[1]]
511-
psyms = reduce(vcat, reorder_parameters(js, parameters(js)))
511+
psyms = reduce(vcat, reorder_parameters(js, parameters(js)); init = [])
512512
paramdict = Dict(value(k) => value(v) for (k, v) in zip(psyms, vcat(p...)))
513513
JumpSysMajParamMapper{typeof(paramexprs), typeof(psyms), rateconsttype}(paramexprs,
514514
psyms,

src/systems/systems.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function structural_simplify(
2828
end
2929
if newsys isa ODESystem
3030
@set! newsys.parent = complete(sys; split)
31-
else
31+
elseif has_parent(newsys)
3232
@set! newsys.parent = complete(sys; split)
3333
end
3434
newsys = complete(newsys; split)
@@ -49,6 +49,11 @@ function structural_simplify(
4949
return newsys
5050
end
5151
end
52+
53+
function __structural_simplify(sys::JumpSystem, args...; kwargs...)
54+
return sys
55+
end
56+
5257
function __structural_simplify(sys::AbstractSystem, io = nothing; simplify = false,
5358
kwargs...)
5459
sys = expand_connections(sys)

test/jumpsystem.jl

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,3 +231,42 @@ let
231231
jtoj = eqeq_dependencies(jdeps, vdeps).fadjlist
232232
@test jtoj == [[1, 2, 4], [1, 2, 4], [1, 2, 3, 4], [1, 2, 3, 4]]
233233
end
234+
235+
# Create JumpProblems for systems without parameters
236+
# Issue#2559
237+
@parameters k
238+
@variables X(t)
239+
rate = k
240+
affect = [X ~ X - 1]
241+
242+
crj = ConstantRateJump(1.0, [X ~ X - 1])
243+
js1 = complete(JumpSystem([crj], t, [X], [k]; name = :js1))
244+
js2 = complete(JumpSystem([crj], t, [X], []; name = :js2))
245+
246+
maj = MassActionJump(1.0, [X => 1], [X => -1])
247+
js3 = complete(JumpSystem([maj], t, [X], [k]; name = :js2))
248+
js4 = complete(JumpSystem([maj], t, [X], []; name = :js3))
249+
250+
u0 = [X => 10]
251+
tspan = (0.0, 1.0)
252+
ps = [k => 1.0]
253+
254+
dp1 = DiscreteProblem(js1, u0, tspan, ps)
255+
dp2 = DiscreteProblem(js2, u0, tspan)
256+
dp3 = DiscreteProblem(js3, u0, tspan, ps)
257+
dp4 = DiscreteProblem(js4, u0, tspan)
258+
259+
@test_nowarn jp1 = JumpProblem(js1, dp1, Direct())
260+
@test_nowarn jp2 = JumpProblem(js2, dp2, Direct())
261+
@test_nowarn jp3 = JumpProblem(js3, dp3, Direct())
262+
@test_nowarn jp4 = JumpProblem(js4, dp4, Direct())
263+
264+
# Ensure `structural_simplify` (and `@mtkbuild`) works on JumpSystem (by doing nothing)
265+
# Issue#2558
266+
@parameters k
267+
@variables X(t)
268+
rate = k
269+
affect = [X ~ X - 1]
270+
271+
j1 = ConstantRateJump(k, [X ~ X - 1])
272+
@test_nowarn @mtkbuild js1 = JumpSystem([j1], t, [X], [k])

0 commit comments

Comments
 (0)