mrc-ide / odin

ᚩ A DSL for describing and solving differential equations in R
https://mrc-ide.github.io/odin
Other
105 stars 13 forks source link

Specifying Jacobian in Odin #251

Open schnebeni opened 2 years ago

schnebeni commented 2 years ago

I'd like to specify the Jacobian for a system of equations I'm working with – I'm also working with an array. I'm not sure how I should specify the order of elements though, because I'm not sure what order the vector of parameters is read-in as.

richfitz commented 2 years ago

This is not currently supported. I believe (though I could be wrong) that if the RHS is compiled then deSolve requires that Jacobian is also supplied, and that would require some work to do as we'd need to extend the odin syntax to support this.

If you press on, the parameter order is always available from the model, e.g.:

names(odin::odin_ir(gen, TRUE)$data$variable$contents)

but you can't rely on different versions of odin not reordering it (it comes from sorting the graph through the equations, and we have thoughts about changing that next year to generate more cache-friendly code).

If you do get something working, please point me to an example where it helps and if and when I get some time I can look at adding support for it more nicely.

schnebeni commented 2 years ago

I'd love to contribute a solution for this problem. Do you have any more tips for implementing a vector of Jacobians (one for each id in the array)?

richfitz commented 2 years ago

This is likely to be a big job and would require some care to get right. You could start by:

Then I'd need to see what changes would be needed to support this.

A warning though - we're pretty swamped with covid response work so this would likely not feature very high up the list of priorities for a while I'm afraid