"Variable does not exist" error for user-defined function in ode_rk45

Hi,

I was trying to replicate the Lotka-Volterra case study as described here updating using the new ODE interface as described here.

However at line vector[2] z[N] = ode_rk45(dz_dt, z_init, 0, ts, alpha, beta, gamma, delta); in the model below I get the error: Variable "dz_dt" does not exist.

Since I define dz_dt in the user defined functions block I couldn’t figure out where the error might be. Any help would be appreciated.

I’m using rstan 2.21.2 on R 4.0.2.


functions {
  vector dz_dt(real t,       // time
               vector z,     // system state {prey, predator}
               real alpha,
               real beta,
               real gamma,
               real delta) {
    
    real u = z[1];
    real v = z[2];

    real du_dt = (alpha - beta * v) * u;
    real dv_dt = (-gamma + delta * u) * v;
    
    vector[2] res;
    res[1] = du_dt;
    res[2] = dv_dt;
    return  res;
  }
}

data {
  int<lower = 0> N;           // number of measurement times
  real ts[N];                 // measurement times > 0
  real y_init[2];             // initial measured populations
  real<lower = 0> y[N, 2];    // measured populations
}

parameters {
  real<lower = 0> alpha;   // { alpha, beta, gamma, delta }
  real<lower = 0> beta;
  real<lower = 0> gamma;
  real<lower = 0> delta;
  real<lower = 0> z_init[2];  // initial population
  real<lower = 0> sigma[2];   // measurement errors
}

transformed parameters {
  vector[2] z[N] = ode_rk45(dz_dt, z_init, 0, ts, alpha, beta, gamma, delta);
}

model {
  alpha ~ normal(1, 0.5);
  gamma ~ normal(1, 0.5);
  beta ~ normal(0.05, 0.05);
  delta ~ normal(0.05, 0.05);
  sigma ~ lognormal(-1, 1);
  z_init ~ lognormal(log(10), 1);
  
  for (k in 1:2) {
    y_init[k] ~ lognormal(log(z_init[k]), sigma[k]);
    y[ , k] ~ lognormal(log(z[, k]), sigma[k]);
  }
}

generated quantities {
  real y_init_rep[2];
  real y_rep[N, 2];
  for (k in 1:2) {
    y_init_rep[k] = lognormal_rng(log(z_init[k]), sigma[k]);
    for (n in 1:N)
      y_rep[n, k] = lognormal_rng(log(z[n, k]), sigma[k]);
  }
}

That is not a great error message but I believe it is implying that your function does not confirm to the strict signature requirements for using ode_rk45 listed at

The stanc3 parser has a better error message:

Semantic error in ‘string’, line 39, column 19 to column 76:
Ill-typed arguments supplied to function ‘ode_rk45’. Expected arguments:
(real, vector) => vector, vector, real, real[]
Instead supplied arguments of incompatible type:
(real, vector, real, real, real, real) => vector, real[], int, real[], real, real, real, real

The main problem is that ode_rk45 was introduced in Stan 2.24 and rstan is at 2.21.

This case study currently only works with Cmdstan (and cmdstanr/py) and Pystan3.

Thanks for the clarification. This might not be the right place to ask this (I can start a separate topic if you prefer) but I’m a bit confused about how to install Cmdstan for MacOS. The User’s Guide says:

Note MacOS installations may include old version of the g++ compiler which is a version 4.2.1. CmdStan requires g++ at 4.9.3 or later. Trying to install later versions of g++ using homebrew or macports is no longer recommended; use the XCode toolchain.

The latest stable release of Command Line Tools comes with g++ 4.2.1. The instructions discourage updating this using other ways. So what is the best way to install CmdStan on MacOS?

1 Like

@zenkavi I’m not entirely sure but I wouldn’t worry about it unless you run into an error. If you try installing CmdStan using the install_cmdstan() function in the cmdstanr package does it work?

Here’s some code:

devtools::install_github("stan-dev/cmdstanr")
library("cmdstanr")
install_cmdstan(cores = 4)

