Hi Dirk,
Yes, you can potentially see where the MCMC breaks, but things are always harder to pin down when your bug manifests as a crash. Here are some more ideas in case something is useful.
You can take control of the master MCMC function by copying and pasting
buildMCMC from nimble's source code. It's "just" a nimbleFunction and if you copy and paste it locally (and change the "name = 'MCMC'" argument), you can use your local copy in place of nimble's buildMCMC. Then for example in the master loop at line 209 (default time=FALSE case) you can insert "print(i)" and you'll get a rolling output of iteration counts until the crash. Sometimes crashes can suppress final output that has not yet been flushed, so it might not be perfect.
If the error is reproducible, i.e. occurs on the same iteration every time (assuming you used set.seed to get the same RNG sequence), and you can find that iteration by the above method, you can arrange to let the sampler know when to go into a debugging mode. For example, you could use the model to share information like this:
In the model, add a dummy node:
debugging ~ dbern(0.5) # This node is isolated, not connected to the rest of the model. set debugging = 0 in inits
In the master MCMC loop in buildMCMC, say you have determined that the problem occurs during iteration 20345, so insert:
if(iter == 20345) model$debugging <<- 1 # Use the "debugging" nodes to share information with the samplers
In your custom sampler:
if(model$debugging) my_debug_fn(<inputs>)
where my_debug_fn is a nimbleRcall and <inputs> is whatever you want to inspect.
You can pause for inspection by putting a debugger (browser) on the R function called by the nimbleRcall. Say that is called R_my_debug_fn
debug(R_my_debug_fn)
Then at iteration 20345, your sampler will call my_debug_fn which will call R_my_debug_fn which will put you in a browser. You can then inspect the compiled model object and/or the compiled MCMC object.
This bug sounds really mysterious so I hope these strategies are some help.
-Perry