mrc-ide / odin

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

Lack of validation in output variables causes two issues #272

Open richfitz opened 1 year ago

richfitz commented 1 year ago

Two models that break:

deriv(S) <- Births - b*S - beta * S * I / N 
deriv(I) <- beta * S * I / N - (b+sigma) * I
deriv(R) <- sigma * I - b*R 

# initial conditions of the variables
initial(S) <- N - I0
initial(I) <- I0
initial(R) <- 0

# parameter values
N <- 1e6                  # total population size
I0 <- user(1)             # num infectious cases at start of epidemic
beta <- R0*(sigma+b)          # transmission parameter
sigma <- user(2)          # recovery rate (1/mean duration infectiousness)
R0 <- user(5)             # av num new cases caused by single infectious case
b <- user(0.02)           # death rate (average life expectancy of 1 year or 52 weeks) = 1/52
Births <- b*N             # number of births (for a constant population size)

output(R0) <- S + I + R

this one validates but won't compile (this is not great in the web version, as the user has no indication of what is wrong). There's a slightly different variant if the target of output is a constant rather than user parameter:

deriv(S) <- Births - b*S - beta * S * I / N 
deriv(I) <- beta * S * I / N - (b+sigma) * I
deriv(R) <- sigma * I - b*R 

# initial conditions of the variables
initial(S) <- N - I0
initial(I) <- I0
initial(R) <- 0

# parameter values
N <- 1e6                  # total population size
I0 <- user(1)             # num infectious cases at start of epidemic
beta <- R0*(sigma+b)          # transmission parameter
sigma <- user(2)          # recovery rate (1/mean duration infectiousness)
R0 <- user(5)             # av num new cases caused by single infectious case
b <- user(0.02)           # death rate (average life expectancy of 1 year or 52 weeks) = 1/52
Births <- b*N             # number of births (for a constant population size)

output(N) <- S + I + R

In this case N is full of junk and eventually crashes R.

Not sure what effect these might have in non-C targets but it can't be good either way really.

Also logged as mrc-3628, same issue