@@ -8,23 +8,7 @@ function regular_rate(out, u, p, t)
88 out[2 ] = 0.01 u[2 ]
99end
1010
11- function regular_c (dc, u, p, t, mark)
12- dc[1 , 1 ] = - 1
13- dc[2 , 1 ] = 1
14- dc[2 , 2 ] = - 1
15- dc[3 , 2 ] = 1
16- end
17-
18- dc = zeros (3 , 2 )
19-
20- rj = RegularJump (regular_rate, regular_c, dc; constant_c = true )
21- jumps = JumpSet (rj)
22-
23- prob = DiscreteProblem ([999.0 , 1.0 , 0.0 ], (0.0 , 250.0 ))
24- jump_prob = JumpProblem (prob, Direct (), rj; rng = rng)
25- sol = solve (jump_prob, SimpleTauLeaping (); dt = 1.0 )
26-
27- const _dc = zeros (3 , 2 )
11+ const dc = zeros (3 , 2 )
2812dc[1 , 1 ] = - 1
2913dc[2 , 1 ] = 1
3014dc[2 , 2 ] = - 1
3721rj = RegularJump (regular_rate, regular_c, 2 )
3822jumps = JumpSet (rj)
3923prob = DiscreteProblem ([999 , 1 , 0 ], (0.0 , 250.0 ))
40- jump_prob = JumpProblem (prob, Direct (), rj; rng = rng)
24+ jump_prob = JumpProblem (prob, PureLeaping (), rj; rng)
4125sol = solve (jump_prob, SimpleTauLeaping (); dt = 1.0 )
26+
27+ # Test PureLeaping aggregator functionality
28+ @testset " PureLeaping Aggregator Tests" begin
29+ # Test with MassActionJump
30+ u0 = [10 , 5 , 0 ]
31+ tspan = (0.0 , 10.0 )
32+ p = [0.1 , 0.2 ]
33+ prob = DiscreteProblem (u0, tspan, p)
34+
35+ # Create MassActionJump
36+ reactant_stoich = [[1 => 1 ], [1 => 2 ]]
37+ net_stoich = [[1 => - 1 , 2 => 1 ], [1 => - 2 , 3 => 1 ]]
38+ rates = [0.1 , 0.05 ]
39+ maj = MassActionJump (rates, reactant_stoich, net_stoich)
40+
41+ # Test PureLeaping JumpProblem creation
42+ jp_pure = JumpProblem (prob, PureLeaping (), JumpSet (maj))
43+ @test jp_pure. aggregator isa PureLeaping
44+ @test jp_pure. discrete_jump_aggregation === nothing
45+ @test jp_pure. massaction_jump != = nothing
46+ @test length (jp_pure. jump_callback. discrete_callbacks) == 0
47+
48+ # Test with ConstantRateJump
49+ rate (u, p, t) = p[1 ] * u[1 ]
50+ affect! (integrator) = (integrator. u[1 ] -= 1 ; integrator. u[3 ] += 1 )
51+ crj = ConstantRateJump (rate, affect!)
52+
53+ jp_pure_crj = JumpProblem (prob, PureLeaping (), JumpSet (crj))
54+ @test jp_pure_crj. aggregator isa PureLeaping
55+ @test jp_pure_crj. discrete_jump_aggregation === nothing
56+ @test length (jp_pure_crj. constant_jumps) == 1
57+
58+ # Test with VariableRateJump
59+ vrate (u, p, t) = t * p[1 ] * u[1 ]
60+ vaffect! (integrator) = (integrator. u[1 ] -= 1 ; integrator. u[3 ] += 1 )
61+ vrj = VariableRateJump (vrate, vaffect!)
62+
63+ jp_pure_vrj = JumpProblem (prob, PureLeaping (), JumpSet (vrj))
64+ @test jp_pure_vrj. aggregator isa PureLeaping
65+ @test jp_pure_vrj. discrete_jump_aggregation === nothing
66+ @test length (jp_pure_vrj. variable_jumps) == 1
67+
68+ # Test with RegularJump
69+ function rj_rate (out, u, p, t)
70+ out[1 ] = p[1 ] * u[1 ]
71+ end
72+
73+ rj_dc = zeros (3 , 1 )
74+ rj_dc[1 , 1 ] = - 1
75+ rj_dc[3 , 1 ] = 1
76+
77+ function rj_c (du, u, p, t, counts, mark)
78+ mul! (du, rj_dc, counts)
79+ end
80+
81+ regj = RegularJump (rj_rate, rj_c, 1 )
82+
83+ jp_pure_regj = JumpProblem (prob, PureLeaping (), JumpSet (regj))
84+ @test jp_pure_regj. aggregator isa PureLeaping
85+ @test jp_pure_regj. discrete_jump_aggregation === nothing
86+ @test jp_pure_regj. regular_jump != = nothing
87+
88+ # Test mixed jump types
89+ mixed_jumps = JumpSet (; massaction_jumps = maj, constant_jumps = (crj,),
90+ variable_jumps = (vrj,), regular_jumps = regj)
91+ jp_pure_mixed = JumpProblem (prob, PureLeaping (), mixed_jumps)
92+ @test jp_pure_mixed. aggregator isa PureLeaping
93+ @test jp_pure_mixed. discrete_jump_aggregation === nothing
94+ @test jp_pure_mixed. massaction_jump != = nothing
95+ @test length (jp_pure_mixed. constant_jumps) == 1
96+ @test length (jp_pure_mixed. variable_jumps) == 1
97+ @test jp_pure_mixed. regular_jump != = nothing
98+
99+ # Test spatial system error
100+ spatial_sys = CartesianGrid ((2 , 2 ))
101+ hopping_consts = [1.0 ]
102+ @test_throws ErrorException JumpProblem (prob, PureLeaping (), JumpSet (maj);
103+ spatial_system = spatial_sys)
104+ @test_throws ErrorException JumpProblem (prob, PureLeaping (), JumpSet (maj);
105+ hopping_constants = hopping_consts)
106+
107+ # Test MassActionJump with parameter mapping
108+ maj_params = MassActionJump (reactant_stoich, net_stoich; param_idxs = [1 , 2 ])
109+ jp_params = JumpProblem (prob, PureLeaping (), JumpSet (maj_params))
110+ scaled_rates = [p[1 ], p[2 ]/ 2 ]
111+ @test jp_params. massaction_jump. scaled_rates == scaled_rates
112+ end
0 commit comments