From c4e3bee9bf1dba3b88e9810c29045c563e23826b Mon Sep 17 00:00:00 2001 From: Sam Isaacson Date: Sat, 30 Dec 2023 15:39:11 -0500 Subject: [PATCH 1/8] drop tests for indexing problem with a parameter --- src/problem.jl | 9 ++++++--- test/jprob_symbol_indexing.jl | 9 +++++---- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/problem.jl b/src/problem.jl index 67f8045c..8423ec1c 100644 --- a/src/problem.jl +++ b/src/problem.jl @@ -122,9 +122,12 @@ 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 + + # since parameters are no longer allowed to be mutated and the preceding will error this + # isn't needed + # if using_params(prob.massaction_jump) + # update_parameters!(prob.massaction_jump, prob.prob.p) + # end end # when getindex is used. diff --git a/test/jprob_symbol_indexing.jl b/test/jprob_symbol_indexing.jl index 15a53f99..59bc373b 100644 --- a/test/jprob_symbol_indexing.jl +++ b/test/jprob_symbol_indexing.jl @@ -6,14 +6,15 @@ 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]) +g = DiscreteFunction((du, u, p, t) -> nothing; syms = [:a, :b]) +# 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]) 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 -# tests for setindex (e.g. `jprob[:a] = 10`) not possible, this requires the problem to have a .f.sys filed., +# these are no longer supported by SciMLBase +# @test jprob[:p1] == 1.0 +# @test jprob[:p2] == 2.0 From d99890da3251476f9b04eb258400be56e2a682f4 Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Sun, 31 Dec 2023 09:08:17 -0500 Subject: [PATCH 2/8] Update jprob_symbol_indexing.jl --- test/jprob_symbol_indexing.jl | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/test/jprob_symbol_indexing.jl b/test/jprob_symbol_indexing.jl index 59bc373b..ad7f7bdc 100644 --- a/test/jprob_symbol_indexing.jl +++ b/test/jprob_symbol_indexing.jl @@ -6,8 +6,7 @@ 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]) -# g = DiscreteFunction((du, u, p, t) -> nothing; syms = [:a, :b], paramsyms = [:p1, :p2]) +g = DiscreteFunction((du, u, p, t) -> nothing; sys = SymbolicIndexingInterface.SymbolCache([:a, :b], [:p1, :p2], :t) dprob = DiscreteProblem(g, [0, 10], (0.0, 10.0), [1.0, 2.0]) jprob = JumpProblem(dprob, Direct(), crj1, crj2) @@ -16,5 +15,5 @@ jprob = JumpProblem(dprob, Direct(), crj1, crj2) @test jprob[:b] == 10 # these are no longer supported by SciMLBase -# @test jprob[:p1] == 1.0 -# @test jprob[:p2] == 2.0 +@test getp(jprob,:p1)(jprob) == 1.0 +@test getp(jprob,:p2)(jprob) == 2.0 From a80abc68992dc0c6432ed4076e45cb36b96a3810 Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Sun, 31 Dec 2023 11:12:57 -0500 Subject: [PATCH 3/8] Update test/jprob_symbol_indexing.jl --- test/jprob_symbol_indexing.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/jprob_symbol_indexing.jl b/test/jprob_symbol_indexing.jl index ad7f7bdc..201a8c69 100644 --- a/test/jprob_symbol_indexing.jl +++ b/test/jprob_symbol_indexing.jl @@ -6,7 +6,7 @@ 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; sys = SymbolicIndexingInterface.SymbolCache([:a, :b], [:p1, :p2], :t) +g = DiscreteFunction((du, u, p, t) -> nothing; sys = SymbolicIndexingInterface.SymbolCache([:a, :b], [:p1, :p2], :t)) dprob = DiscreteProblem(g, [0, 10], (0.0, 10.0), [1.0, 2.0]) jprob = JumpProblem(dprob, Direct(), crj1, crj2) From bd4898297b36c207bd409e18489e6b261d6d90aa Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Sun, 31 Dec 2023 12:52:35 -0500 Subject: [PATCH 4/8] bumps for the new LTS --- .github/workflows/CI.yml | 1 - Project.toml | 14 +++++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 71f27f8c..a75f4e85 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -19,7 +19,6 @@ jobs: - Core version: - '1' - - '1.6' steps: - uses: actions/checkout@v4 - uses: julia-actions/setup-julia@v1 diff --git a/Project.toml b/Project.toml index ea68f6a9..8b70577a 100644 --- a/Project.toml +++ b/Project.toml @@ -28,20 +28,20 @@ FastBroadcast = "7034ab61-46d4-4ed7-9d0f-46aef9175898" JumpProcessFastBroadcastExt = "FastBroadcast" [compat] -ArrayInterface = "6, 7" -DataStructures = "0.17, 0.18" +ArrayInterface = "7" +DataStructures = "0.18" DiffEqBase = "6.122" -DocStringExtensions = "0.8.6, 0.9" +DocStringExtensions = "0.9" FunctionWrappers = "1.0" Graphs = "1.4" PoissonRandom = "0.4" RandomNumbers = "1.3" -RecursiveArrayTools = "2, 3" -Reexport = "0.2, 1.0" +RecursiveArrayTools = "3" +Reexport = "1.0" SciMLBase = "1.51, 2" -StaticArrays = "0.10, 0.11, 0.12, 1.0" +StaticArrays = "1.0" UnPack = "1.0.2" -julia = "1.6" +julia = "1.10" [extras] DiffEqCallbacks = "459566f4-90b8-5000-8ac3-15dfb0a30def" From 77995f7efc515c3eb9984eaca3f73822ef7794b8 Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Thu, 25 Jan 2024 00:52:48 -0500 Subject: [PATCH 5/8] Update test/jprob_symbol_indexing.jl Co-authored-by: Aayush Sabharwal --- test/jprob_symbol_indexing.jl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/jprob_symbol_indexing.jl b/test/jprob_symbol_indexing.jl index 201a8c69..5428770c 100644 --- a/test/jprob_symbol_indexing.jl +++ b/test/jprob_symbol_indexing.jl @@ -17,3 +17,5 @@ jprob = JumpProblem(dprob, Direct(), crj1, crj2) # these are no longer supported by SciMLBase @test getp(jprob,:p1)(jprob) == 1.0 @test getp(jprob,:p2)(jprob) == 2.0 +@test jprob.ps[:p1] == 1.0 +@test jprob.ps[:p2] == 2.0 From 7a279c6a48edbc41ec76c890558ead80b27c80b9 Mon Sep 17 00:00:00 2001 From: Sam Isaacson Date: Wed, 20 Mar 2024 11:57:59 -0400 Subject: [PATCH 6/8] Auto stash before merge of "pr/387" and "origin/master" --- src/aggregators/coevolve.jl | 2 +- src/aggregators/ssajump.jl | 3 +-- src/problem.jl | 16 ++++++---------- 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/src/aggregators/coevolve.jl b/src/aggregators/coevolve.jl index 82e8beb9..9aca9480 100644 --- a/src/aggregators/coevolve.jl +++ b/src/aggregators/coevolve.jl @@ -69,7 +69,7 @@ end # executing jump at the next jump time function (p::CoevolveJumpAggregation)(integrator::I) where {I <: - AbstractSSAIntegrator} + AbstractSSAIntegrator} if !accept_next_jump!(p, integrator, integrator.u, integrator.p, integrator.t) return nothing end diff --git a/src/aggregators/ssajump.jl b/src/aggregators/ssajump.jl index 3f6df60a..035ab008 100644 --- a/src/aggregators/ssajump.jl +++ b/src/aggregators/ssajump.jl @@ -56,8 +56,7 @@ end end @inline function concretize_affects!(p::AbstractSSAJumpAggregator{T, S, F1, F2}, - ::I) where {T, S, F1, F2 <: Tuple, - I <: DiffEqBase.DEIntegrator} + ::I) where {T, S, F1, F2 <: Tuple, I <: DiffEqBase.DEIntegrator} nothing end diff --git a/src/problem.jl b/src/problem.jl index e5310b0e..18159f29 100644 --- a/src/problem.jl +++ b/src/problem.jl @@ -154,14 +154,12 @@ function JumpProblem(prob, jumps::AbstractJump...; kwargs...) JumpProblem(prob, JumpSet(jumps...); kwargs...) end -function JumpProblem( - prob, aggregator::AbstractAggregatorAlgorithm, jumps::ConstantRateJump; - kwargs...) +function JumpProblem(prob, aggregator::AbstractAggregatorAlgorithm, + jumps::ConstantRateJump; kwargs...) JumpProblem(prob, aggregator, JumpSet(jumps); kwargs...) end -function JumpProblem( - prob, aggregator::AbstractAggregatorAlgorithm, jumps::VariableRateJump; - kwargs...) +function JumpProblem(prob, aggregator::AbstractAggregatorAlgorithm, + jumps::VariableRateJump; kwargs...) JumpProblem(prob, aggregator, JumpSet(jumps); kwargs...) end function JumpProblem(prob, aggregator::AbstractAggregatorAlgorithm, jumps::RegularJump; @@ -324,8 +322,7 @@ function extend_problem(prob::DiffEqBase.AbstractSDEProblem, jumps; rng = DEFAUL end ttype = eltype(prob.tspan) - u0 = ExtendedJumpArray(prob.u0, - [-randexp(rng, ttype) for i in 1:length(jumps)]) + u0 = ExtendedJumpArray(prob.u0, [-randexp(rng, ttype) for i in 1:length(jumps)]) remake(prob, f = SDEFunction{isinplace(prob)}(jump_f, jump_g), g = jump_g, u0 = u0) end @@ -350,8 +347,7 @@ function extend_problem(prob::DiffEqBase.AbstractDDEProblem, jumps; rng = DEFAUL end ttype = eltype(prob.tspan) - u0 = ExtendedJumpArray(prob.u0, - [-randexp(rng, ttype) for i in 1:length(jumps)]) + u0 = ExtendedJumpArray(prob.u0, [-randexp(rng, ttype) for i in 1:length(jumps)]) remake(prob, f = DDEFunction{isinplace(prob)}(jump_f), u0 = u0) end From dbd37f6b0eb6a3b77d8a8b552979bea822668544 Mon Sep 17 00:00:00 2001 From: Sam Isaacson Date: Wed, 20 Mar 2024 13:13:40 -0400 Subject: [PATCH 7/8] fix problem symbolic indexing --- Project.toml | 18 ++++++++++-------- src/JumpProcesses.jl | 1 + src/problem.jl | 13 ++++++++----- test/jprob_symbol_indexing.jl | 27 +++++++++++++++++++++------ 4 files changed, 40 insertions(+), 19 deletions(-) diff --git a/Project.toml b/Project.toml index 8b70577a..00277cb0 100644 --- a/Project.toml +++ b/Project.toml @@ -19,6 +19,7 @@ RecursiveArrayTools = "731186ca-8d62-57ce-b412-fbd966d074cd" Reexport = "189a3867-3050-52da-a836-e630ba90ab69" SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462" StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" +SymbolicIndexingInterface = "2efcf032-c050-4f8e-a9bb-153293bab1f5" UnPack = "3a884ed6-31ef-47d7-9d2a-63182c4928ed" [weakdeps] @@ -28,18 +29,19 @@ FastBroadcast = "7034ab61-46d4-4ed7-9d0f-46aef9175898" JumpProcessFastBroadcastExt = "FastBroadcast" [compat] -ArrayInterface = "7" +ArrayInterface = "7.9" DataStructures = "0.18" -DiffEqBase = "6.122" +DiffEqBase = "6.148" DocStringExtensions = "0.9" -FunctionWrappers = "1.0" -Graphs = "1.4" +FunctionWrappers = "1.1" +Graphs = "1.9" PoissonRandom = "0.4" -RandomNumbers = "1.3" -RecursiveArrayTools = "3" +RandomNumbers = "1.5" +RecursiveArrayTools = "3.12" Reexport = "1.0" -SciMLBase = "1.51, 2" -StaticArrays = "1.0" +SciMLBase = "2.30.1" +StaticArrays = "1.9" +SymbolicIndexingInterface = "0.3.11" UnPack = "1.0.2" julia = "1.10" diff --git a/src/JumpProcesses.jl b/src/JumpProcesses.jl index ed35ae5f..0fd0d878 100644 --- a/src/JumpProcesses.jl +++ b/src/JumpProcesses.jl @@ -17,6 +17,7 @@ import Graphs: neighbors, outdegree import RecursiveArrayTools: recursivecopy! using StaticArrays, Base.Threads +import SymbolicIndexingInterface as SII abstract type AbstractJump end abstract type AbstractMassActionJump <: AbstractJump end diff --git a/src/problem.jl b/src/problem.jl index 18159f29..f7f6dbaf 100644 --- a/src/problem.jl +++ b/src/problem.jl @@ -122,12 +122,15 @@ end # when setindex! is used. function Base.setindex!(prob::JumpProblem, args...; kwargs...) SciMLBase.___internal_setindex!(prob.prob, args...; kwargs...) +end + +# for updating parameters in JumpProblems to update MassActionJumps +function SII.set_parameter!(prob::JumpProblem, val, idx) + ans = SII.set_parameter!(SII.parameter_values(prob), val, idx) - # since parameters are no longer allowed to be mutated and the preceding will error this - # isn't needed - # if using_params(prob.massaction_jump) - # update_parameters!(prob.massaction_jump, prob.prob.p) - # end + if using_params(prob.massaction_jump) + update_parameters!(prob.massaction_jump, prob.prob.p) + end end # when getindex is used. diff --git a/test/jprob_symbol_indexing.jl b/test/jprob_symbol_indexing.jl index 5428770c..0ae4d488 100644 --- a/test/jprob_symbol_indexing.jl +++ b/test/jprob_symbol_indexing.jl @@ -1,21 +1,36 @@ # prepares the problem -using JumpProcesses, Test +using JumpProcesses, Test, SymbolicIndexingInterface 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; sys = SymbolicIndexingInterface.SymbolCache([:a, :b], [:p1, :p2], :t)) +maj = MassActionJump([[1 => 1], [1 => 1]], [[1 => -1], [1 => -1]]; param_idxs = [1,2]) +g = DiscreteFunction((du, u, p, t) -> nothing; + sys = SymbolicIndexingInterface.SymbolCache([:a, :b], [:p1, :p2], :t)) dprob = DiscreteProblem(g, [0, 10], (0.0, 10.0), [1.0, 2.0]) -jprob = JumpProblem(dprob, Direct(), crj1, crj2) +jprob = JumpProblem(dprob, Direct(), crj1, crj2, maj) -# runs the tests +# test basic querying of u0 and p @test jprob[:a] == 0 @test jprob[:b] == 10 - -# these are no longer supported by SciMLBase @test getp(jprob,:p1)(jprob) == 1.0 @test getp(jprob,:p2)(jprob) == 2.0 @test jprob.ps[:p1] == 1.0 @test jprob.ps[:p2] == 2.0 + +# test updating u0 +jprob[:a] = 20 +@test jprob[:a] == 20 + +# test mass action jumps update with parameter mutation in problems +@test jprob.massaction_jump.scaled_rates[1] == 1.0 +jprob.ps[:p1] = 3.0 +@test jprob.ps[:p1] == 3.0 +@test jprob.massaction_jump.scaled_rates[1] == 3.0 +p1setter = setp(jprob, [:p1, :p2]) +p1setter(jprob, [4.0, 10.0]) +@test jprob.ps[:p1] == 4.0 +@test jprob.ps[:p2] == 10.0 +@test jprob.massaction_jump.scaled_rates == [4.0, 10.0] From 0f14821c1b2c37136eaea87eeea3681f02febd8c Mon Sep 17 00:00:00 2001 From: Sam Isaacson Date: Wed, 20 Mar 2024 13:16:14 -0400 Subject: [PATCH 8/8] return set_parameter! returns --- src/problem.jl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/problem.jl b/src/problem.jl index f7f6dbaf..9b4eccdf 100644 --- a/src/problem.jl +++ b/src/problem.jl @@ -131,6 +131,8 @@ function SII.set_parameter!(prob::JumpProblem, val, idx) if using_params(prob.massaction_jump) update_parameters!(prob.massaction_jump, prob.prob.p) end + + ans end # when getindex is used.