clustermq icon indicating copy to clipboard operation
clustermq copied to clipboard

Clustermq 0.8.96 fails with error on `foreach ... %dopar% ...` in Jupyter lab R console/notebooks

Open efremale opened this issue 2 years ago • 1 comments

Example:

library(foreach)                                                                                                                      
library(clustermq)                                                                                                                    
clustermq::register_dopar_cmq(n_jobs = 50L, template = list(partition = "p_fast_c7"))
foreach::foreach(x=1:3) %dopar% {x**2}

Error:

Error in new_CppObject_xp(fields$.module, fields$.pointer, ...): Invalid argument
Traceback:

1. foreach::foreach(x = 1:3) %dopar% {
 .     x^2
 . }
2. e$fun(obj, substitute(ex), parent.frame(), e$data)
3. do.call(Q_rows, c(list(df = args_df, fun = fun), data))
4. (function (df, fun, const = list(), export = list(), pkgs = c(), 
 .     seed = 128965, memory = NULL, template = list(), n_jobs = NULL, 
 .     job_size = NULL, rettype = "list", fail_on_error = TRUE, 
 .     workers = NULL, log_worker = FALSE, chunk_size = NA, timeout = Inf, 
 .     max_calls_worker = Inf, verbose = TRUE) 
 . {
 .     if (!is.null(memory)) 
 .         template$memory = memory
 .     if (!is.null(template$memory) && template$memory < 50) 
 .         stop("Worker needs about 23 MB overhead, set memory>=50")
 .     if (is.na(seed) || length(seed) != 1) 
 .         stop("'seed' needs to be a length-1 integer")
 .     fun = match.fun(fun)
 .     df = as.data.frame(df, check.names = FALSE, stringsAsFactors = FALSE)
 .     n_calls = nrow(df)
 .     seed = as.integer(seed)
 .     check_args(fun, df, const)
 .     data = list(fun = fun, const = const, export = export, pkgs = pkgs, 
 .         rettype = rettype, common_seed = seed)
 .     if (is.null(workers)) {
 .         qsys_id = toupper(getOption("clustermq.scheduler", qsys_default))
 .         if (qsys_id != "LOCAL" && is.null(n_jobs) && is.null(job_size)) 
 .             stop("n_jobs or job_size is required")
 .         n_jobs = Reduce(min, c(ceiling(n_calls/job_size), n_jobs, 
 .             n_calls))
 .         workers = workers(n_jobs, data = data, reuse = FALSE, 
 .             template = template, log_worker = log_worker, verbose = verbose)
 .     }
 .     else do.call(workers$set_common_data, data)
 .     if (is.na(chunk_size)) 
 .         chunk_size = round(Reduce(min, c(500, n_calls/n_jobs/100, 
 .             n_calls/2000, 10000 * n_calls/utils::object.size(df)[[1]])))
 .     chunk_size = max(chunk_size, 1)
 .     if (class(workers)[1] == "LOCAL") {
 .         list2env(export, envir = environment(fun))
 .         for (pkg in pkgs) library(pkg, character.only = TRUE)
 .         re = work_chunk(df = df, fun = fun, const = const, rettype = rettype, 
 .             common_seed = seed, progress = TRUE)
 .         summarize_result(re$result, length(re$errors), length(re$warnings), 
 .             c(re$errors, re$warnings), fail_on_error = fail_on_error)
 .     }
 .     else {
 .         if (workers$workers == 0) 
 .             stop("Attempting to use workers object without active workers")
 .         master(qsys = workers, iter = df, rettype = rettype, 
 .             fail_on_error = fail_on_error, chunk_size = chunk_size, 
 .             timeout = timeout, max_calls_worker = max_calls_worker, 
 .             verbose = verbose)
 .     }
 . })(df = structure(list(1L, 2L, 3L), .Dim = c(3L, 1L), .Dimnames = list(
 .     NULL, "x")), fun = function (x, ...) 
 . {
 .     x^2
 . }, n_jobs = 50L, template = list(partition = "p_fast_c7"))
5. workers(n_jobs, data = data, reuse = FALSE, template = template, 
 .     log_worker = log_worker, verbose = verbose)
6. qsys$new(data = data, reuse = reuse, ...)
7. initialize(...)
8. super$initialize(..., template = template)
9. methods::new(CMQMaster)
10. initialize(value, ...)
11. initialize(value, ...)
12. .Object$initialize(...)
13. Rcpp::cpp_object_initializer(.self, .refClassDef, ...)
14. new_CppObject_xp(fields$.module, fields$.pointer, ...)

This doesn't happen in terminal. Version 0.8.95.1 works too.

sessionInfo():

R version 4.0.3 (2020-10-10)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: CentOS Linux 7 (Core)

Matrix products: default
BLAS:   /opt/third/R/4.0.3/lib64/R/lib/libRblas.so
LAPACK: /opt/third/R/4.0.3/lib64/R/lib/libRlapack.so

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] clustermq_0.8.96 foreach_1.5.1   

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.7        getPass_0.2-2     uuid_0.1-4        R6_2.5.0         
 [5] rlang_0.4.11      fansi_0.5.0       tools_4.0.3       pkgbuild_1.2.0   
 [9] utf8_1.2.2        cli_3.0.1         withr_2.4.2       iterators_1.0.13 
[13] htmltools_0.5.1.1 ellipsis_0.3.2    remotes_2.2.0     rprojroot_2.0.2  
[17] digest_0.6.27     lifecycle_1.0.0   crayon_1.4.1      processx_3.5.2   
[21] IRdisplay_1.0     callr_3.7.0       repr_1.1.3        codetools_0.2-18 
[25] base64enc_0.1-3   vctrs_0.3.8       ps_1.6.0          IRkernel_1.2     
[29] curl_4.3.2        evaluate_0.14     pbdZMQ_0.3-5      compiler_4.0.3   
[33] pillar_1.6.2      prettyunits_1.1.1 jsonlite_1.7.2  

efremale avatar Aug 16 '21 17:08 efremale

Yes, the current Github version is a not yet finished rewrite of the code base (using ZeroMQ C++ bindings because we can't fix some issues on the R side otherwise), and unfortunately still contains quite a few bugs. Please use CRAN if you want a stable package for the time being.

mschubert avatar Aug 17 '21 12:08 mschubert

I assume this has been fixed with the more recent stable releases. Please reopen if not.

mschubert avatar Dec 16 '23 12:12 mschubert