Skip to content

Commit

Permalink
Merge e6d4da7 into 888a36b
Browse files Browse the repository at this point in the history
  • Loading branch information
TorkelE committed Apr 4, 2023
2 parents 888a36b + e6d4da7 commit c163962
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/problem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,19 @@ function DiffEqBase.remake(thing::JumpProblem; kwargs...)
thing.kwargs)
end

# when setindex! is used.
function Base.setindex!(prob::JumpProblem, args...; kwargs...)
SciMLBase.___internal_setindex!(prob.prob, args...; kwargs...)
if using_params(prob.massaction_jump)
update_parameters!(prob.massaction_jump, prob.prob.p)
end
end

# when getindex is used.
function Base.getindex(prob::JumpProblem, args...; kwargs...)
Base.getindex(prob.prob, args...; kwargs...)
end

DiffEqBase.isinplace(::JumpProblem{iip}) where {iip} = iip
JumpProblem(prob::JumpProblem) = prob

Expand Down
17 changes: 17 additions & 0 deletions test/jprob_symbol_indexing.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# prepares the problem
using JumpProcesses, Test
rate1(u,p,t) = p[1]
rate2(u,p,t) = p[2]
affect1!(integ) = (integ.u[1] +=1)
affect2!(integ) = (integ.u[2] += 1)
crj1 = ConstantRateJump(rate1, affect1!)
crj2 = ConstantRateJump(rate2, affect2!)
g = DiscreteFunction((du,u,p,t) -> nothing; syms = [:a, :b], paramsyms = [:p1, :p2])
dprob = DiscreteProblem(g, [0, 10], (0.0, 10.0), [1.0, 2.0]; syms = [:a, :b], paramsyms = [:p1, :p2])
jprob = JumpProblem(dprob, Direct(), crj1, crj2)

# runs the tests
@test jprob[:a] == 0
@test jprob[:b] == 10
@test jprob[:p1] == 1.0
@test jprob[:p2] == 2.0
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ using JumpProcesses, DiffEqBase, SafeTestsets
@time @safetestset "Spatial A + B <--> C" begin include("spatial/ABC.jl") end
@time @safetestset "Spatially Varying Reaction Rates" begin include("spatial/spatial_majump.jl") end
@time @safetestset "Pure diffusion" begin include("spatial/diffusion.jl") end
@time @safetestset "Symbol based problem indexing" begin include("jprob_symbol_indexing.jl") end
end

0 comments on commit c163962

Please sign in to comment.