HenrikBengtsson / future.batchtools

:rocket: R package future.batchtools: A Future API for Parallel and Distributed Processing using batchtools
https://future.batchtools.futureverse.org
84 stars 9 forks source link

run(), resolved()[?], and result(): the RNG state is updated - from where? #82

Closed HenrikBengtsson closed 1 year ago

HenrikBengtsson commented 1 year ago

Something updates .Random.seed when a future is launched, checked, and collected, e.g.

> library(future.batchtools)
> plan(batchtools_interactive) ## also with batchtools_local and batchtools_sge
> f <- future(42, lazy = TRUE)
> f <- run(f)
TRACKER: .Random.seed changed
> resolved(f)
[1] FALSE
> resolved(f)
[1] TRUE
TRACKER: .Random.seed changed
> resolved(f)
[1] TRUE
> r <- result(f)
TRACKER: .Random.seed changed
> r <- result(f)
> v <- value(f)
> 
HenrikBengtsson commented 1 year ago

One thing that updates the RNG state is batchtools::makeRegistry(). It does so in two places; first to generate a random seed, unless argument seed is specified. However, later on it also calls batchtools:::rnd_hash(), which also update the RNG state.

HenrikBengtsson commented 1 year ago

Added test to future.tests that checks for this:

── Settings ────────────────────────────────────────────────────────────────────
- future.tests version      : 0.4.0.9001
- R_FUTURE_TESTS_ROOT       : 
- Option 'future.tests.root': NULL
- Default test set folder   : /home/hb/R/x86_64-pc-linux-gnu-library/4.2-CBI-gcc9/future.tests/test-db
- Max number of workers     : 2
- Timeout                   : N/A

── Running 50 test sets with plan(future.batchtools::batchtools_local) ─────────
ℹ Backend package: future.batchtools 0.10.0.9020
…
- ✔ Random Number Generation (RNG) - %<-% (2 tests) (18.4s)                     
✖ Orchestration Stability - future() does not update RNG state (1 test) (965ms) 
  ✖ lazy=FALSE, globals=TRUE, stdout=TRUE
✖ Orchestration Stability - result() does not update RNG state (1 test) (2s)    
-   ✖ lazy=FALSE, globals=TRUE, stdout=TRUE
✖ Orchestration Stability - value() does not update RNG state (1 test) (3.1s)   
  ✖ lazy=FALSE, globals=TRUE, stdout=TRUE
HenrikBengtsson commented 1 year ago

The following calls in run() updates the RNG state: