ITADN

Imperative events in the DSL

#1335Openkaandocal 创建于 2025-11-09
K
kaandocalcommented
Hey, first of all - massive congratulations on all this work over the past few years! The amount of supported functionality added over the past year or two is crazy, and I'm really enjoying the current version! As I may have gone a bit overboard with my modelling I ran into a small problem recently (bug/feature request?). Namely, I want to use the experimental `MTK.ImperativeAffect` interface within the DSL, which does not seem to be supported: ```julia function affect(x, obs, ctx, int) dX = rand(Poisson(1)) @set! x.X = x.X + dX end rn = @reaction_network begin k, 0 --> X @discrete_events begin 1.0 => affect end end ``` This throws the following error: ``` The affect part of all events (the right-hand side) must be a vector. This is not the case for: affect. ``` in `Catalyst.read_events_option`. This is because the DSL expects affects of the form `[ X ~ X + 1 ]`, even though MTK supports more general affect functions. My current solution is: * hack the code for `Catalyst.read_events_option` to remove those checks * create `affect_wrapper = MTK.ImperativeAffect(...)` wrapping the affect function * use the line `1.0 => $affect_wrapper` This seems to work, but is messy. Any chance one could incorporate this into the DSL by fine-tuning these checks? Alternatively, is there a convenient way of adding events to an existing reaction system (copies are fine)? It seems like I'd have to manually recreate one to do so, which involves copying a lot of fields and is very reliant on Catalyst internals... As an extension, I'd like to have random times between these events. I might be able to concoct something using JumpProcesses, but is there an easier way to do this with newer versions?
2 条评论