SciML / Catalyst.jl

Chemical reaction network and systems biology interface for scientific machine learning (SciML). High performance, GPU-parallelized, and O(1) solvers in open source software.
https://docs.sciml.ai/Catalyst/stable/
Other
437 stars 71 forks source link

type of parameters not always preserved with symbolic indexing #939

Closed isaacsas closed 3 weeks ago

isaacsas commented 3 weeks ago
using Catalyst, ModelingToolkit
revsys = @reaction_network revsys begin
    @parameters m::Int n::Int
    k₊, m*A --> (m*n)*B
    k₋, B --> A
end
typeof(ModelingToolkit.unwrap(revsys.k₊))  # SymbolicUtils.BasicSymbolic{Real}

Same issue with symbolic interface

using Catalyst, ModelingToolkit
t = default_t()
@parameters m::Int n::Int k₊ k₋
@species A(t) B(t)
rx1 = Reaction(k₊, [A], [B], [m], [m*n])   
rx2 = Reaction(k₋, [B], [A])
@named revsys = ReactionSystem([rx1, rx2], t)
typeof(ModelingToolkit.unwrap(revsys.k₊))  # SymbolicUtils.BasicSymbolic{Real}
isaacsas commented 3 weeks ago

Seems like this is related to symbolic indexing:

julia> parameters(revsys)
4-element Vector{Any}:
 m
 n
 k₊
 k₋

julia> typeof.(parameters(revsys))
4-element Vector{DataType}:
 SymbolicUtils.BasicSymbolic{Int64}
 SymbolicUtils.BasicSymbolic{Int64}
 SymbolicUtils.BasicSymbolic{Real}
 SymbolicUtils.BasicSymbolic{Real}
isaacsas commented 3 weeks ago

Not sure if this is actually a Catalyst-level issue or MTK-level.

isaacsas commented 3 weeks ago

Also, using @unpack seems to preserve the type ok.

isaacsas commented 3 weeks ago

@TorkelE is this one there is already an issue for?

isaacsas commented 3 weeks ago

This does not appear to happen for ODESystems, so is a Catalyst-related issue.

isaacsas commented 3 weeks ago

I'm dumb, there is no issue here...