R Session Aborted

I’ve been frequently getting “R Session Aborted” error while working on a project recently. I would like to understand generally why this happens. And also here I attach the codes I’m using.

Here I attach 3 files, the R script file simulates the data and runs stan files using rstan. The two stan files are two models I’ve been working on. I encounter different issues while using different methods on them.

  1. if I use vb function on “owa_ext_bin_mfvb” model, it can run, but results is not ideal
  2. if I use vb function on “owa_ext_bin_svi” model, usually the first time I try to run it, it’ll give me the following error message:

Error in sampler$call_sampler(c(args, dotlist)) :
stan::variational::normal_meanfield::calc_grad: The number of dropped evaluations has reached its maximum amount (10). Your model may be either severely ill-conditioned or misspecified.

And if I just immediately try to run it again, 50% of the time it runs ok. 50% of the time it crashes with “R Session Aborted” error. From the forum I understand that this error message is related to parameter initialization? I’d like to know if there’s anything I need to change in my code so as to avoid this error. Also would like to understand, when it runs, why sometimes it crashes R. Any suggestions on my code (in terms of efficiency or anything) would be appreciated!

Note that this is similar set up as the first model, except that I’m allowing for more dependencies between the parameters in order to relax the independence assumptions in MFVB (I tried using algorithm=“fullrank” in vb function, it won’t work, will crash R).

  1. I then tried using MCMC with the first model and frequently get “R Session Aborted” error. I realized that I’m not able to reproduce the error. It seems to randomly happens at random time… here are just some observations:
  • one time I tried with all parameter set as default, then after all 4 chains finished running, my R console is flooded non-stop with the following msg. Is it sth wrong with rcpp? I had to manually terminate my R session.

*** recursive gc invocation

  • if I set iter to a small number (e.g., 20, 200), it tends to work out fine
  1. After I update to use rstan 2.21.1, it always generates the following warning message whenever I run it. Wonder any plan to get rid of this?

sh: clang++ -mmacosx-version-min=10.13: command not found
The NEXT version of Stan will not be able to pre-process your Stan program.
Please open an issue at
https://github.com/stan-dev/stanc3/issues
if you can share or at least describe your Stan program. This will help ensure that Stan
continues to work on your Stan programs in the future. Thank you!
This message can be avoided by wrapping your function call inside suppressMessages().

Finally here’s info with my system:

R 4.0.2
macos 10.15.5
Rstan 2.21.1

Many thanks!

Question2.R (1.9 KB) owa_ext_bin_mfvb.stan (901 Bytes)
owa_ext_bin_svi.stan (1.2 KB)

We’ve been finding all sorts of weird issues with the latest rstan unfortunately. One option to is to use the older version (which I think you said on GitHub that you’ve done), but another option is to use the new CmdStanR interface, which should play nicer with R (i.e., fewer crashes). To run VB with CmdStanR the syntax is:

# http://mc-stan.org/cmdstanr/reference/model-method-variational.html
model <- cmdstan_model(stan_file)
fit <- model$variational(data, ...)