Skip to content

Add @poissonians DSL option for @reaction_network and @network_component#1388

Merged
isaacsas merged 8 commits intoSciML:masterfrom
isaacsas:add_poissonians_dsl
Feb 8, 2026
Merged

Add @poissonians DSL option for @reaction_network and @network_component#1388
isaacsas merged 8 commits intoSciML:masterfrom
isaacsas:add_poissonians_dsl

Conversation

@isaacsas
Copy link
Copy Markdown
Member

@isaacsas isaacsas commented Feb 7, 2026

Requires SciML/ModelingToolkit.jl#4274 and an MTKBase release before we can test/merge.

Summary

Adds @poissonians as a DSL option in @reaction_network and @network_component, allowing users to declare poissonians inline rather than constructing them externally and interpolating.

rn = @reaction_network begin
    @parameters λ k d
    @variables X(t)
    @poissonians dN(λ)
    @equations D(X) ~ dN
    (k, d), 0 <--> S
end

Multiple poissonians and begin/end block syntax are supported:

@poissonians begin
    dN₁(λ₁)
    dN₂(λ₂)
end

Rate expressions can also be interpolated from external variables:

rate_expr = k * V
rn = @reaction_network begin
    @poissonians dN($(rate_expr))
    ...
end

Note: Symbols appearing in poissonian rates must be pre-declared (via @parameters, @species, etc.) or interpolated — they are not auto-inferred.

Depends on: A fix in ModelingToolkitBase that makes @poissonians consistently return Vector{Num} (matching @brownians behavior). Without that fix, the macro returns a scalar Num for a single poissonian and a Tuple for multiple.

Support declaring poissonians inline in the DSL via @poissonians, matching
the existing @brownians pattern. Poissonian names are added to syms_declared
to prevent inference as variables, and are passed to make_ReactionSystem_internal.
Symbols in poissonian rates must be pre-declared or interpolated.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@isaacsas isaacsas requested a review from TorkelE February 7, 2026 13:36
@isaacsas
Copy link
Copy Markdown
Member Author

isaacsas commented Feb 7, 2026

@TorkelE please give this a review to make sure you are happy with how this has modified / integrated into the DSL.

isaacsas and others added 3 commits February 7, 2026 08:38
Validates poissonian rate symbols at macro expansion time against
declared/inferred symbols, skipping interpolated subtrees. Throws
UndeclaredSymbolicError with a descriptive message for any unrecognized
symbols.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Tests that errors in non-first poissonians are caught and that multiple
undeclared symbols across poissonians are all reported in one message.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@isaacsas
Copy link
Copy Markdown
Member Author

isaacsas commented Feb 7, 2026

OK, I think this should be good modulo needing that MTK PR + a release.

Comment thread src/dsl.jl
Comment thread src/dsl.jl Outdated
Comment thread src/dsl.jl Outdated
Comment thread src/dsl.jl
isaacsas and others added 2 commits February 8, 2026 07:47
Co-authored-by: Torkel Loman <[email protected]>
Co-authored-by: Torkel Loman <[email protected]>
@isaacsas isaacsas merged commit 821eedc into SciML:master Feb 8, 2026
19 checks passed
@isaacsas isaacsas deleted the add_poissonians_dsl branch February 8, 2026 14:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants