HenrikBengtsson / future

:rocket: R package: future: Unified Parallel and Distributed Processing in R for Everyone
https://future.futureverse.org
951 stars 83 forks source link

Custom methods not working on HPC/UNIX #614

Closed stephenashton-dhsc closed 2 years ago

stephenashton-dhsc commented 2 years ago

Describe the bug

When I try to run code containing a custom method on a HPC/UNIX environment, it does not appear to detect the method definition.

Reproduce example

methods::setGeneric(
  "my_custom_method",
  function(x) {
    standardGeneric("my_custom_method")
  }
)

methods::setMethod(
  "my_custom_method",
  methods::signature(x = "numeric"),
  function(x) {
    y <- x^2
    return(y)
  }
)

library(future)
future::plan("future::sequential")
f <- future({1^2})
value(f)

Return:

Error in (function (classes, fdef, mtable)  : 
  unable to find an inherited method for function ‘my_custom_method’ for signature ‘"numeric"’
Calls: value -> value.Future -> signalConditions
Execution halted

Expected behavior

[1] 1

Session information

Please share your session information after the error has occurred so that we also see which packages and versions are involved;

> sessionInfo()
R version 4.1.3 (2022-03-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19042)

Matrix products: default

locale:
[1] LC_COLLATE=English_United Kingdom.1252  LC_CTYPE=English_United Kingdom.1252   
[3] LC_MONETARY=English_United Kingdom.1252 LC_NUMERIC=C                           
[5] LC_TIME=English_United Kingdom.1252    

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

other attached packages:
[1] future_1.25.0

loaded via a namespace (and not attached):
[1] compiler_4.1.3    parallelly_1.31.1 parallel_4.1.3    tools_4.1.3       listenv_0.8.0    
[6] codetools_0.2-18  digest_0.6.29     globals_0.14.0 

> future::futureSessionInfo()
*** Package versions
future 1.25.0, parallelly 1.31.1, parallel 4.1.3, globals 0.14.0, listenv 0.8.0

*** Allocations
availableCores():
system 
     8 
availableWorkers():
$system
[1] "localhost" "localhost" "localhost" "localhost" "localhost" "localhost" "localhost" "localhost"

*** Settings
- future.plan=<not set>
- future.fork.multithreading.enable=<not set>
- future.globals.maxSize=<not set>
- future.globals.onReference=<not set>
- future.resolve.recursive=<not set>
- future.rng.onMisuse=<not set>
- future.wait.timeout=<not set>
- future.wait.interval=<not set>
- future.wait.alpha=<not set>
- future.startup.script=<not set>

*** Backends
Number of workers: 1
List of future strategies:
1. sequential:
   - args: function (..., envir = parent.frame())
   - tweaked: FALSE
   - call: NULL

*** Basic tests
  worker   pid     r sysname release     version      nodename machine          login           user
1      1 20460 4.1.3 Windows  10 x64 build 19042 PHE-4K097131H  x86-64 Stephen.Ashton Stephen.Ashton
  effective_user
1 Stephen.Ashton
Number of unique PIDs: 1 (as expected)
stephenashton-dhsc commented 2 years ago

Apologies - I was originally seeing the error in furrr, but I think I translated it into future incorrectly