Skip to content

doFuture: Error: length(results) == nbr_of_elements is not TRUE #220

Closed

Description

@nbarsch

Hi Henrik,

I'm trying to replicate what you have done here: https://www.r-bloggers.com/dofuture-a-universal-foreach-adaptor-ready-to-be-used-by-1000-packages/

I'm trying to do this with a sample of seven vms in a cluster (what I could get with the free trial). I keep getting the error Error: length(results) == nbr_of_elements is not TRUE

The cluster seems to be working fine since I can accomplish the same task with future_lapply just fine. It's when I try to do a future foreach loop that I get the error.

###After doing authentication etc.
vms <- lapply(vm_names, gce_vm, 
                     predefined_type = "f1-micro", 
                     template = "r-base") 
vms <- lapply(vms, gce_ssh_setup)

###Go Rockies, Go Broncos
gce_ssh(vms[[1]], "echo GO ROCKIES, GO BRONCOS!")

###set the cluster
plan(cluster, workers = as.cluster(vms))

###sample function 
run <- function(...) {
  cd4.rg <- function(data, mle) MASS::mvrnorm(nrow(data), mle$m, mle$v)
  cd4.mle <- list(m = colMeans(cd4), v = var(cd4))
  boot(cd4, corr, R = 5000, sim = "parametric", ran.gen = cd4.rg, mle = cd4.mle)
}

###Works fine
t3 <- system.time(boot0 <- future_lapply(1:100, FUN = run, future.seed = 0xBEEF))

###Doesn't work
registerDoFuture()
system.time(
  r <- foreach(i=1:trials, .packages="boot") %dopar% {
    ind <- run()
  })

What am I doing wrong here? Thanks in advance and cheers on the really cool package!

