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

Create new model without declaring parameters

Open wangwillian0 opened this issue 3 years ago • 9 comments

It would be nice if the macro @reaction_network could infer the parameters and the chemical species directly from the model without the need to declare the parameters after end.

wangwillian0 avatar May 11 '21 15:05 wangwillian0

This is tricky because we might want to ultimately allow

rn = @reaction_network begin
              k*B, 3*A  --> 2*C
       end k
rn2 = @reaction_network begin
              k, 3*A  + 2*B --> 2*C
       end k B

to default B to be a species in the former and a parameter in the latter. This could be useful in defining composed networks from smaller sub-networks, but requires some way of the user telling us what is a species vs. parameter.

isaacsas avatar May 11 '21 17:05 isaacsas

One thing we could potentially do, unless we find something which covers all cases, is to allow for different macros, e.g.

rn = @sometag_reaction_network
    (k1,k2), X1 <-->X2
end

which then know that all species are declared as reaction components.

TorkelE avatar May 11 '21 17:05 TorkelE

Yeah, I was thinking about that too. Maybe @default_network or @simple_network?

isaacsas avatar May 11 '21 17:05 isaacsas

What about just add to the current macro some default behavior (when nothing is declared) of taking everything from the right side as species ? Something like 0, A --> A could be used to force some implicit specie and it could also print the species and parameters along with the latex of reactions to make clear what the user just did. A new macro seems a little unnecessary to me.

rn = @reaction_network begin
              k*B, 3*A  --> 2*C
       end k

Btw is this supposed to work already ? (I'm using v6.12.1)

wangwillian0 avatar May 11 '21 19:05 wangwillian0

rn = @reaction_network begin
              k*B, 3*A  --> 2*C
       end k

this would work, but B would be considered a species.

A default behaviour could become problematic in a case like

rn = @reaction_network begin
        x, 3*A  --> 2*C
 end

where x would become a parameter (but according current notation it is a species), even weirder if one adds a parameter

rn = @reaction_network begin
        x*k, 3*A  --> 2*C
 end k

one would suddenly turn x to a species (if the previous default case made it a parameter).

Typing additional reactions seems cumbersome, I don't think that's the way to go. A directly better alternative would just be to use your suggestion as the default, and change the current version (parameters typed) to a special macro. The question is what is actually the most used case. Having a species only in the rates is very rare, and only that feature would merit having the current default as the special case macro. However, I do find it quite useful to time the order of the parameters (if only to avoid having to double check the order when I write the parameter values into the parameter vector).

TorkelE avatar May 11 '21 19:05 TorkelE

I see... But even if its not the most common, does changing to declaration of species instead of parameters solve part of this issue ? There is no reaction without reactant (is even possible to create a model with parameters only ?). Maybe make the current macro work with declaration of species while infer automatically when nothing is declared - so it cover every strange model and just works; and create a new macro to deal with more customization like the order of parameters (and species too if its possible) ?

wangwillian0 avatar May 11 '21 23:05 wangwillian0

Declaring with species instead of parameters would work. But there's still teh question what woudl actually be the most useful default (i.e. do more people prefer declaring the paraemter order or not). So some kind of decision would have to be made, personally, I'm not sure what I would prefer, and would have to think about it. Decisions can take time! This would also be a really breaking change, so would need to wait until a really major update anyway.

What I'm saying is that changing the default to what you suggest would take time, and the by far quickest solution would be to make an alternative macro, from there it would also be easier for people to figure out what they'd prefer as the default behaviour.

TorkelE avatar May 12 '21 11:05 TorkelE

Got it, personally I like more to order the species because usually my parameters are just constants while I need to manipulate and plot the species, but I understand your point. I will try to keep track of it 🙂

wangwillian0 avatar May 12 '21 16:05 wangwillian0

We should just make the DSL consistent with what @reaction does. Adding parameters at the end can be an optional way to overrule this default.

isaacsas avatar May 31 '22 14:05 isaacsas

This is now on master and will be in Catalyst 13

isaacsas avatar Feb 08 '23 12:02 isaacsas