Skip to content

fix: fix creation of JumpProblems with no parameters #2564

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/systems/jumps/jumpsystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ end
function JumpSysMajParamMapper(js::JumpSystem, p; jseqs = nothing, rateconsttype = Float64)
eqs = (jseqs === nothing) ? equations(js) : jseqs
paramexprs = [maj.scaled_rates for maj in eqs.x[1]]
psyms = reduce(vcat, reorder_parameters(js, parameters(js)))
psyms = reduce(vcat, reorder_parameters(js, parameters(js)); init = [])
paramdict = Dict(value(k) => value(v) for (k, v) in zip(psyms, vcat(p...)))
JumpSysMajParamMapper{typeof(paramexprs), typeof(psyms), rateconsttype}(paramexprs,
psyms,
Expand Down
7 changes: 6 additions & 1 deletion src/systems/systems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function structural_simplify(
end
if newsys isa ODESystem
@set! newsys.parent = complete(sys; split)
else
elseif has_parent(newsys)
@set! newsys.parent = complete(sys; split)
end
newsys = complete(newsys; split)
Expand All @@ -49,6 +49,11 @@ function structural_simplify(
return newsys
end
end

function __structural_simplify(sys::JumpSystem, args...; kwargs...)
return sys
end

function __structural_simplify(sys::AbstractSystem, io = nothing; simplify = false,
kwargs...)
sys = expand_connections(sys)
Expand Down
39 changes: 39 additions & 0 deletions test/jumpsystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -231,3 +231,42 @@ let
jtoj = eqeq_dependencies(jdeps, vdeps).fadjlist
@test jtoj == [[1, 2, 4], [1, 2, 4], [1, 2, 3, 4], [1, 2, 3, 4]]
end

# Create JumpProblems for systems without parameters
# Issue#2559
@parameters k
@variables X(t)
rate = k
affect = [X ~ X - 1]

crj = ConstantRateJump(1.0, [X ~ X - 1])
js1 = complete(JumpSystem([crj], t, [X], [k]; name = :js1))
js2 = complete(JumpSystem([crj], t, [X], []; name = :js2))

maj = MassActionJump(1.0, [X => 1], [X => -1])
js3 = complete(JumpSystem([maj], t, [X], [k]; name = :js2))
js4 = complete(JumpSystem([maj], t, [X], []; name = :js3))

u0 = [X => 10]
tspan = (0.0, 1.0)
ps = [k => 1.0]

dp1 = DiscreteProblem(js1, u0, tspan, ps)
dp2 = DiscreteProblem(js2, u0, tspan)
dp3 = DiscreteProblem(js3, u0, tspan, ps)
dp4 = DiscreteProblem(js4, u0, tspan)

@test_nowarn jp1 = JumpProblem(js1, dp1, Direct())
@test_nowarn jp2 = JumpProblem(js2, dp2, Direct())
@test_nowarn jp3 = JumpProblem(js3, dp3, Direct())
@test_nowarn jp4 = JumpProblem(js4, dp4, Direct())

# Ensure `structural_simplify` (and `@mtkbuild`) works on JumpSystem (by doing nothing)
# Issue#2558
@parameters k
@variables X(t)
rate = k
affect = [X ~ X - 1]

j1 = ConstantRateJump(k, [X ~ X - 1])
@test_nowarn @mtkbuild js1 = JumpSystem([j1], t, [X], [k])