Hi Dirk,
That's an interesting catch. The exit behavior of the for-loop index differs (but result y shouldn't differ). Often for-loop indices are later ignored, but sometimes one relies on their exit value, so this could matter. There are some other differences in compiled vs uncompiled behavior, notably that in compiled code non-scalar numeric arguments will be passed by reference. There shouldn't be glaring differences in math.
One way to test your own samplers would be to call them manually (outside of the MCMC), after setting the seed for reproducibility. Off the top of my head I can suggest two ways to do this. The first would be to build the sampler on its own (not within an MCMC). For that purpose it might be easier to remove uses of the mvSamples, since those are set up from the MCMC (i.e. buildMCMC). Then you could compile the sampler object directly and, if you set a seed, set values in the model, and call the sampler, all with the uncompiled objects (model + sampler) and then (after re-setting to the same seed) with the compiled objects (model + sampler), you should get identical behavior. The second would be to do
nimbleOptions(buildInterfacesForCompiledNestedNimbleFunctions = TRUE)
(always worth a chuckle at that long but accurate name ;-) )
Then you can use the samplers as they were built in the MCMC (including mvSamples etc). You should be able to access samplers (compiled or uncompiled) by
MCMC$samplerFunctions[[i]]
where MCMC was returned from buildMCMC and i is a choice of which sampler you want to look at. E.g. you can set the state of the model, then the seed, and then manually call one iteration of sampler i:
MCMC$samplerFunctions[[i]]$run()
or inspect its internals
MCMC$samplerFunctions[[i]]$scale
In the uncompiled MCMC, you can check the target node of a sampler to be sure it's the sampler of interest
MCMC$samplerFunctions[[i]]$target
A final approach to checking on what your own sampler is doing is to define a nimbleRcall to some R function and call it from the run code of your sampler. Then put a browser() in the R function (or debug() it). Then when your compiled code is running, it will call your R function and you'll get into a browser, from which you can inspect the state of the compiled model etc (e.g. to see what proposal value was used, or what calculations were done). You can also access sampler setup (member) variables as described above. If you need to look at local variables, you'd have to pass them as arguments to the nimbleRcall.
HTH
Perry