Alrighty I think I got this working!
Can you try the below and let me know if it works? I made some slight changes to your stan program so please copy and paste this stan program into Test_Adjoint_v2.stan
. That file has a couple different things
- Instead of parameter packing it uses the new ODE interface (which I think is a bit nicer to read and is also a bit more performant)
- There was an indexing error that is now removed (
[n_obs+1:2*n_obs]
should be written have parenthesis like [(n_obs+1):(2*n_obs)]
(@rybern I wonder if we could make a warning about this in pedantic mode, it seems kind of common?)
3ā¦ I think time < right_t[i]
should be time <= right_t[i]
in SIR
? Else on the last iteration idt beta
is set.
Speaking of (3), thank you twice for reporting this because I found a little bug in the stan compiler when users donāt set initial values for an object in functions! Because of (3) sometimes beta would not be set. I thought I was catching that in the compiler but itās an easy fix.
Anyway, copy pasting the above and running the below should work!
# make a fresh cmdstan somewhere
# Note here I'm just doing it in the same folder as where I put Bernadette
# so they are next to each other
git clone --recursive https://github.com/stan-dev/cmdstan
# go down to stan math and checkout the fix branch
cd cmdstan/stan/lib/stan_math/
git checkout fix/adjoint-mem-ownership
# back to cmdstan folder
cd ../../
# This should be okay with gcc > 8 or clang
echo "CXXFLAGS+=-march=native" > make/local
make ../Bernadette/Test_Adjoint/Test_Adjoint_v2
../Bernadette/Test_Adjoint/Test_Adjoint_v2 data file="../Bernadette/Test_Adjoint/adjoint_data.json" init="../Bernadette/Test_Adjoint/init.json" sample output refresh=2 random seed=123
You could also just run upto the point of building cmdstan and then switch over to the cmdstanr
pointing to the new cmdstan.
On my computer Iām seeing
Gradient evaluation took 0.159679 seconds
1000 transitions using 10 leapfrog steps per transition would take 1596.79 seconds.
Adjust your expectations accordingly!
Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Exception: ode_adjoint_tol_ctl: ode parameters and data argument number 3 at index is inf, but must be finite! (in '../Bernadette/Test_Adjoint/Test_Adjoint_v2.stan', line 148, column 2 to line 163, column 101)
If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Exception: ode_adjoint_tol_ctl: ode parameters and data argument number 3 at index is inf, but must be finite! (in '../Bernadette/Test_Adjoint/Test_Adjoint_v2.stan', line 148, column 2 to line 163, column 101)
If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Exception: CVODES: CVode At t = 0 and h = 3.7207e-102, the corrector convergence test failed repeatedly or with |h| = hmin. Error code: -4 (in '../Bernadette/Test_Adjoint/Test_Adjoint_v2.stan', line 148, column 2 to line 163, column 101)
If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
CVODES: CVode At t = 394 and h = -2.85893e-26, the error test failed repeatedly or with |h| = hmin. Error code: -3
If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Iteration: 1 / 2000 [ 0%] (Warmup)
Iteration: 2 / 2000 [ 0%] (Warmup)
Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Exception: normal_lpdf: Scale parameter is 0, but must be positive! (in '../Bernadette/Test_Adjoint/Test_Adjoint_v2.stan', line 195, column 23 to column 59)
If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Iteration: 4 / 2000 [ 0%] (Warmup)
Iteration: 6 / 2000 [ 0%] (Warmup)
So after the first few iterations the warnings go away which at least seems good. Though note I did not run this for the full number of iterations so you may still have divergent transitions.