stan-dev / stan-dev/projpred

`doFuture` warning about PRNG use in parallel projections

Open
#520 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
R
Stars
114
Forks
31
PR merge metrics
No merged PRs in 30d

Description

When running a projection in parallel (across draws) using the doFuture package, the doFuture package claims that the pseudo-random number generator (PRNG) had been used. This is unexpected because the projection is deterministic, which can be checked by inspecting the source code of fit_glm_ridge_callback() (including all functions used by it, and functions used by these, and so on).

Reprex:

data("df_gaussian", package = "projpred")
df_gaussian <- df_gaussian[1:29, ]
dat <- data.frame(y = df_gaussian$y, df_gaussian$x)
rfit <- rstanarm::stan_glm(y ~ X1 + X2 + X3 + X4 + X5,
                           data = dat,
                           chains = 1,
                           iter = 500,
                           seed = 1140350788,
                           refresh = 0)

library(projpred)

doFuture::registerDoFuture()
future::plan(future::multisession, workers = 4)
progressr::handlers(global = TRUE)
trigger_default <- options(projpred.prll_prj_trigger = 0L)

prj <- project(rfit,
               predictor_terms = c("X1", "X2"),
               seed = 46782345)

The last line throws 4 warnings (one per parallel worker), the last one (here for worker 4) being:

Warning: UNRELIABLE VALUE: One of the foreach() iterations (‘doFuture-4’)
unexpectedly generated random numbers without declaring so. There is a risk
that those random numbers are not statistically sound and the overall results
might be invalid. To fix this, use '%dorng%' from the 'doRNG' package instead
of '%dopar%'. This ensures that proper, parallel-safe random numbers are
produced via the L'Ecuyer-CMRG method. To disable this check, set option
'doFuture.rng.onMisuse' to "ignore".

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the provided reprex and tracing fit_glm_ridge_callback() through the parallel projection call chain to identify what triggers doFuture's PRNG check. Done means deterministic projections no longer emit the unexpected worker warnings while preserving the projection results.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.