If that runs successfully then you can double check that you can compile and run a model using one of the example models:

fit <- cmdstanr_example(quiet=FALSE)
1 Like

Thanks again! I installed it anyway and though initially it gave me the following error

Error in get0(oNam, envir = ns) : lazy-load database '/Library/Frameworks/R.framework/Versions/4.0/Resources/library/R6/R/R6.rdb' is corrupt

after restarting my R session it seemed to be working.

I am now able to compile and run the model and estimates I’ve gotten aren’t too far from the case study but I got lots of messages during sampling. Is there anything I should change or is it ok to ignore these?

Chain 1 Rejecting initial value:
Chain 1   Error evaluating the log probability at the initial value.
Chain 1 Exception: ode_rk45:  Failed to integrate to next output time (9) in less than max_num_steps steps (in '/var/folders/10/zpzbg__x3hlc56gwq9zf6r600000gn/T/Rtmp3DXbaF/model-20bf71c39170.stan', line 19, column 4 to column 16)
Chain 1 Exception: ode_rk45:  Failed to integrate to next output time (9) in less than max_num_steps steps (in '/var/folders/10/zpzbg__x3hlc56gwq9zf6r600000gn/T/Rtmp3DXbaF/model-20bf71c39170.stan', line 19, column 4 to column 16)
Chain 1 Rejecting initial value:
Chain 1   Error evaluating the log probability at the initial value.
Chain 1 Exception: lognormal_lpdf: Random variable[1] is -1.76058, but must be >= 0! (in '/var/folders/10/zpzbg__x3hlc56gwq9zf6r600000gn/T/Rtmp3DXbaF/model-20bf71c39170.stan', line 49, column 2 to column 33)
Chain 1 Exception: lognormal_lpdf: Random variable[1] is -1.76058, but must be >= 0! (in '/var/folders/10/zpzbg__x3hlc56gwq9zf6r600000gn/T/Rtmp3DXbaF/model-20bf71c39170.stan', line 49, column 2 to column 33)
Chain 1 Gradient evaluation took 0.000614 seconds
Chain 1 1000 transitions using 10 leapfrog steps per transition would take 6.14 seconds.
Chain 1 Adjust your expectations accordingly!
Chain 1 Iteration:    1 / 2000 [  0%]  (Warmup) 
Chain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 1 Exception: lognormal_lpdf: Random variable[2] is -0.548493, but must be >= 0! (in '/var/folders/10/zpzbg__x3hlc56gwq9zf6r600000gn/T/Rtmp3DXbaF/model-20bf71c39170.stan', line 49, column 2 to column 33)
Chain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 1 
Chain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 1 Exception: lognormal_lpdf: Location parameter[2] is nan, but must be finite! (in '/var/folders/10/zpzbg__x3hlc56gwq9zf6r600000gn/T/Rtmp3DXbaF/model-20bf71c39170.stan', line 54, column 4 to column 47)
Chain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 1 
Chain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 1 Exception: ode_rk45: ode parameters and data is inf, but must be finite! (in '/var/folders/10/zpzbg__x3hlc56gwq9zf6r600000gn/T/Rtmp3DXbaF/model-20bf71c39170.stan', line 40, column 2 to column 77)
Chain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 1 
Chain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 1 Exception: lognormal_lpdf: Location parameter[1] is nan, but must be finite! (in '/var/folders/10/zpzbg__x3hlc56gwq9zf6r600000gn/T/Rtmp3DXbaF/model-20bf71c39170.stan', line 54, column 4 to column 47)
Chain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 1 
Chain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 1 Exception: lognormal_lpdf: Location parameter[2] is nan, but must be finite! (in '/var/folders/10/zpzbg__x3hlc56gwq9zf6r600000gn/T/Rtmp3DXbaF/model-20bf71c39170.stan', line 54, column 4 to column 47)
Chain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 1 
Chain 1 Iteration:  100 / 2000 [  5%]  (Warmup) 
Chain 1 Iteration:  200 / 2000 [ 10%]  (Warmup) 
Chain 1 Iteration:  300 / 2000 [ 15%]  (Warmup) 
Chain 1 Iteration:  400 / 2000 [ 20%]  (Warmup) 
Chain 1 Iteration:  500 / 2000 [ 25%]  (Warmup) 
Chain 1 Iteration:  600 / 2000 [ 30%]  (Warmup) 
Chain 1 Iteration:  700 / 2000 [ 35%]  (Warmup) 
Chain 1 Iteration:  800 / 2000 [ 40%]  (Warmup) 
Chain 1 Iteration:  900 / 2000 [ 45%]  (Warmup) 
Chain 1 Iteration: 1000 / 2000 [ 50%]  (Warmup) 
Chain 1 Iteration: 1001 / 2000 [ 50%]  (Sampling) 
Chain 1 Iteration: 1100 / 2000 [ 55%]  (Sampling) 
Chain 1 Iteration: 1200 / 2000 [ 60%]  (Sampling) 
Chain 1 Iteration: 1300 / 2000 [ 65%]  (Sampling) 
Chain 1 Iteration: 1400 / 2000 [ 70%]  (Sampling) 
Chain 1 Iteration: 1500 / 2000 [ 75%]  (Sampling) 
Chain 1 Iteration: 1600 / 2000 [ 80%]  (Sampling) 
Chain 1 Iteration: 1700 / 2000 [ 85%]  (Sampling) 
Chain 1 Iteration: 1800 / 2000 [ 90%]  (Sampling) 
Chain 1 Iteration: 1900 / 2000 [ 95%]  (Sampling) 
Chain 1 Iteration: 2000 / 2000 [100%]  (Sampling) 
Chain 1 finished in 25.7 seconds.
Chain 2 Rejecting initial value:
Chain 2   Error evaluating the log probability at the initial value.
Chain 2 Exception: lognormal_lpdf: Random variable[1] is -1.01172, but must be >= 0! (in '/var/folders/10/zpzbg__x3hlc56gwq9zf6r600000gn/T/Rtmp3DXbaF/model-20bf71c39170.stan', line 49, column 2 to column 33)
Chain 2 Exception: lognormal_lpdf: Random variable[1] is -1.01172, but must be >= 0! (in '/var/folders/10/zpzbg__x3hlc56gwq9zf6r600000gn/T/Rtmp3DXbaF/model-20bf71c39170.stan', line 49, column 2 to column 33)
Chain 2 Rejecting initial value:
Chain 2   Error evaluating the log probability at the initial value.
Chain 2 Exception: ode_rk45:  Failed to integrate to next output time (9) in less than max_num_steps steps (in '/var/folders/10/zpzbg__x3hlc56gwq9zf6r600000gn/T/Rtmp3DXbaF/model-20bf71c39170.stan', line 19, column 4 to column 16)
Chain 2 Exception: ode_rk45:  Failed to integrate to next output time (9) in less than max_num_steps steps (in '/var/folders/10/zpzbg__x3hlc56gwq9zf6r600000gn/T/Rtmp3DXbaF/model-20bf71c39170.stan', line 19, column 4 to column 16)
Chain 2 Gradient evaluation took 0.000219 seconds
Chain 2 1000 transitions using 10 leapfrog steps per transition would take 2.19 seconds.
Chain 2 Adjust your expectations accordingly!
Chain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 2 Exception: ode_rk45:  Failed to integrate to next output time (1) in less than max_num_steps steps (in '/var/folders/10/zpzbg__x3hlc56gwq9zf6r600000gn/T/Rtmp3DXbaF/model-20bf71c39170.stan', line 19, column 4 to column 16)
Chain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 2 
Chain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 2 Exception: ode_rk45:  Failed to integrate to next output time (1) in less than max_num_steps steps (in '/var/folders/10/zpzbg__x3hlc56gwq9zf6r600000gn/T/Rtmp3DXbaF/model-20bf71c39170.stan', line 19, column 4 to column 16)
Chain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 2 
Chain 2 Iteration:    1 / 2000 [  0%]  (Warmup) 
Chain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 2 Exception: ode_rk45:  Failed to integrate to next output time (1) in less than max_num_steps steps (in '/var/folders/10/zpzbg__x3hlc56gwq9zf6r600000gn/T/Rtmp3DXbaF/model-20bf71c39170.stan', line 19, column 4 to column 16)
Chain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 2 
Chain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 2 Exception: lognormal_lpdf: Random variable[2] is -1.94217, but must be >= 0! (in '/var/folders/10/zpzbg__x3hlc56gwq9zf6r600000gn/T/Rtmp3DXbaF/model-20bf71c39170.stan', line 49, column 2 to column 33)
Chain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 2 
Chain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 2 Exception: ode_rk45: ode parameters and data is inf, but must be finite! (in '/var/folders/10/zpzbg__x3hlc56gwq9zf6r600000gn/T/Rtmp3DXbaF/model-20bf71c39170.stan', line 40, column 2 to column 77)
Chain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 2 
Chain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 2 Exception: lognormal_lpdf: Random variable[1] is -29.9513, but must be >= 0! (in '/var/folders/10/zpzbg__x3hlc56gwq9zf6r600000gn/T/Rtmp3DXbaF/model-20bf71c39170.stan', line 49, column 2 to column 33)
Chain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 2 
Chain 2 Iteration:  100 / 2000 [  5%]  (Warmup) 
Chain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 2 Exception: lognormal_lpdf: Location parameter[1] is nan, but must be finite! (in '/var/folders/10/zpzbg__x3hlc56gwq9zf6r600000gn/T/Rtmp3DXbaF/model-20bf71c39170.stan', line 54, column 4 to column 47)
Chain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 2 
Chain 2 Iteration:  200 / 2000 [ 10%]  (Warmup) 
Chain 2 Iteration:  300 / 2000 [ 15%]  (Warmup) 
Chain 2 Iteration:  400 / 2000 [ 20%]  (Warmup) 
Chain 2 Iteration:  500 / 2000 [ 25%]  (Warmup) 
Chain 2 Iteration:  600 / 2000 [ 30%]  (Warmup) 
Chain 2 Iteration:  700 / 2000 [ 35%]  (Warmup) 
Chain 2 Iteration:  800 / 2000 [ 40%]  (Warmup) 
Chain 2 Iteration:  900 / 2000 [ 45%]  (Warmup) 
Chain 2 Iteration: 1000 / 2000 [ 50%]  (Warmup) 
Chain 2 Iteration: 1001 / 2000 [ 50%]  (Sampling) 
Chain 2 Iteration: 1100 / 2000 [ 55%]  (Sampling) 
Chain 2 Iteration: 1200 / 2000 [ 60%]  (Sampling) 
Chain 2 Iteration: 1300 / 2000 [ 65%]  (Sampling) 
Chain 2 Iteration: 1400 / 2000 [ 70%]  (Sampling) 
Chain 2 Iteration: 1500 / 2000 [ 75%]  (Sampling) 
Chain 2 Iteration: 1600 / 2000 [ 80%]  (Sampling) 
Chain 2 Iteration: 1700 / 2000 [ 85%]  (Sampling) 
Chain 2 Iteration: 1800 / 2000 [ 90%]  (Sampling) 
Chain 2 Iteration: 1900 / 2000 [ 95%]  (Sampling) 
Chain 2 Iteration: 2000 / 2000 [100%]  (Sampling) 
Chain 2 finished in 24.2 seconds.
Chain 3 Iteration:    1 / 2000 [  0%]  (Warmup) 
Chain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 3 Exception: ode_rk45: ode parameters and data is inf, but must be finite! (in '/var/folders/10/zpzbg__x3hlc56gwq9zf6r600000gn/T/Rtmp3DXbaF/model-20bf71c39170.stan', line 40, column 2 to column 77)
Chain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 3 
Chain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 3 Exception: ode_rk45: ode parameters and data is inf, but must be finite! (in '/var/folders/10/zpzbg__x3hlc56gwq9zf6r600000gn/T/Rtmp3DXbaF/model-20bf71c39170.stan', line 40, column 2 to column 77)
Chain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 3 
Chain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 3 Exception: lognormal_lpdf: Random variable[2] is -124.473, but must be >= 0! (in '/var/folders/10/zpzbg__x3hlc56gwq9zf6r600000gn/T/Rtmp3DXbaF/model-20bf71c39170.stan', line 49, column 2 to column 33)
Chain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 3 
Chain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 3 Exception: lognormal_lpdf: Random variable[2] is -30.6713, but must be >= 0! (in '/var/folders/10/zpzbg__x3hlc56gwq9zf6r600000gn/T/Rtmp3DXbaF/model-20bf71c39170.stan', line 49, column 2 to column 33)
Chain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 3 
Chain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 3 Exception: lognormal_lpdf: Random variable[2] is -6.69811, but must be >= 0! (in '/var/folders/10/zpzbg__x3hlc56gwq9zf6r600000gn/T/Rtmp3DXbaF/model-20bf71c39170.stan', line 49, column 2 to column 33)
Chain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 3 
Chain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 3 Exception: lognormal_lpdf: Random variable[2] is -0.998122, but must be >= 0! (in '/var/folders/10/zpzbg__x3hlc56gwq9zf6r600000gn/T/Rtmp3DXbaF/model-20bf71c39170.stan', line 49, column 2 to column 33)
Chain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 3 
Chain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 3 Exception: lognormal_lpdf: Location parameter[11] is nan, but must be finite! (in '/var/folders/10/zpzbg__x3hlc56gwq9zf6r600000gn/T/Rtmp3DXbaF/model-20bf71c39170.stan', line 54, column 4 to column 47)
Chain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 3 
Chain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 3 Exception: ode_rk45: ode parameters and data is inf, but must be finite! (in '/var/folders/10/zpzbg__x3hlc56gwq9zf6r600000gn/T/Rtmp3DXbaF/model-20bf71c39170.stan', line 40, column 2 to column 77)
Chain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 3 
Chain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 3 Exception: lognormal_lpdf: Random variable[2] is -48.4869, but must be >= 0! (in '/var/folders/10/zpzbg__x3hlc56gwq9zf6r600000gn/T/Rtmp3DXbaF/model-20bf71c39170.stan', line 49, column 2 to column 33)
Chain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 3 
Chain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 3 Exception: lognormal_lpdf: Location parameter[19] is nan, but must be finite! (in '/var/folders/10/zpzbg__x3hlc56gwq9zf6r600000gn/T/Rtmp3DXbaF/model-20bf71c39170.stan', line 54, column 4 to column 47)
Chain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 3 
Chain 3 Iteration:  100 / 2000 [  5%]  (Warmup) 
Chain 3 Iteration:  200 / 2000 [ 10%]  (Warmup) 
Chain 3 Iteration:  300 / 2000 [ 15%]  (Warmup) 
Chain 3 Iteration:  400 / 2000 [ 20%]  (Warmup) 
Chain 3 Iteration:  500 / 2000 [ 25%]  (Warmup) 
Chain 3 Iteration:  600 / 2000 [ 30%]  (Warmup) 
Chain 3 Iteration:  700 / 2000 [ 35%]  (Warmup) 
Chain 3 Iteration:  800 / 2000 [ 40%]  (Warmup) 
Chain 3 Iteration:  900 / 2000 [ 45%]  (Warmup) 
Chain 3 Iteration: 1000 / 2000 [ 50%]  (Warmup) 
Chain 3 Iteration: 1001 / 2000 [ 50%]  (Sampling) 
Chain 3 Iteration: 1100 / 2000 [ 55%]  (Sampling) 
Chain 3 Iteration: 1200 / 2000 [ 60%]  (Sampling) 
Chain 3 Iteration: 1300 / 2000 [ 65%]  (Sampling) 
Chain 3 Iteration: 1400 / 2000 [ 70%]  (Sampling) 
Chain 3 Iteration: 1500 / 2000 [ 75%]  (Sampling) 
Chain 3 Iteration: 1600 / 2000 [ 80%]  (Sampling) 
Chain 3 Iteration: 1700 / 2000 [ 85%]  (Sampling) 
Chain 3 Iteration: 1800 / 2000 [ 90%]  (Sampling) 
Chain 3 Iteration: 1900 / 2000 [ 95%]  (Sampling) 
Chain 3 Iteration: 2000 / 2000 [100%]  (Sampling) 
Chain 3 finished in 26.1 seconds.
Chain 4 Rejecting initial value:
Chain 4   Error evaluating the log probability at the initial value.
Chain 4 Exception: ode_rk45:  Failed to integrate to next output time (5) in less than max_num_steps steps (in '/var/folders/10/zpzbg__x3hlc56gwq9zf6r600000gn/T/Rtmp3DXbaF/model-20bf71c39170.stan', line 19, column 4 to column 16)
Chain 4 Exception: ode_rk45:  Failed to integrate to next output time (5) in less than max_num_steps steps (in '/var/folders/10/zpzbg__x3hlc56gwq9zf6r600000gn/T/Rtmp3DXbaF/model-20bf71c39170.stan', line 19, column 4 to column 16)
Chain 4 Gradient evaluation took 0.000149 seconds
Chain 4 1000 transitions using 10 leapfrog steps per transition would take 1.49 seconds.
Chain 4 Adjust your expectations accordingly!
Chain 4 Iteration:    1 / 2000 [  0%]  (Warmup) 
Chain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 4 Exception: ode_rk45: ode parameters and data is inf, but must be finite! (in '/var/folders/10/zpzbg__x3hlc56gwq9zf6r600000gn/T/Rtmp3DXbaF/model-20bf71c39170.stan', line 40, column 2 to column 77)
Chain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 4 
Chain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 4 Exception: ode_rk45: ode parameters and data is inf, but must be finite! (in '/var/folders/10/zpzbg__x3hlc56gwq9zf6r600000gn/T/Rtmp3DXbaF/model-20bf71c39170.stan', line 40, column 2 to column 77)
Chain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 4 
Chain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 4 Exception: lognormal_lpdf: Random variable[1] is -2.38955, but must be >= 0! (in '/var/folders/10/zpzbg__x3hlc56gwq9zf6r600000gn/T/Rtmp3DXbaF/model-20bf71c39170.stan', line 49, column 2 to column 33)
Chain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 4 
Chain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 4 Exception: lognormal_lpdf: Random variable[2] is -18.7624, but must be >= 0! (in '/var/folders/10/zpzbg__x3hlc56gwq9zf6r600000gn/T/Rtmp3DXbaF/model-20bf71c39170.stan', line 49, column 2 to column 33)
Chain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 4 
Chain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 4 Exception: lognormal_lpdf: Random variable[2] is -3.4297, but must be >= 0! (in '/var/folders/10/zpzbg__x3hlc56gwq9zf6r600000gn/T/Rtmp3DXbaF/model-20bf71c39170.stan', line 49, column 2 to column 33)
Chain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 4 
Chain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 4 Exception: ode_rk45: ode parameters and data is inf, but must be finite! (in '/var/folders/10/zpzbg__x3hlc56gwq9zf6r600000gn/T/Rtmp3DXbaF/model-20bf71c39170.stan', line 40, column 2 to column 77)
Chain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 4 
Chain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 4 Exception: ode_rk45: ode parameters and data is inf, but must be finite! (in '/var/folders/10/zpzbg__x3hlc56gwq9zf6r600000gn/T/Rtmp3DXbaF/model-20bf71c39170.stan', line 40, column 2 to column 77)
Chain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 4 
Chain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 4 Exception: lognormal_lpdf: Random variable[2] is -1.18445, but must be >= 0! (in '/var/folders/10/zpzbg__x3hlc56gwq9zf6r600000gn/T/Rtmp3DXbaF/model-20bf71c39170.stan', line 49, column 2 to column 33)
Chain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 4 
Chain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 4 Exception: lognormal_lpdf: Location parameter[15] is nan, but must be finite! (in '/var/folders/10/zpzbg__x3hlc56gwq9zf6r600000gn/T/Rtmp3DXbaF/model-20bf71c39170.stan', line 54, column 4 to column 47)
Chain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 4 
Chain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 4 Exception: lognormal_lpdf: Location parameter[6] is nan, but must be finite! (in '/var/folders/10/zpzbg__x3hlc56gwq9zf6r600000gn/T/Rtmp3DXbaF/model-20bf71c39170.stan', line 54, column 4 to column 47)
Chain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 4 
Chain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 4 Exception: lognormal_lpdf: Location parameter[7] is nan, but must be finite! (in '/var/folders/10/zpzbg__x3hlc56gwq9zf6r600000gn/T/Rtmp3DXbaF/model-20bf71c39170.stan', line 54, column 4 to column 47)
Chain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 4 
Chain 4 Iteration:  100 / 2000 [  5%]  (Warmup) 
Chain 4 Iteration:  200 / 2000 [ 10%]  (Warmup) 
Chain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 4 Exception: lognormal_lpdf: Random variable[1] is -5.23541, but must be >= 0! (in '/var/folders/10/zpzbg__x3hlc56gwq9zf6r600000gn/T/Rtmp3DXbaF/model-20bf71c39170.stan', line 49, column 2 to column 33)
Chain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 4 
Chain 4 Iteration:  300 / 2000 [ 15%]  (Warmup) 
Chain 4 Iteration:  400 / 2000 [ 20%]  (Warmup) 
Chain 4 Iteration:  500 / 2000 [ 25%]  (Warmup) 
Chain 4 Iteration:  600 / 2000 [ 30%]  (Warmup) 
Chain 4 Iteration:  700 / 2000 [ 35%]  (Warmup) 
Chain 4 Iteration:  800 / 2000 [ 40%]  (Warmup) 
Chain 4 Iteration:  900 / 2000 [ 45%]  (Warmup) 
Chain 4 Iteration: 1000 / 2000 [ 50%]  (Warmup) 
Chain 4 Iteration: 1001 / 2000 [ 50%]  (Sampling) 
Chain 4 Iteration: 1100 / 2000 [ 55%]  (Sampling) 
Chain 4 Iteration: 1200 / 2000 [ 60%]  (Sampling) 
Chain 4 Iteration: 1300 / 2000 [ 65%]  (Sampling) 
Chain 4 Iteration: 1400 / 2000 [ 70%]  (Sampling) 
Chain 4 Iteration: 1500 / 2000 [ 75%]  (Sampling) 
Chain 4 Iteration: 1600 / 2000 [ 80%]  (Sampling) 
Chain 4 Iteration: 1700 / 2000 [ 85%]  (Sampling) 
Chain 4 Iteration: 1800 / 2000 [ 90%]  (Sampling) 
Chain 4 Iteration: 1900 / 2000 [ 95%]  (Sampling) 
Chain 4 Iteration: 2000 / 2000 [100%]  (Sampling) 
Chain 4 finished in 23.3 seconds.

All 4 chains finished successfully.
Mean chain execution time: 24.8 seconds.
Total execution time: 115.0 seconds.

Great, glad it’s working for you. It looks like those warnings all happened during the warmup period of each chain rather than during the sampling period, and weird stuff can happen during warmup. As long as you’re not getting too many of those during sampling it should be ok.

And this

seems to be related to the R6 package, which is one of cmdstanr’s dependencies. Not sure why that happened but if it’s working now I think it’s safe to ignore.