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

Proposed notation for delay #191

Open TorkelE opened 4 years ago

TorkelE commented 4 years ago

I wouldn't look at the implementation of delay into DiffEqBio just yet. (we will let MTK handle that, and first, we need jack DiffEqBio into MTK. I hope to start working on the DiffEqBio side of things in the next couple of day)

We could, however, start looking at how to allow time-delays to be given in the DiffEqBio DSL. I suggest using [] for this:

@reaction_network begin
    p, ∅ → X
    d*X[t-τ], X → ∅
end p d τ

here X[t-τ] would denote the value of the variable X at some previous time. I believe we have already reserved the value of t for the current time (cannot be used for other variables or parameters). τ would be a simple parameter to the model. One could also write a constant, such as X[t-2.5]. Allowing

Does this sound reasonable?

isaacsas commented 4 years ago

Sounds reasonable to me, but I don't have much experience using the delay equation interface (so don't know how general it is or what we'd want to support). I guess once we see how it is done in MT we can have a similar level of support in the DSL here.

korsbo commented 4 years ago

Tricky. The mathematical notation uses round brackets. This gets a little bit confusing with Julia functions, but as long as he still know that X in your example is a variable then we should be good. Square brackets do not currently collide with anything in diffeqbio but what if we want to introduce spatial modelling? Square brackets would be natural for indexing.

ChrisRackauckas commented 4 years ago

Looks reasonable to me. Note that adding delay lowering in MTK for ODEs and DDEs is something on my mind but isn't the easiest thing in the world, but I plan to get to it in the next month. Delays in jumps will be an issue for a bit though, since we would need to change the jump interface to include the integrator so that it could grab the sol to interpolate the history.

TorkelE commented 4 years ago

Never thought about delays in Jumps.

Yes, it may take some time until this might actually come to use.

TorkelE commented 7 months ago

Given current development, I do not think this is the way to go. Something like

@reaction_network begin
    @delayed_variable Xτ ~ X(t-τ)
    p, ∅ --> X
    d*Xτ, X --> ∅
end

might be better though

isaacsas commented 6 months ago

System seems to just accept X(t-\tau) directly, so maybe we can just let people type that (and add a check to see if there are delayed variables / capture them).

ChrisRackauckas commented 6 months ago

https://github.com/SciML/ModelingToolkit.jl/pull/2208

isaacsas commented 6 months ago

Is it just constant lags currently?

TorkelE commented 6 months ago

System seems to just accept X(t-\tau) directly, so maybe we can just let people type that (and add a check to see if there are delayed variables / capture them).

Exactly how would that look? E.g.

@reaction_network begin
    p, ∅ --> X
    d*X(t-τ), X --> ∅
end

and similar is problematic because currently X(t-τ) could be multiplication (rather than a function call with a delayed time).

isaacsas commented 6 months ago

How could it be multiplication? That isn't valid in Julia is it?

TorkelE commented 6 months ago

No, you are right, I mixed it up!

TorkelE commented 6 months ago

Yes, your approach seems like the way to go