Skip to content

more RNG consistency #389

@topepo

Description

@topepo

First, we should make sure that package dependencies do not change the RNNG state when they are loaded. For example:

> set.seed(1)
> runif(1)
[1] 0.2655087
> 
> set.seed(1)
> library(forecast)
Registered S3 method overwritten by 'quantmod':
  method            from
  as.zoo.data.frame zoo 
> runif(1)
[1] 0.3721239

Second, currently tune resets the RNGkind after usage:

library(tidymodels)
#> Registered S3 method overwritten by 'tune':
#>   method                   from   
#>   required_pkgs.model_spec parsnip

RNGkind()
#> [1] "Mersenne-Twister" "Inversion"        "Rejection"
set.seed(6735)
folds <- vfold_cv(mtcars, v = 5)
spline_rec <-
  recipe(mpg ~ ., data = mtcars) %>%
  step_ns(disp, deg_free = tune("disp")) %>%
  step_ns(wt, deg_free = tune("wt"))

lin_mod <-
  linear_reg() %>%
  set_engine("lm")

spline_grid <- expand.grid(disp = 2:5, wt = 2:5)

spline_res <-
  tune_grid(lin_mod, spline_rec, resamples = folds, grid = spline_grid)

RNGkind()
#> [1] "L'Ecuyer-CMRG" "Inversion"     "Rejection"

Created on 2021-06-29 by the reprex package (v2.0.0)

We do change the RNG kind (see #331) and reset it. However, it is being reset somewhere so we need to add another on.exit().

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugan unexpected problem or unintended behaviorfeaturea feature request or enhancement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions