@@ -7,6 +7,9 @@ using Catalyst, Statistics, StochasticDiffEq, Test
7
7
using StableRNGs
8
8
rng = StableRNG (123456 )
9
9
10
+ # Sets the default `t` to use.
11
+ t = default_t ()
12
+
10
13
# Fetch test functions and networks.
11
14
include (" ../test_functions.jl" )
12
15
include (" ../test_networks.jl" )
@@ -315,30 +318,61 @@ let
315
318
end
316
319
end
317
320
321
+ # Tests noise scaling is added properly for programmatically created system.
322
+ # Tests noise scaling for interpolation into the `@reaction macro`.
323
+ # Tests that species, variables, and parameters are extracted from noise scaling metadata when
324
+ # `ReactionSystems`s are declared programmatically.
325
+ let
326
+ # Programmatically creates a model with noise scaling.
327
+ t = default_t ()
328
+ @species X (t) H (t)
329
+ @variables h (t)
330
+ @parameters p d η
331
+ rx1 = Reaction (p, nothing , [X]; metadata = [:noise_scaling => η* H + 1 ])
332
+ rx2 = @reaction d, X --> 0 , [noise_scaling= $ h]
333
+ @named rs = ReactionSystem ([rx1, rx2], t)
334
+
335
+ # Checks that noise scaling has been added correctly.
336
+ @test issetequal ([X, H], species (rs))
337
+ @test issetequal ([X, H, h], unknowns (rs))
338
+ @test issetequal ([p, d, η], parameters (rs))
339
+ @test isequal (get_noise_scaling (reactions (rs)[1 ]), η* H + 1 )
340
+ @test isequal (get_noise_scaling (reactions (rs)[2 ]), h)
341
+ end
342
+
318
343
# Tests the `remake_noise_scaling` function.
344
+ # Checks a parameter part of the initial system is added properly.
345
+ # Checks that parameters, variables, and species not part of the original system are added properly.
319
346
let
320
347
# Creates noise scaling networks.
321
348
noise_scaling_network1 = @reaction_network begin
349
+ @parameters η1
322
350
p, 0 --> X, [noise_scaling= 2.0 ]
323
351
d, X --> 0
324
352
end
325
- noise_scaling_network2 = set_default_noise_scaling (noise_scaling_network1, 0.5 )
326
-
327
- # Checks that the two networks' reactions have the correct metadata.
328
- @test reactions (noise_scaling_network1)[1 ]. metadata == [:noise_scaling => 2.0 ]
329
- @test reactions (noise_scaling_network1)[2 ]. metadata == []
330
- @test reactions (noise_scaling_network2)[1 ]. metadata == [:noise_scaling => 2.0 ]
331
- @test reactions (noise_scaling_network2)[2 ]. metadata == [:noise_scaling => 0.5 ]
353
+ @unpack p, d, η1, X = noise_scaling_network1
354
+ @parameters η2
355
+ @species Y (t)
356
+ @variables V (t)
357
+
358
+ noise_scaling_network2 = set_default_noise_scaling (noise_scaling_network1, η1 + η2 + Y + V)
359
+ @test isequal (reactions (noise_scaling_network2)[1 ]. metadata, [:noise_scaling => 2.0 ])
360
+ @test isequal (reactions (noise_scaling_network2)[2 ]. metadata, [:noise_scaling => η1 + η2 + Y + V])
361
+ @test issetequal ([p, d, η1, η2], parameters (noise_scaling_network2))
362
+ @test issetequal ([X, Y], species (noise_scaling_network2))
363
+ @test issetequal ([X, Y, V], unknowns (noise_scaling_network2))
364
+ @test issetequal ([V], nonspecies (noise_scaling_network2))
332
365
end
333
366
334
367
# Tests the `remake_noise_scaling` function on a hierarchical model.
335
- let
368
+ # Checks that species, variables, and parameters not part of the original system is added properly.
369
+ let
336
370
# Creates hierarchical model.
337
- rn1 = @reaction_network begin
371
+ rn1 = @reaction_network rn1 begin
338
372
p, 0 --> X, [noise_scaling= 2.0 ]
339
373
d, X --> 0
340
374
end
341
- rn2 = @reaction_network begin
375
+ rn2 = @reaction_network rn2 begin
342
376
k1, X1 --> X2, [noise_scaling= 5.0 ]
343
377
k2, X2 --> X1
344
378
end
355
389
end
356
390
357
391
392
+
358
393
# ## Other Tests ###
359
394
360
395
# Tests simulating a network without parameters.
0 commit comments