Index error when using new ODE interface

I’m trying to rewrite the SEIR model we used in a tutorial ([2006.02985] Bayesian workflow for disease transmission modeling in Stan) using the new ODE interfaces, including the prototype adjoint solver. I’m running into an odd bug, which is that once the code ends its warmup and starts sampling, I get an index error from Eigen:

Chain 1 Assertion failed: (index >= 0 && index < size()), function operator[], file stan/lib/stan_math/lib/eigen_3.3.9/Eigen/src/Core/DenseCoeffsBase.h, line 408.
Warning: Chain 1 finished unexpectedly!

The generated quantities block is commented out, so I don’t know why the error systematically kicks in during the sampling phase. Note the error doesn’t occur when I use integrate_ode_rk45, but when I use ode_rk45_tol. I’m attaching the relevant Stan file, which contains, commented out, the original code. I can provide the R script and data to run the model, if needed.

seir_forcing_survey.stan (5.4 KB)

In the old interface you had

real y[n_days, 4];

which is an array of 4-element arrays. The first dimension has n_days.

In the new interface you wrote

vector[n_days] y[4];

which is a 4-element array of vectors the size of n_days.

What you want is

vector[4] y[n_days];

or the equivalent but nicer way

array[n_days] vector[4]

1 Like

Also, on develop cmdstan, the error is nicer, the one you got it is not very informative.

1 Like