BRMS Rcpp Pointer Initialisation Error


I have been encountering a curious crash when performing a power analysis with the BRMS package. The output of the crash:

In summary, we are compiling a BRM from our pilot data, generating predicted draws based on that model, constructing a new BRM from those predicted draws, and then iteratively simulating new batches of entries, updating our new model, and writing to a file. All of this is taking place within a singularity image on a remote connection to a cluster computer. The crash is very inconsistent (for a given script and set of parameters it may sometimes crash or sometimes succeed), but it seems to always occur after the second update to the second model (ie, the first update to the model works fine and produces an output, but after the second generation and update the script crashes).

Running the models with very low numbers of chain iterations (eg, 10) seems to work smoothly–no crashes are encountered. But with any other numbers (eg, 3000) it can become very inconsistent and unpredictable, often resulting in the crash.

It should be noted that running the script on my laptop (Windows 10 home) and on another laptop (MacOS Mojave 10.14.6) seems to work fine, although we have only run 10 simulations. It seems to be specific to the environment of the cluster computer.

We have eliminated the possibility that the crash is a result of a misassembled singularity image; I have constructed multiple images to test this, and I’ve also tried using the image someone built completely independently here: Docker Hub.

I’ve also seen a thread on this forum with the same crash that I am experiencing, though the context of the crash is slightly different: Rccp Error - Failed to initialize module pointer. In the thread the user was attempting to build a package based off of rstan, and the solution to his issue was to add a few lines in the NAMESPACE document.

Would the equivalent change here be to add those lines directly into the NAMESPACE document of the BRMS library? I ask because the file says specifically not to edit it.

Here’s a link to the contents of the directory we are using on the cluster computer, which includes the script (power_comp.R) and the output directory (results): power - Google Drive

Specifications for the singularity image and laptop R environment: BRMS version is 4.0.2, R version is 4.0.2.

Given all of this, does anybody have any idea as to why the crash is occurring? Any help would be greatly appreciated!


That sounds frustrating.

For what you’re doing, can you use the cmdstanr backend to brms?

You can do brm(..., backend = "cmdstanr") to use cmdstanr. I don’t think it works with all brms stuff though, but maybe it works for what you’re doing.

@andrjohns does this problem ring a bell at all to you? Don’t need a solution – just if it seems familiar.

@bbbales2 Not something I’ve seen before no, not sure where the issue could be coming from

@curtisc Do you know if the brms model is being recompiled when update is called? Try running with recompile=FALSE if it is. But another good option (if possible), would be to install the cmdstanR package and use backend="cmdstanr", as Ben mentioned above. The cmdstanR package tends to be more stable