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

Allowing units via the DSL

Open isaacsas opened this issue 3 years ago • 2 comments

Now that ModelingToolkit and ReactionSystems support units, do we want to expand @reaction_network to allow users to input units for species and parameters too?

isaacsas avatar Aug 19 '21 18:08 isaacsas

Would it be possible, at least for standard cases, to autogenerate units for parameters? Even in the Gillespie case, the units should just be copy numbers for each species, right? It seems it would be possible to allow quite a lot to happen automatically (but an option to specify would also be good).

TorkelE avatar Aug 19 '21 21:08 TorkelE

We’d at least need a base unit specified for time and amount of a species. But the usefulness of units currently is we can check combinations of parameters don’t give an inconsistent rate law. The units are ultimately dropped when simulating ODEs or jumps. So for now they are just a potentially useful check on model correctness. If one isn’t going to give them manually I’m not sure what would be gained by us attaching default units internally.

isaacsas avatar Aug 19 '21 21:08 isaacsas

Given the @parameters option, one can do:

using Catalyst
rn = @reaction_network begin
  @parameters Y [isconstantspecies=true]
  k, X + Y --> 0
end

It seems like a sensible approach to similarly set species (and parameter) units like

  rn = @reaction_network begin
    @species X(t) [unit=µM]
    k, X --> 0
  end

TorkelE avatar Feb 27 '23 13:02 TorkelE

The ModelingToolkit interface should just work: https://docs.sciml.ai/ModelingToolkit/stable/basics/Validation/

however, we need the @variables macro in the DSL so t can be specified with units by a user. Otherwise an incompatible units error will be given.

isaacsas avatar Feb 27 '23 13:02 isaacsas

sounds good. When I add the @variables macro option (probably this week) I will also add some tests to ensure that this works.

TorkelE avatar Feb 27 '23 15:02 TorkelE

Close by https://github.com/SciML/Catalyst.jl/pull/623

isaacsas avatar Mar 02 '23 20:03 isaacsas