159159
160160# Test with JumpSystem.
161161let
162- p = rand (rng, length (k))
163162 @species A (t) B (t) C (t) D (t) E (t) F (t)
164163 rxs = [Reaction (k[1 ], nothing , [A]), # 0 -> A
165164 Reaction (k[2 ], [B], nothing ), # B -> 0
@@ -193,27 +192,29 @@ let
193192 @test all (map (i -> typeof (equations (js)[i]) <: JumpProcesses.ConstantRateJump , cidxs))
194193 @test all (map (i -> typeof (equations (js)[i]) <: JumpProcesses.VariableRateJump , vidxs))
195194
196- pars = rand (rng, length (k))
195+ p = rand (rng, length (k))
196+ pmap = parameters (js) .=> p
197197 u0 = rand (rng, 2 : 10 , 6 )
198+ u0map = unknowns (js) .=> u0
198199 ttt = rand (rng)
199200 jumps = Vector {Union{ConstantRateJump, MassActionJump, VariableRateJump}} (undef,
200201 length (rxs))
201202
202- jumps[1 ] = MassActionJump (pars [1 ], Vector {Pair{Int, Int}} (), [1 => 1 ])
203- jumps[2 ] = MassActionJump (pars [2 ], [2 => 1 ], [2 => - 1 ])
204- jumps[3 ] = MassActionJump (pars [3 ], [1 => 1 ], [1 => - 1 , 3 => 1 ])
205- jumps[4 ] = MassActionJump (pars [4 ], [3 => 1 ], [1 => 1 , 2 => 1 , 3 => - 1 ])
206- jumps[5 ] = MassActionJump (pars [5 ], [3 => 1 ], [1 => 2 , 3 => - 1 ])
207- jumps[6 ] = MassActionJump (pars [6 ], [1 => 1 , 2 => 1 ], [1 => - 1 , 2 => - 1 , 3 => 1 ])
208- jumps[7 ] = MassActionJump (pars [7 ], [2 => 2 ], [1 => 1 , 2 => - 2 ])
209- jumps[8 ] = MassActionJump (pars [8 ], [1 => 1 , 2 => 1 ], [2 => - 1 , 3 => 1 ])
210- jumps[9 ] = MassActionJump (pars [9 ], [1 => 1 , 2 => 1 ], [1 => - 1 , 2 => - 1 , 3 => 1 , 4 => 1 ])
211- jumps[10 ] = MassActionJump (pars [10 ], [1 => 2 ], [1 => - 2 , 3 => 1 , 4 => 1 ])
212- jumps[11 ] = MassActionJump (pars [11 ], [1 => 2 ], [1 => - 1 , 2 => 1 ])
213- jumps[12 ] = MassActionJump (pars [12 ], [1 => 1 , 2 => 3 , 3 => 4 ],
203+ jumps[1 ] = MassActionJump (p [1 ], Vector {Pair{Int, Int}} (), [1 => 1 ])
204+ jumps[2 ] = MassActionJump (p [2 ], [2 => 1 ], [2 => - 1 ])
205+ jumps[3 ] = MassActionJump (p [3 ], [1 => 1 ], [1 => - 1 , 3 => 1 ])
206+ jumps[4 ] = MassActionJump (p [4 ], [3 => 1 ], [1 => 1 , 2 => 1 , 3 => - 1 ])
207+ jumps[5 ] = MassActionJump (p [5 ], [3 => 1 ], [1 => 2 , 3 => - 1 ])
208+ jumps[6 ] = MassActionJump (p [6 ], [1 => 1 , 2 => 1 ], [1 => - 1 , 2 => - 1 , 3 => 1 ])
209+ jumps[7 ] = MassActionJump (p [7 ], [2 => 2 ], [1 => 1 , 2 => - 2 ])
210+ jumps[8 ] = MassActionJump (p [8 ], [1 => 1 , 2 => 1 ], [2 => - 1 , 3 => 1 ])
211+ jumps[9 ] = MassActionJump (p [9 ], [1 => 1 , 2 => 1 ], [1 => - 1 , 2 => - 1 , 3 => 1 , 4 => 1 ])
212+ jumps[10 ] = MassActionJump (p [10 ], [1 => 2 ], [1 => - 2 , 3 => 1 , 4 => 1 ])
213+ jumps[11 ] = MassActionJump (p [11 ], [1 => 2 ], [1 => - 1 , 2 => 1 ])
214+ jumps[12 ] = MassActionJump (p [12 ], [1 => 1 , 2 => 3 , 3 => 4 ],
214215 [1 => - 1 , 2 => - 3 , 3 => - 2 , 4 => 3 ])
215- jumps[13 ] = MassActionJump (pars [13 ], [1 => 3 , 2 => 1 ], [1 => - 3 , 2 => - 1 ])
216- jumps[14 ] = MassActionJump (pars [14 ], Vector {Pair{Int, Int}} (), [1 => 2 ])
216+ jumps[13 ] = MassActionJump (p [13 ], [1 => 3 , 2 => 1 ], [1 => - 3 , 2 => - 1 ])
217+ jumps[14 ] = MassActionJump (p [14 ], Vector {Pair{Int, Int}} (), [1 => 2 ])
217218
218219 jumps[15 ] = ConstantRateJump ((u, p, t) -> p[15 ] * u[1 ] / (2 + u[1 ]),
219220 integrator -> (integrator. u[1 ] -= 1 ))
@@ -230,32 +231,34 @@ let
230231 integrator -> (integrator. u[4 ] -= 2 ; integrator. u[5 ] -= 1 ; integrator. u[6 ] += 2 ))
231232
232233 unknownoid = Dict (unknown => i for (i, unknown) in enumerate (unknowns (js)))
233- jspmapper = ModelingToolkit. JumpSysMajParamMapper (js, pars)
234+ dprob = DiscreteProblem (js, u0map, (0.0 , 10.0 ), pmap)
235+ mtkpars = dprob. p
236+ jspmapper = ModelingToolkit. JumpSysMajParamMapper (js, mtkpars)
234237 symmaj = ModelingToolkit. assemble_maj (equations (js). x[1 ], unknownoid, jspmapper)
235- maj = MassActionJump (symmaj. param_mapper (pars ), symmaj. reactant_stoch, symmaj. net_stoch,
238+ maj = MassActionJump (symmaj. param_mapper (mtkpars ), symmaj. reactant_stoch, symmaj. net_stoch,
236239 symmaj. param_mapper, scale_rates = false )
237240 for i in midxs
238- @test_broken abs (jumps[i]. scaled_rates - maj. scaled_rates[i]) < 100 * eps ()
241+ @test abs (jumps[i]. scaled_rates - maj. scaled_rates[i]) < 100 * eps ()
239242 @test jumps[i]. reactant_stoch == maj. reactant_stoch[i]
240243 @test jumps[i]. net_stoch == maj. net_stoch[i]
241244 end
242245 for i in cidxs
243246 crj = ModelingToolkit. assemble_crj (js, equations (js)[i], unknownoid)
244- @test_broken isapprox (crj. rate (u0, p , ttt), jumps[i]. rate (u0, p, ttt))
245- fake_integrator1 = (u = zeros (6 ), p = p , t = 0.0 )
246- fake_integrator2 = deepcopy (fake_integrator1 )
247+ @test isapprox (crj. rate (u0, mtkpars , ttt), jumps[i]. rate (u0, p, ttt))
248+ fake_integrator1 = (u = zeros (6 ), p = mtkpars , t = 0.0 )
249+ fake_integrator2 = (u = zeros ( 6 ), p, t = 0.0 )
247250 crj. affect! (fake_integrator1)
248251 jumps[i]. affect! (fake_integrator2)
249- @test fake_integrator1 == fake_integrator2
252+ @test fake_integrator1. u == fake_integrator2. u
250253 end
251254 for i in vidxs
252255 crj = ModelingToolkit. assemble_vrj (js, equations (js)[i], unknownoid)
253- @test_broken isapprox (crj. rate (u0, p , ttt), jumps[i]. rate (u0, p, ttt))
254- fake_integrator1 = (u = zeros (6 ), p = p , t = 0.0 )
255- fake_integrator2 = deepcopy (fake_integrator1 )
256+ @test isapprox (crj. rate (u0, mtkpars , ttt), jumps[i]. rate (u0, p, ttt))
257+ fake_integrator1 = (u = zeros (6 ), p = mtkpars , t = 0.0 )
258+ fake_integrator2 = (u = zeros ( 6 ), p, t = 0.0 )
256259 crj. affect! (fake_integrator1)
257260 jumps[i]. affect! (fake_integrator2)
258- @test fake_integrator1 == fake_integrator2
261+ @test fake_integrator1. u == fake_integrator2. u
259262 end
260263end
261264
439442 umean += sol (10.0 , idxs = [B1, B2, B3, C])
440443 end
441444 umean /= Nsims
442- @test isapprox (umean[1 ], umean[2 ]; rtol = 1e-2 )
445+ @test isapprox (umean[1 ], umean[2 ]; rtol = 1e-2 )
443446 @test isapprox (umean[1 ], umean[3 ]; rtol = 1e-2 )
444447 @test umean[4 ] == 10
445448end
0 commit comments