@@ -369,6 +369,9 @@ function make_reaction_system(ex::Expr; name = :(gensym(:ReactionSystem)))
369
369
parameters_declared = extract_syms (options, :parameters )
370
370
variables = extract_syms (options, :variables )
371
371
372
+ # Handles a (potential) noise scaling parameter.
373
+ # nosie_scaling_p_args = handle_noise_scaling_ps!(parameters_declared, options)
374
+
372
375
# handle independent variables
373
376
if haskey (options, :ivs )
374
377
ivs = Tuple (extract_syms (options, :ivs ))
@@ -391,7 +394,7 @@ function make_reaction_system(ex::Expr; name = :(gensym(:ReactionSystem)))
391
394
declared_syms)
392
395
species = vcat (species_declared, species_extracted)
393
396
parameters = vcat (parameters_declared, parameters_extracted)
394
-
397
+
395
398
# Checks for input errors.
396
399
(sum (length .([reaction_lines, option_lines])) != length (ex. args)) &&
397
400
error (" @reaction_network input contain $(length (ex. args) - sum (length .([reaction_lines,option_lines]))) malformed lines." )
@@ -414,6 +417,7 @@ function make_reaction_system(ex::Expr; name = :(gensym(:ReactionSystem)))
414
417
push! (rxexprs. args, get_rxexprs (reaction))
415
418
end
416
419
420
+ # Returns the rephrased expression.
417
421
quote
418
422
$ ps
419
423
$ ivexpr
@@ -556,8 +560,22 @@ function get_pexpr(parameters_extracted, options)
556
560
pexprs = (haskey (options, :parameters ) ? options[:parameters ] :
557
561
(isempty (parameters_extracted) ? :() : :(@parameters )))
558
562
foreach (p -> push! (pexprs. args, p), parameters_extracted)
563
+ append! (pexprs. args, get_noise_scaling_pexpr (options))
559
564
pexprs
560
565
end
566
+ # Extracts any decalred nosie scaling parameters.
567
+ function get_noise_scaling_pexpr (options)
568
+ haskey (options, :noise_scaling_parameters ) || return []
569
+ ns_expr = options[:noise_scaling_parameters ]
570
+ for idx = length (ns_expr. args): - 1 : 3
571
+ if ns_expr. args[idx] isa Symbol
572
+ insert! (ns_expr. args, idx+ 1 , :([noisescalingparameter= true ]))
573
+ elseif (ns_expr. args[idx] isa Expr) && (ns_expr. args[idx]. head == :ref )
574
+ insert! (ns_expr. args, idx+ 1 , :([noisescalingparameter= true ]))
575
+ end
576
+ end
577
+ return ns_expr. args[3 : end ]
578
+ end
561
579
562
580
# Creates the reaction vector declaration statement.
563
581
function get_rxexprs (rxstruct)
@@ -811,6 +829,21 @@ function recursive_expand_functions!(expr::ExprValues)
811
829
expr
812
830
end
813
831
832
+ # ## Option Handling ###
833
+
834
+ # Extracts any potential nosie scaling parameters and add them to teh decalred parameters.
835
+ function add_noise_scaling_ps! (parameters_declared, options)
836
+ haskey (options, :noise_scaling_parameters ) || return
837
+ for arg in options[:noise_scaling_parameters ]. args[end : - 1 : 3 ]
838
+ if arg isa Symbol
839
+ push! (parameters_declared, arg)
840
+ elseif arg isa Expr
841
+ push! (parameters_declared, arg. args[1 ])
842
+ end
843
+ end
844
+ end
845
+
846
+
814
847
# ### Old functions (for deleting).
815
848
816
849
# function get_rx_species_deletethis(rxs, ps)
0 commit comments