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
464 stars 78 forks source link

valid ways to write equations using the DSL #1044

Open vyudu opened 2 months ago

vyudu commented 2 months ago

Might be worth thinking about allowing more complicated derivative expressions on the left side of differential equations.

@reaction_network begin
    @variables A(t) B(t)
    @equations D(A) + D(B) ~ A
end

f(A, t) = 2*A*t
@reaction_network begin
    @variables A(t) B(t)
    @equations f(A, t)*D(A) ~ A + B
end

This latter one may be complicated since we probably want to escape the f(A, t) but not the D(A)? @TorkelE would it be easy to change the DSL code to allow for stuff like this?

I assume we want both of the following to work?

f(A, t) = 2*A*t
@reaction_network begin
    @variables A(t) B(t)
    @equations f(A, t) ~ A + B
end

@reaction_network begin
    @variables A(t) B(t)
    @equations A + B ~ f(A, t)
end
isaacsas commented 2 months ago

Yes, it would be nice if all of these are supported (assuming they work in the symbolic interface).

TorkelE commented 2 months ago

All this should work (sans any function related its). Anything that is a valid equation normally should also work in the DSL. However, it is only in the case of D(V) ~ ... (Where there are no differentials on the RHS) Where we automatically under that V is a variable.

If you check the texts added here https://github.com/SciML/Catalyst.jl/pull/815 you can see all the details of how it work.