Activity

  1. HenrikBengtsson commented on Apr 27, 2018

    @HenrikBengtsson
    Collaborator

    In case that R-blogger page is not up-to-date, let's use the example at https://www.jottr.org/2017/03/18/dofuture/.

    I believe that error occurs after the doFuture adapter has collected the data from the workers, so I doubt it has to do with your GCE setup. Does it work if you play the same game on your local machine?

    library("doFuture")
    registerDoFuture()
    nodes <- rep("localhost", times = 4L)
    plan(cluster, workers = nodes)
    y <- foreach(i=1:100, .packages="boot") %dopar% {
      ind <- run()
    }

    Also, what's your sessionInfo()?

  2. HenrikBengtsson commented on Apr 27, 2018

    @HenrikBengtsson
    Collaborator

    ...and what does traceback() output immediately after you get that error.

  3. nbarsch commented on Apr 27, 2018

    @nbarsch
    Author

    Works fine if I do it off my own local cores with your code above.

    Session info below:

    R version 3.4.3 (2017-11-30)
    Platform: x86_64-apple-darwin15.6.0 (64-bit)
    Running under: macOS Sierra 10.12.3

    Matrix products: default
    BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
    LAPACK: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRlapack.dylib

    locale:
    [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

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

    other attached packages:
    [1] future.apply_0.1.0 googleComputeEngineR_0.2.0.9000
    [3] boot_1.3-20 doParallel_1.0.11
    [5] dplyr_0.7.4 doFuture_0.6.0
    [7] iterators_1.0.9 foreach_1.4.4
    [9] future_1.8.0 bigrquery_1.0.0.9000

    loaded via a namespace (and not attached):
    [1] Rcpp_0.12.16 pillar_1.1.0 compiler_3.4.3
    [4] googleAuthR_0.6.2.9000 bindr_0.1 tools_3.4.3
    [7] testthat_2.0.0 digest_0.6.15 jsonlite_1.5
    [10] memoise_1.1.0 tibble_1.4.2 pkgconfig_2.0.1
    [13] rlang_0.2.0 DBI_0.8 curl_3.2
    [16] yaml_2.1.18 bindrcpp_0.2 withr_2.1.1
    [19] httr_1.3.1 stringr_1.3.0 globals_0.11.0
    [22] devtools_1.13.4 glue_1.2.0 listenv_0.7.0
    [25] R6_2.2.2 magrittr_1.5 codetools_0.2-15
    [28] MASS_7.3-47 assertthat_0.2.0 stringi_1.1.7
    [31] openssl_0.9.9

  4. HenrikBengtsson commented on Apr 27, 2018

    @HenrikBengtsson
    Collaborator

    Weird, to rule out that there's some clash with all those other package, make sure to also try in a clean R session. I guess something like (maybe there is more loaded when you actually set up the GCE workers):

    > sessionInfo()
    [...]
    other attached packages:
    [1] boot_1.3-20            googleAuthR_0.6.2.9000 doFuture_0.6.0   
    [4] iterators_1.0.9        foreach_1.4.4          future_1.8.0     
    [7] globals_0.11.0   
    
    loaded via a namespace (and not attached):
     [1] codetools_0.2-15   listenv_0.7.0      digest_0.6.15      assertthat_0.2.0  
     [5] R6_2.2.2           jsonlite_1.5       httr_1.3.1         tools_3.4.4       
     [9] compiler_3.4.4     memoise_1.1.0    
  5. nbarsch commented on Apr 27, 2018

    @nbarsch
    Author

    Sorry for delay in getting you traceback(). . . I had destroyed the cluster so had to regenerate it.

    traceback()
    5: stop(msg, call. = FALSE, domain = NA)
    4: stopifnot(length(results) == nbr_of_elements)
    3: e$fun(obj, substitute(ex), parent.frame(), e$data)
    2: foreach(i = 1:trials, .packages = "boot") %dopar% {
    ind <- run()
    }
    1: system.time(r <- foreach(i = 1:trials, .packages = "boot") %dopar%
    {
    ind <- run()
    })

    I"m working on the clean session now, running tests and will get back.

  6. nbarsch commented on Apr 27, 2018

    @nbarsch
    Author

    Thank you so much for your help Henrik! I still get the same error :(

    Ok from a completely clean rsession only loading doFuture and googleComputeEngine (and dependencies), and from a freshly regenerated cluster in the new session:

    Code I ran in the fresh session to generate the cluster:

    library(doFuture)
    
    Sys.setenv(GCE_AUTH_FILE= account_key,
               GCE_DEFAULT_PROJECT_ID= project,
               GCE_DEFAULT_ZONE= zone)
    
    library(googleComputeEngineR)
    
    gce_global_project(project)
    gce_global_zone(zone)
    default_project <- gce_get_project(project)
    
    vm_names <- paste0("vm",1:7)
    
    vms <- lapply(vm_names, gce_vm, 
                  predefined_type = "f1-micro", 
                  template = "r-base")
    
    vms <- lapply(vms, gce_ssh_setup)
    
    
    ###Test if the first VM responds to a ping
    gce_ssh(vms[[1]], "echo GO ROCKIES, GO BRONCOS!")
    
    
    
    run <- function(...) {
      cd4.rg <- function(data, mle) MASS::mvrnorm(nrow(data), mle$m, mle$v)
      cd4.mle <- list(m = colMeans(cd4), v = var(cd4))
      boot(cd4, corr, R = 5000, sim = "parametric", ran.gen = cd4.rg, mle = cd4.mle)
    }
    
    

    Does not work:

    registerDoFuture()
    plan(cluster, workers = as.cluster(vms))
    y <- foreach(i=1:100, .packages="boot") %dopar% {
      ind <- run()
    }
    Error: length(results) == nbr_of_elements is not TRUE
    traceback()
    4: stop(msg, call. = FALSE, domain = NA)
    3: stopifnot(length(results) == nbr_of_elements)
    2: e$fun(obj, substitute(ex), parent.frame(), e$data)
    1: foreach(i = 1:100, .packages = "boot") %dopar% {
           ind <- run()
       }
    
    

    HOWEVER THIS WORKS JUST FINE:

    
    system.time(boot0 <- future.apply::future_lapply(1:100, FUN = run, future.seed = 0xBEEF))
       user  system elapsed 
      0.263   0.039  15.909
    

    Rsession info:

    > sessionInfo()
    R version 3.4.3 (2017-11-30)
    Platform: x86_64-apple-darwin15.6.0 (64-bit)
    Running under: macOS Sierra 10.12.3
    
    Matrix products: default
    BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
    LAPACK: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRlapack.dylib
    
    locale:
    [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
    
    attached base packages:
    [1] parallel  stats     graphics  grDevices utils     datasets  methods   base     
    
    other attached packages:
    [1] googleComputeEngineR_0.2.0.9000 doFuture_0.6.0                 
    [3] iterators_1.0.9                 foreach_1.4.4                  
    [5] future_1.8.0                   
    
    loaded via a namespace (and not attached):
     [1] codetools_0.2-15       listenv_0.7.0          withr_2.1.1           
     [4] digest_0.6.15          assertthat_0.2.0       R6_2.2.2              
     [7] jsonlite_1.5           magrittr_1.5           httr_1.3.1            
    [10] rlang_0.2.0            curl_3.2               testthat_2.0.0        
    [13] googleAuthR_0.6.2.9000 boot_1.3-20            devtools_1.13.4       
    [16] tools_3.4.3            yaml_2.1.18            compiler_3.4.3        
    [19] globals_0.11.0         memoise_1.1.0          openssl_0.9.9 
    
  7. HenrikBengtsson commented on Apr 28, 2018

    @HenrikBengtsson
    Collaborator

    Ok, I'll look into this. As a starter I'll try to make that assertion error message more informative. These updates will be done to the doFuture package, but I'll let you know here we there's something new you can try out.

    PS. The assertion message is making sure that the collected results from the workers are of the proper length after being turned into a list - in your case it's not, which could be because there's one or more iterations that somehow return something out of the ordinary. This is what I need to figure out.

  8. changed the title [-]Error: length(results) == nbr_of_elements is not TRUE[/-] [+]doFuture: Error: length(results) == nbr_of_elements is not TRUE[/+] on Apr 28, 2018
  9. HenrikBengtsson commented on Apr 28, 2018

    @HenrikBengtsson
    Collaborator

    Please retry with the develop version of doFuture:

    remotes::install_github('HenrikBengtsson/doFuture@develop')

    Instead of the not-so-informative assertion error:

    Error: length(results) == nbr_of_elements is not TRUE
    

    you should now get something like:

    Unexpected error in doFuture(): After gathering and merging the results from 4 chunks in
    to a list, the total number of elements (= 99) does not match the number of input elements
    in 'X' (= 100). There were in total 4 chunks and 4 elements (1 chunks with 24 elements,
    3 chunks with 25 elements)
    

    Hopefully this will help narrow in on what's happening to your GCE processing.

  10. nbarsch commented on Apr 28, 2018

    @nbarsch
    Author

    Ok trying this now.

  11. nbarsch commented on Apr 28, 2018

    @nbarsch
    Author
    > y <- foreach(i=1:100, .packages="boot") %dopar% {
    +   ind <- run()
    + }
    

    Error: Unexpected error in doFuture(): After gathering and merging the results from 7 chunks in to a list, the total number of elements (= 14) does not match the number of input elements in 'X' (= 100). There were in total 7 chunks and 7 elements (7 chunks with 2 elements)

    This looks similar to your error above, but I'm struggling to understand what it means.

  12. HenrikBengtsson commented on Apr 28, 2018

    @HenrikBengtsson
    Collaborator

    Got it. If you rerun with:

    options(doFuture.debug = TRUE)

    you should should be able to see the str() output of the 7 chunks and then the generated list of 14 elements. That should tell us what those 7 chunks are actually containing.

  13. nbarsch commented on Apr 28, 2018

    @nbarsch
    Author
    > y <- foreach(i=1:100, .packages="boot") %dopar% {
    +   ind <- run()
    + }
    doFuture() ...
    - dummy globals (as locals): [1] ‘i’
    - R expression:
    {
        doFuture::registerDoFuture(globalsAs = "*")
        lapply(seq_along(...future.x_ii), FUN = function(jj) {
            ...future.x_jj <- ...future.x_ii[[jj]]
            i <- NULL
            ...future.env <- environment()
            local({
                for (name in names(...future.x_jj)) {
                    assign(name, ...future.x_jj[[name]], envir = ...future.env, 
                      inherits = FALSE)
                }
            })
            tryCatch({
                ind <- run()
            }, error = identity)
        })
    }
    - identifying globals and packages ...
    List of 2
     $ ...future.x_ii: NULL
     $ run           :function (...)  
      ..- attr(*, "srcref")=Class 'srcref'  atomic [1:8] 1 8 5 1 8 1 1 5
      .. .. ..- attr(*, "srcfile")=Classes 'srcfilecopy', 'srcfile' <environment: 0x10d012ae8> 
     - attr(*, "where")=List of 2
      ..$ ...future.x_ii:<environment: 0x10ccb0ea8> 
      ..$ run           :<environment: R_GlobalEnv> 
     - attr(*, "class")= chr [1:3] "FutureGlobals" "Globals" "list"
     - attr(*, "resolved")= logi FALSE
     - attr(*, "total_size")= num 10856
      - R expression:
    {
        doFuture::registerDoFuture(globalsAs = "*")
        lapply(seq_along(...future.x_ii), FUN = function(jj) {
            ...future.x_jj <- ...future.x_ii[[jj]]
            i <- NULL
            ...future.env <- environment()
            local({
                for (name in names(...future.x_jj)) {
                    assign(name, ...future.x_jj[[name]], envir = ...future.env, 
                      inherits = FALSE)
                }
            })
            tryCatch({
                ind <- run()
            }, error = identity)
        })
    }
      - globals: [2] ‘...future.x_ii’, ‘run’
    List of 2
     $ ...future.x_ii: NULL
     $ run           :function (...)  
      ..- attr(*, "srcref")=Class 'srcref'  atomic [1:8] 1 8 5 1 8 1 1 5
      .. .. ..- attr(*, "srcfile")=Classes 'srcfilecopy', 'srcfile' <environment: 0x10d012ae8> 
     - attr(*, "where")=List of 2
      ..$ ...future.x_ii:<environment: 0x10ccb0ea8> 
      ..$ run           :<environment: R_GlobalEnv> 
     - attr(*, "class")= chr [1:3] "FutureGlobals" "Globals" "list"
     - attr(*, "resolved")= logi FALSE
     - attr(*, "total_size")= num 10856
      - packages: [2] ‘boot’, ‘stats’
    - identifying globals and packages ... DONE
    Number of chunks: 7
    Number of futures (= number of chunks): 7
    Launching 7 futures (chunks) ...
    Chunk #1 of 7 ...
    Chunk #1 of 7 ... DONE
    Chunk #2 of 7 ...
    Chunk #2 of 7 ... DONE
    Chunk #3 of 7 ...
    Chunk #3 of 7 ... DONE
    Chunk #4 of 7 ...
    Chunk #4 of 7 ... DONE
    Chunk #5 of 7 ...
    Chunk #5 of 7 ... DONE
    Chunk #6 of 7 ...
    Chunk #6 of 7 ... DONE
    Chunk #7 of 7 ...
    Chunk #7 of 7 ... DONE
    Launching 7 futures (chunks) ... DONE
    - resolving future
    - collecting values of future
    Unexpected error in doFuture(): After gathering and merging the results from 7 chunks in to a list, the total number of elements (= 14) does not match the number of input elements in 'X' (= 100). There were in total 7 chunks and 7 elements (7 chunks with 2 elements)
    chunk_sizes
    2 
    7 
    Results before merge chunks:
    List of 7
     $ :List of 2
      ..$ message: chr "there is no package called ‘doFuture’"
      ..$ call   : language loadNamespace(name)
      ..- attr(*, "class")= chr [1:3] "simpleError" "error" "condition"
     $ :List of 2
      ..$ message: chr "there is no package called ‘doFuture’"
      ..$ call   : language loadNamespace(name)
      ..- attr(*, "class")= chr [1:3] "simpleError" "error" "condition"
     $ :List of 2
      ..$ message: chr "there is no package called ‘doFuture’"
      ..$ call   : language loadNamespace(name)
      ..- attr(*, "class")= chr [1:3] "simpleError" "error" "condition"
     $ :List of 2
      ..$ message: chr "there is no package called ‘doFuture’"
      ..$ call   : language loadNamespace(name)
      ..- attr(*, "class")= chr [1:3] "simpleError" "error" "condition"
     $ :List of 2
      ..$ message: chr "there is no package called ‘doFuture’"
      ..$ call   : language loadNamespace(name)
      ..- attr(*, "class")= chr [1:3] "simpleError" "error" "condition"
     $ :List of 2
      ..$ message: chr "there is no package called ‘doFuture’"
      ..$ call   : language loadNamespace(name)
      ..- attr(*, "class")= chr [1:3] "simpleError" "error" "condition"
     $ :List of 2
      ..$ message: chr "there is no package called ‘doFuture’"
      ..$ call   : language loadNamespace(name)
      ..- attr(*, "class")= chr [1:3] "simpleError" "error" "condition"
    Results after merge chunks:
    List of 14
     $ message: chr "there is no package called ‘doFuture’"
     $ call   : language loadNamespace(name)
     $ message: chr "there is no package called ‘doFuture’"
     $ call   : language loadNamespace(name)
     $ message: chr "there is no package called ‘doFuture’"
     $ call   : language loadNamespace(name)
     $ message: chr "there is no package called ‘doFuture’"
     $ call   : language loadNamespace(name)
     $ message: chr "there is no package called ‘doFuture’"
     $ call   : language loadNamespace(name)
     $ message: chr "there is no package called ‘doFuture’"
     $ call   : language loadNamespace(name)
     $ message: chr "there is no package called ‘doFuture’"
     $ call   : language loadNamespace(name)
    Error: Unexpected error in doFuture(): After gathering and merging the results from 7 chunks in to a list, the total number of elements (= 14) does not match the number of input elements in 'X' (= 100). There were in total 7 chunks and 7 elements (7 chunks with 2 elements)
    
  14. nbarsch commented on Apr 28, 2018

    @nbarsch
    Author

    I'm just getting familiar with futures and doparallel (I have a ton of foreach experience less running it parallel) but it looked like it could be an issue with the .packages() so I changed it to .packages=c("boot","doFuture") and got a different error:

    Number of chunks: 7
    Number of futures (= number of chunks): 7
    Launching 7 futures (chunks) ...
    Chunk #1 of 7 ...
    Chunk #1 of 7 ... DONE
    Chunk #2 of 7 ...
    Chunk #2 of 7 ... DONE
    Chunk #3 of 7 ...
    Chunk #3 of 7 ... DONE
    Chunk #4 of 7 ...
    Chunk #4 of 7 ... DONE
    Chunk #5 of 7 ...
    Chunk #5 of 7 ... DONE
    Chunk #6 of 7 ...
    Chunk #6 of 7 ... DONE
    Chunk #7 of 7 ...
    Chunk #7 of 7 ... DONE
    Launching 7 futures (chunks) ... DONE
    - resolving future
    - collecting values of future
    Error: Internal error: Unexpected result retrieved for ClusterFuture future (‘<none>’): ‘{; doFuture::registerDoFuture(globalsAs = "*"); lapply(seq_along(...future.x_ii), FUN = function(jj) {; ...future.x_jj <- ...future.x_ii[[jj]]; i <- NULL; ...future.env <- environment(); ...; }, error = identity); }); }’
    
  15. HenrikBengtsson commented on Apr 28, 2018

    @HenrikBengtsson
    Collaborator

    Ok, so installing doFuture on your GCE workers should solve/workaround this. If you use:

    cl <- as.cluster(vms)
    clusterEvalQ(cl, install.packages("doFuture"))
    plan(cluster, workers = cl)

    I'd expect that the foreach() call would work after that.

    Alternatively, use my https://hub.docker.com/r/henrikbengtsson/r-base-future/ Docker file. This is actually what's used in the https://www.jottr.org/2017/03/18/dofuture/ example;

    vms <- lapply(paste0("node", 1:10), FUN = googleComputeEngineR::gce_vm, template = "r-base")
    vms <- lapply(vms, FUN = gce_ssh_setup)
    vms <- as.cluster(vms, docker_image = "henrikbengtsson/r-base-future")

    This was a good example of how error handling should be improved in doFuture (and future.apply). I'll make sure to improve upon this. It's probably also related to recent attempts to improve what type of results can be used in future (>= 1.8.0). So, thanks for reporting on this.

  16. 1 remaining item

  17. HenrikBengtsson commented on Apr 29, 2018

    @HenrikBengtsson
    Collaborator

    No worries; this should go smoothly and when it doesn't the error message should be clear. Things needs to be improved on my end.

    Having said this, do not use your .packages approach. The doFuture package plays a special role here and needs to be available on the worker before that comes in play in the internal code. It's different from other packages that needs to be "exported".

    Instead, follow my instruction in #220 (comment) to pre-install doFuture early on before you even bring in foreach.

  18. HenrikBengtsson commented on Apr 29, 2018

    @HenrikBengtsson
    Collaborator

    ... or did you say you did install doFuture according to my instructions and you're still getting that error? If that's the case, drop "doFuture" from .packages.

    PS. I haven't reproduced your problem myself, but I'm planning to do it when I find the time (futureverse/doFuture#25).

  19. nbarsch commented on Apr 29, 2018

    @nbarsch
    Author

    Yes I still get the error after installing doFuture across the cluster in the method 1 of the #220 comment you referred to above, without the docker image.

    I'm trying to create the vm's using the docker image now, but when I try to cluster 7 together the as.cluster function times out:

    Do you know how to set the timeout limit higher?

    Status: Downloaded newer image for henrikbengtsson/r-base-future:latest
    Error in socketConnection("localhost", port = port, server = TRUE, blocking = TRUE,  : 
      reached elapsed time limit
    

    Thanks again for all your help!

  20. HenrikBengtsson commented on Apr 29, 2018

    @HenrikBengtsson
    Collaborator

    Ok, I'll probably have to make I sure I can reproduce a few things myself locally before I can give some more concrete instructions. The one thing I can say is that in order for the foreach() call to work you need to make sure doFuture is available on all the workers. One way to check that is do make sure you get all TRUE:s from call:

    clusterEvalQ(cl, requireNamespace("doFuture"))

    If there are any FALSE returns, then doFuture was not successfully installed on that worker.

  21. HenrikBengtsson commented on Apr 29, 2018

    @HenrikBengtsson
    Collaborator

    Ok, so I've setup up some doFuture package tests that emulate when the doFuture package is not available on a worker. Reinstall doFuture 0.6.0-9001;

    remotes::install_github('HenrikBengtsson/doFuture@develop')

    and also the develop version of future 1.8.0-9000;

    remotes::install_github('HenrikBengtsson/future@develop')

    Then you will get the following error message whenever you use foreach() and the doFuture package is missing on the worker:

    Error: Unexpected result (of class 'snow-try-error' != 'FutureResult') retrieved for
    ClusterFuture future (label = '<none>', expression = '{; doFuture::registerDoFuture(
    globalsAs = "*"); lapply(seq_along(...future.x_ii), FUN = function(jj) {; ...future.x_jj <-
     ...future.x_ii[[jj]]; ii <- NULL; ...future.env <- environment(); ...; tryCatch(ii, error = 
    identity); }); }'): there is no package called 'doFuture'
  22. HenrikBengtsson commented on May 1, 2018

    @HenrikBengtsson
    Collaborator

    Have you had a chance to retry? I'm going to submit a future 1.8.1 release to CRAN soon, so I'd like to know if there's anything else I should tweak in error message from the future package that could help here.

  23. nbarsch commented on May 4, 2018

    @nbarsch
    Author

    Ooof sorry bout the slow response Henrik! I'm gonna test this now, I got caught on another project for a couple days!

  24. nbarsch commented on May 4, 2018

    @nbarsch
    Author

    I'm still getting the same error, despite that doFuture is installed on the cluster nodes:

    > clusterEvalQ(cl, requireNamespace("doFuture"))
    [[1]]
    [1] TRUE
    
    [[2]]
    [1] TRUE
    
    [[3]]
    [1] TRUE
    
    plan(cluster, workers=cl)
    > registerDoFuture()
    > y <- foreach(i=1:100) %dopar% {
    +   ind <- run()
    + }
    Error: Unexpected error in doFuture(): After gathering and merging the results from 3 chunks in to a list, the total number of elements (= 6) does not match the number of input elements in 'X' (= 100). There were in total 3 chunks and 3 elements (3 chunks with 2 elements)
    
    
    

    With verbose:

    > options(doFuture.debug = TRUE)
    > plan(cluster, workers=cl)
    > registerDoFuture()
    > y <- foreach(i=1:100) %dopar% {
    +   ind <- run()
    + }
    doFuture() ...
    - dummy globals (as locals): [1] ‘i’
    - R expression:
    {
        doFuture::registerDoFuture(globalsAs = "*")
        lapply(seq_along(...future.x_ii), FUN = function(jj) {
            ...future.x_jj <- ...future.x_ii[[jj]]
            i <- NULL
            ...future.env <- environment()
            local({
                for (name in names(...future.x_jj)) {
                    assign(name, ...future.x_jj[[name]], envir = ...future.env, 
                      inherits = FALSE)
                }
            })
            tryCatch({
                ind <- run()
            }, error = identity)
        })
    }
    - identifying globals and packages ...
    List of 2
     $ ...future.x_ii: NULL
     $ run           :function (...)  
      ..- attr(*, "srcref")=Class 'srcref'  atomic [1:8] 1 8 5 1 8 1 1 5
      .. .. ..- attr(*, "srcfile")=Classes 'srcfilecopy', 'srcfile' <environment: 0x1101f96d8> 
     - attr(*, "where")=List of 2
      ..$ ...future.x_ii:<environment: 0x10a1f4640> 
      ..$ run           :<environment: R_GlobalEnv> 
     - attr(*, "class")= chr [1:3] "FutureGlobals" "Globals" "list"
     - attr(*, "resolved")= logi FALSE
     - attr(*, "total_size")= num 10856
      - R expression:
    {
        doFuture::registerDoFuture(globalsAs = "*")
        lapply(seq_along(...future.x_ii), FUN = function(jj) {
            ...future.x_jj <- ...future.x_ii[[jj]]
            i <- NULL
            ...future.env <- environment()
            local({
                for (name in names(...future.x_jj)) {
                    assign(name, ...future.x_jj[[name]], envir = ...future.env, 
                      inherits = FALSE)
                }
            })
            tryCatch({
                ind <- run()
            }, error = identity)
        })
    }
      - globals: [2] ‘...future.x_ii’, ‘run’
    List of 2
     $ ...future.x_ii: NULL
     $ run           :function (...)  
      ..- attr(*, "srcref")=Class 'srcref'  atomic [1:8] 1 8 5 1 8 1 1 5
      .. .. ..- attr(*, "srcfile")=Classes 'srcfilecopy', 'srcfile' <environment: 0x1101f96d8> 
     - attr(*, "where")=List of 2
      ..$ ...future.x_ii:<environment: 0x10a1f4640> 
      ..$ run           :<environment: R_GlobalEnv> 
     - attr(*, "class")= chr [1:3] "FutureGlobals" "Globals" "list"
     - attr(*, "resolved")= logi FALSE
     - attr(*, "total_size")= num 10856
      - packages: [2] ‘boot’, ‘stats’
    - identifying globals and packages ... DONE
    Number of chunks: 3
    Number of futures (= number of chunks): 3
    Launching 3 futures (chunks) ...
    Chunk #1 of 3 ...
    Chunk #1 of 3 ... DONE
    Chunk #2 of 3 ...
    Chunk #2 of 3 ... DONE
    Chunk #3 of 3 ...
    Chunk #3 of 3 ... DONE
    Launching 3 futures (chunks) ... DONE
    - resolving future
    - collecting values of future
    Unexpected error in doFuture(): After gathering and merging the results from 3 chunks in to a list, the total number of elements (= 6) does not match the number of input elements in 'X' (= 100). There were in total 3 chunks and 3 elements (3 chunks with 2 elements)
    chunk_sizes
    2 
    3 
    Results before merge chunks:
    List of 3
     $ :List of 2
      ..$ message: chr "unused argument (globalsAs = \"*\")"
      ..$ call   : language doFuture::registerDoFuture(globalsAs = "*")
      ..- attr(*, "class")= chr [1:3] "simpleError" "error" "condition"
     $ :List of 2
      ..$ message: chr "unused argument (globalsAs = \"*\")"
      ..$ call   : language doFuture::registerDoFuture(globalsAs = "*")
      ..- attr(*, "class")= chr [1:3] "simpleError" "error" "condition"
     $ :List of 2
      ..$ message: chr "unused argument (globalsAs = \"*\")"
      ..$ call   : language doFuture::registerDoFuture(globalsAs = "*")
      ..- attr(*, "class")= chr [1:3] "simpleError" "error" "condition"
    Results after merge chunks:
    List of 6
     $ message: chr "unused argument (globalsAs = \"*\")"
     $ call   : language doFuture::registerDoFuture(globalsAs = "*")
     $ message: chr "unused argument (globalsAs = \"*\")"
     $ call   : language doFuture::registerDoFuture(globalsAs = "*")
     $ message: chr "unused argument (globalsAs = \"*\")"
     $ call   : language doFuture::registerDoFuture(globalsAs = "*")
    Error: Unexpected error in doFuture(): After gathering and merging the results from 3 chunks in to a list, the total number of elements (= 6) does not match the number of input elements in 'X' (= 100). There were in total 3 chunks and 3 elements (3 chunks with 2 elements)
    
  25. HenrikBengtsson commented on May 4, 2018

    @HenrikBengtsson
    Collaborator

    Have you updated to future 1.8.1, which was release on CRAN yesterday?

  26. HenrikBengtsson commented on May 4, 2018

    @HenrikBengtsson
    Collaborator

    And I'm sure if you update doFuture too on master those "unused argument" errors also go away, because I fixed that when I posted #220 (comment)

  27. HenrikBengtsson commented on May 11, 2018

    @HenrikBengtsson
    Collaborator

    Any news? Can I close?

  28. HenrikBengtsson commented on Jun 13, 2018

    @HenrikBengtsson
    Collaborator

    I think I've solved this one - if you still observe issues, please feel free to reopen.

  29. brickyyyy commented on Mar 11, 2019

    @brickyyyy

    I get the following error even after updating all packages.
    `Error: Unexpected result (of class ‘snow-try-error’ != ‘FutureResult’) retrieved for ClusterFuture future (label = ‘’, expression = ‘{; doFuture::registerDoFuture(); lapply(seq_along(...future.x_ii), FUN = function(jj) {; ...future.x_jj <- ...future.x_ii[[jj]]; i <- NULL; ...future.env <- environment(); ...; }, error = identity); }); }’): there is no package called ‘doFuture’. This suggests that the communication with ClusterFuture worker (‘SOCKnode’ #1) is out of sync.
    Traceback:

    1. main_method(object, ks = 10)
    2. main_method(object, ks = 10)
    3. calc_dists(object)
    4. calc_dists(object)
    5. foreach::foreach(i = distances) %dopar% {
      . try({
      . calculate_distance(dataset, i)
      . })
      . }
    6. e$fun(obj, substitute(ex), parent.frame(), e$data)
    7. lapply(fs, FUN = value, stdout = FALSE, signal = FALSE)
    8. FUN(X[[i]], ...)
    9. value.Future(X[[i]], ...)
    10. result(future)
    11. result.ClusterFuture(future)`
      Any suggestions would be appreciated!
  30. HenrikBengtsson commented on Mar 11, 2019

    @HenrikBengtsson
    Collaborator

    @brickyyyy, that looks like a different error from what's reported in this issue. Please post a new issue with full details what you are doing including code and sessionInfo(). Also, make sure you can get things working with a very simple example first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions