CmdStanR: Model doesn't sample after restarting R (Windows)

I’ve been slowly and mostly happily switching from RStan to CmdStanR, but I just noticed a weird behavior:

I compile a model, succesfully sample, then, after restarting the R sesion, cmdstan_model happily reports

Model executable is up to date!

But running model$sample() gives me

Chain 1 finished unexpectedly!
Chain 2 finished unexpectedly!
Chain 3 finished unexpectedly!
Chain 4 finished unexpectedly!
All chains finished unexpectedly!

I see that the model process gets started, but then terminates immediately.

If I delete the .exe file and recompile, everything works fine until I restart R. Then no sampling once again.

I am on Windows 10. I tried adding the folder containing the model .exe file as an exception into Windows Defender, but to no avail. Any further hints where to look at?

Can you try running the exe in the cmdline if you see any errors?

Hmmm, that’s strange. I can’t think of a good reason why restarting your R session would have that effect. That’s annoying! I’m not able to reproduce this behavior on my mac. Is anyone else able to reproduce this on Windows (or any OS)?

Thanks for the report @martinmodrak . The fix PR is here

The problem was that we only set the TBB path in the compiling step and if you did a reboot and used a built model it never got set.

You can check that this is the bug by rebooting, force-compiling some unrelated model, and trying to run the previously failing model.

I checked locally but you can also try the branch with remotes::install_github("stan-dev/cmdstanr@tbbPathOnRun")

1 Like

I tried and it works, no longer need to recompile, thanks!

1 Like