tmbstan
tmbstan copied to clipboard
MCMC chains on multiple cores
This Windows specific issue was raised on https://groups.google.com/g/tmb-users/c/1K65LWZ8SIE Workarounds are currently needed:
library(RTMB)
set.seed(123)
data <- list(Y = rnorm(10) + 1:10, x=1:10)
parameters <- list(a=0, b=0, logSigma=0)
f <- function(parms) {
require(RTMB) ## WORKAROUND
Y <- data$Y
x <- data$x
a <- parms$a
b <- parms$b
logSigma <- parms$logSigma
ADREPORT(exp(2*logSigma));
nll = -sum(dnorm(Y, a+b*x, exp(logSigma), TRUE))
nll
}
environment(f) <- new.env() ## WORKAROUND
environment(f)$data <- data ## WORKAROUND
obj <- MakeADFun(f, parameters)
library(tmbstan)
s <- tmbstan(obj, iter = 100, chains = 2, cores = 2) ## Now works !
- Workarounds should not be needed
In addition, while debugging (debug(selectMethod("sampling","stanmodel"))
), some further issues were found:
- Quite slow to start the cluster
cl <- parallel::makeCluster(...)
because of package loading I think. Might not all be necessary? -
FIXED: ~
parallel::clusterEvalQ(cl, .dotlist$object@ptr)
return null pointers, i.e. the fast CCallables are not used !~ - Virtually impossible for a user to diagnose. There might be a clue here:
sinkfile <- paste0(tfile, "_StanProgress.txt")
?