Hello All, Has anyone else encountered an issue where a node is sampled well on a single chain but the sampler sticks when running the model in parallel on multiple chains? In my case, I started with a model that wasn't sampling a node on a single chain until I forced a slice sampler on that node. However, when I switched to running in parallel, by wrapping my nimbleModel, compile, config, remove/add sampler, build, compile, run lines inside a function as recommended, the same nodes do not move beyond passed their initial values. Adjusting the sliceWidth control to start with a large initial width didn't help. The parallelization is not effecting the other nodes in the model. I can also see from the trace plots that stuck nodes are accepting their random initial values. Here is a snippet of the parallelization code where I think the problem must lie:
run_MCMC_allcode <- function(X, data, constants, code, monitors, niter, nburnin, thin){
library(nimble)
dmy_function<-nimbleFunction(...#custom function)
assign(' dmy_function ', dmy_function , envir = .GlobalEnv)
inits <- X$inits
# Build model
model <- nimbleModel(code = code,
data = data,
constants = constants,
inits = inits)
assign('rmy_function',
rmy_function , envir = .GlobalEnv) # dummy random
cmodel <- compileNimble(model)
conf <- configureMCMC(cmodel, monitors = monitors)
conf$removeSamplers(paste0("K[", 1:constants$S, "]")) # this is stuck node K: discrete scalars
for(i in seq_len(constants$S)) {
conf$addSampler(target = paste0("K[", i, "]"),
type = "slice")
}
modbuild<- buildMCMC(conf)
modc <- compileNimble(modbuild, project = model)
seed <- X$seed
results <- runMCMC(modc, niter = niter, nburnin = nburnin, thin = thin, setSeed = seed)
return(list(results = results, seed = seed))
}
output <- parLapply(cl = cl, X = inputsList,
fun = run_MCMC_allcode,
data = data,
constants = constants,
code = code,
monitors = c("lambdaM","alpha","sigma","pbar",
"M","K"),
niter = 1000,
nburnin = 100,
thin = 1)