Catalyst.jl icon indicating copy to clipboard operation
Catalyst.jl copied to clipboard

species that only appear within observables

Open isaacsas opened this issue 7 months ago • 5 comments

I feel like this should error or auto-discover but it goes through ok and results in a system that does not have species_A2 as a variable or species:

function model()
          t = default_t() # i have to add this, otherwise it throws error
          
          @species begin
                species_A1(t)
                species_A2(t)
          end

          @parameters begin
                p1
                p2
          end

          A_rate = p1 * species_A1
          B_rate = p2 * p1 * species_A1
          
          rn = @reaction_network begin

               @combinatoric_ratelaws false

               @observables begin 
                   total_A ~ $species_A1 + $species_A2 
                   Tree ~ $species_A1 * $p1 - $species_A2 * ($p2-$p1) 
               end
               
              $B_rate, B => A
              $A_rate, 0 => A
              
          end
          return rn
       end

Output:

julia> rn = model()
Model ##ReactionSystem#307:
Unknowns (3): see unknowns(##ReactionSystem#307)
  B(t)
  A(t)
  species_A1(t)
Parameters (2): see parameters(##ReactionSystem#307)
  p2
  p1
Observed (2): see observed(##ReactionSystem#307)

julia> unknowns(rn)
3-element Vector{SymbolicUtils.BasicSymbolic{Real}}:
 B(t)
 A(t)
 species_A1(t)

julia> species(rn)
3-element Vector{SymbolicUtils.BasicSymbolic{Real}}:
 B(t)
 A(t)
 species_A1(t)

julia> nonspecies(rn)
SymbolicUtils.BasicSymbolic{Real}[]

julia> observed(rn)
2-element Vector{Equation}:
 total_A(t) ~ species_A2(t) + species_A1(t)
 Tree(t) ~ -(-p1 + p2)*species_A2(t) + p1*species_A1(t)

isaacsas avatar Aug 06 '25 14:08 isaacsas

So I think there was a thing where species that were only observables are intentionally eliminated. Think it had to do with consistency with MTK, but not sure how it does for Systems there days. Think it was like 2-3 years since we actually looked at this so don't remember the details.

TorkelE avatar Aug 06 '25 14:08 TorkelE

(either case, I guess we just check what MTK does and changes to that, probably, although I think there is a good argument for an explicitly declared observable should be a species. This is related to the case where observables are elimainted and don't appear in plots by defaults though)

TorkelE avatar Aug 06 '25 15:08 TorkelE

This should be handled by just not separating the equations and putting the observed in the equation set. This should just be covered in the transition to v10 anyways for correctness so I'll handle that.

ChrisRackauckas avatar Aug 06 '25 15:08 ChrisRackauckas

Do observed as normal equations work with pure jump models now? (i.e. do they get moved by MTK to being observed from being equations so one ends up with a pure jump model?)

isaacsas avatar Aug 06 '25 16:08 isaacsas

I think Catalyst still needs to support a notion of observed so in Catalyst we can know that these aren't meant to be system equations that define dynamics. Not having this would be limiting for conducting analysis on Catalyst models. If MTK now supports these as normal equations and properly eliminates them while preserving the desired final model type we can switch our conversion functions to move them to be equations.

isaacsas avatar Aug 06 '25 16:08 isaacsas