@@ -198,15 +198,37 @@ function find_jump_vars!(ps, us, jumps::Vector, t)
198198 for jump in jumps
199199 MT. collect_vars! (us, ps, jump, t)
200200 end
201+ return
202+ end
203+
204+ function collect_symbolic_expression_vars! (us, ps, expr, t)
205+ for var in Symbolics. get_variables (expr)
206+ var = unwrap (var)
207+ isequal (var, t) && continue
208+ if MT. isparameter (var)
209+ push! (ps, var)
210+ else
211+ push! (us, var)
212+ end
213+ end
214+ return nothing
215+ end
216+
217+ function find_poissonian_vars! (ps, us, poissonians:: Vector , t)
218+ for poissonian in poissonians
219+ collect_symbolic_expression_vars! (us, ps, MT. getpoissonianrate (poissonian), t)
220+ end
221+ return
201222end
202223
203224# Loops through all tstop expressions, adding encountered unknowns and parameters
204225# to their respective vectors (`ps` and `us`). Unwraps each expression (Num → SymbolicT)
205- # so that `collect_vars!` can traverse it.
226+ # before collecting symbolic variables from it.
206227function find_tstop_vars! (ps, us, tstops:: Vector , t)
207228 for ts in tstops
208- MT . collect_vars ! (us, ps, unwrap (ts), t)
229+ collect_symbolic_expression_vars ! (us, ps, unwrap (ts), t)
209230 end
231+ return
210232end
211233
212234# Validates that tstop expressions only contain parameters and constants (no unknowns or
@@ -229,7 +251,7 @@ function check_tstops(tstops, unknowns, iv)
229251 # Check that no unknowns (species/variables) appear in the tstop expression.
230252 empty! (found_us)
231253 empty! (found_ps)
232- MT . collect_vars ! (found_us, found_ps, tsu, iv)
254+ collect_symbolic_expression_vars ! (found_us, found_ps, tsu, iv)
233255 for v in found_us
234256 if v in unknowns_set
235257 throw (ArgumentError (" Tstop expression `$ts ` contains unknown `$v `. Tstops must only depend on parameters and constants, not dynamic state." ))
@@ -648,13 +670,16 @@ function make_ReactionSystem_internal(rxs_and_eqs::Vector, iv, us_in, ps_in, bro
648670 # Loops through all jumps, adding encountered quantities to the unknown and parameter vectors.
649671 find_jump_vars! (ps, us, jumps, t)
650672
673+ # Loops through all poissonians, adding encountered quantities in their rate expressions.
674+ find_poissonian_vars! (ps, us, poissonians, t)
675+
651676 # Loops through all tstop expressions, adding encountered quantities to the unknown and parameter vectors.
652677 find_tstop_vars! (ps, us, tstops, t)
653678
654679 # Discover parameters/unknowns from observed equation RHS.
655680 # Only process RHS to avoid adding observable LHS to unknowns (observables stay observables).
656681 for eq in observed
657- MT . collect_vars ! (us, ps, eq. rhs, t)
682+ collect_symbolic_expression_vars ! (us, ps, eq. rhs, t)
658683 end
659684
660685 # Converts the found unknowns and parameters to vectors.
0 commit comments