CPU time xx times elapsed time

Hi folks,

I'm working on re-submitting {greta} onto CRAN after it was archived last year. (this PR: Address cran patch i792 by njtierney · Pull Request #793 · greta-dev/greta · GitHub) I keep running into this NOTE when I submit to CRAN:

Flavor: r-devel-linux-x86_64-debian-gcc
Check: re-building of vignette outputs, Result: NOTE
  Re-building vignettes had CPU time 4.1 times elapsed time

Searching around, I see the following related posts:

I understand this error means that our code is using 2 or more cores. I am a bit confused how this is happening on CRAN, as we mostly skip running of vignettes on CRAN as it involves installing tensorflow and tensorflow probability. I have tried variants of these solutions, except for the .onLoad approach - as we need users to be able to use more than 2 cores.

I have tried very hard to limit the vignettes to only use 2 cores, by setting options like the following in the vignette:


knitr::opts_chunk$set(echo = TRUE,
                      eval = greta:::check_tf_version("message"),
                      purl = greta:::check_tf_version("message"),
                      cache = TRUE,
                      comment = NA,
                      progress = FALSE)

# Force limit to 2 cores for CRAN
Sys.setenv("R_PARALLELLY_AVAILABLE_CORES" = "2")
Sys.setenv("MC_CORES" = "2")
Sys.setenv("OMP_THREAD_LIMIT" = "2")
Sys.setenv("OMP_NUM_THREADS" = "2")
options(mc.cores = 2)

# ...

This above approach does not seem to solve this problem. Searching more generally, I see Code Issues – The CRAN Cookbook and

I also note that I cannot reproduce the same error with:

rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran", "--no-multiarch"), env = "_R_CHECK_VIGNETTE_TIMING_CPU_TO_ELAPSED_THRESHOLD_ = 53")

I'm wondering if there is something I am missing on how to deal with this vignette building NOTE, or if I should if ask CRAN can ignore this NOTE?

Best,

Nick

I don't think this is a NOTE you can ignore - if it causes trouble on CRAN it could cause trouble for users in practice.

I see your check_n_cores function uses all available cores if the user has not specified how many cores to use and your modelling functions don't specify a number of cores by default (e.g. mcmc). The CRAN Cookbook advises

It’s best to provide an option for setting the number of cores in any function, with the default ideally set to fewer than 2 cores.

So I would try temporarily setting the number of cores to 1 or 2 in check_n_cores when n_cores is NULL and see if that fixes the issue. If it does, you'll need to think how best to implement a fix: Keep defaulting to 2 if the user doesn't specify n_cores? Keep current behaviour but specify n_cores for each call in the vignette? Implement a package option that the user can set to NULL (= all available) but you can set to 2 in the vignette? Etc. If the temporary fix doesn't work, then you might try bisecting the vignette with knitr::knit_exit() to try to pin down the code causing the issue - maybe you can narrow it down to a particular package/function your code depends on.

1 Like

Thank you so much for this, Heather! I believe we have introduced this error somewhere recently, and we should probably depend on 2 by default.

1 Like

At the moment I cannot seem to replicate the CRAN NOTE, and I also don't really know how to track this bug down. It seems that perhaps my best recourse here to get {greta} on CRAN is to not build the vignettes and use articles instead.