1

我目前正在使用furrr我的模型创建更有条理的执行。我使用 adata.frame以有序的方式将参数传递给函数,然后使用 将furrr::future_map()函数映射到所有参数。在我的本地机器(OSX)上使用顺序和多核期货时,该功能可以完美运行。

现在,我想测试创建自己的 AWS 实例集群的代码(如图所示

我使用链接的文章代码创建了一个函数:

make_cluster_ec2  <- function(public_ip){
  ssh_private_key_file  <-  Sys.getenv('PEM_PATH')
  github_pac  <-  Sys.getenv('PAC')

  cl_multi <- future::makeClusterPSOCK(
  workers = public_ip,
  user = "ubuntu",
  rshopts = c(
    "-o", "StrictHostKeyChecking=no",
    "-o", "IdentitiesOnly=yes",
    "-i", ssh_private_key_file
  ),
  rscript_args = c(
    "-e", shQuote("local({p <- Sys.getenv('R_LIBS_USER'); dir.create(p, recursive = TRUE, showWarnings = FALSE); .libPaths(p)})"),
    "-e", shQuote("install.packages('devtools')"),
    "-e", shQuote(glue::glue("devtools::install_github('user/repo', auth_token = '{github_pac}')"))
  ),
  dryrun = FALSE)

  return(cl_multi)

}

然后,我创建集群对象,然后检查它是否连接到正确的实例

public_ids <- c('public_ip_1', 'public_ip_2')
cls <- make_cluster_ec2(public_ids)
f <- future(Sys.info())

当我打印时,f我得到了我的一个远程实例的规格,这表明套接字已正确连接:

> value(f)
                                      sysname
                                      "Linux"
                                      release
                            "4.15.0-1037-aws"
                                      version
"#39-Ubuntu SMP Tue Apr 16 08:09:09 UTC 2019"
                                     nodename
                           "ip-xxx-xx-xx-xxx"
                                      machine
                                     "x86_64"
                                        login
                                     "ubuntu"
                                         user
                                     "ubuntu"
                               effective_user
                                     "ubuntu"

但是当我使用我的集群计划运行我的代码时:

plan(list(tweak(cluster, workers = cls), multisession))
  parameter_df %>%
  mutate(model_traj =  furrr::future_pmap(list('lat' = latitude,
                               'lon' = longitude,
                               'height' = stack_height,
                               'name_source' = facility_name,
                               'id_source' = facility_id,
                               'duration' = duration,
                               'days' = seq_dates,
                               'daily_hours' = daily_hours,
                               'direction' = 'forward',
                               'met_type' = 'reanalysis',
                               'met_dir' = here::here('met'),
                               'exec_dir' = here::here("Hysplit4/exec"),
                               'cred'= list(creds)),
                           dirtywind::hysplit_trajectory,
                           .progress = TRUE)
  )

我收到以下错误:

Error in file(temp_file, "a") : cannot open the connection
In addition: Warning message:
In file(temp_file, "a") :
  cannot open file '/var/folders/rc/rbmg32js2qlf4d7cd4ts6x6h0000gn/T//RtmpPvdbV3/filecf23390c093.txt': No such file or directory

我无法弄清楚引擎盖下发生了什么,我也无法traceback()从我的远程机器上看到错误。我已经测试了与文章中示例的连接,并且事情似乎运行正常。我想知道为什么要tempdir在执行期间创建一个。我在这里想念什么?

(这也是repo中的一个问题)furrr

4

1 回答 1

4

禁用进度条,即不指定.progress = TRUE.

这是因为.progress = TRUE 假设您的 R 工作人员可以写入主 R 进程创建的临时文件。这通常只有在您在同一台机器上并行化时才有可能。

此错误的一个较小示例是:

library(future)
## Set up a cluster with one worker running on another machine
cl <- makeClusterPSOCK(workers = "node2")
plan(cluster, workers = cl)

y <- furrr::future_map(1:2, identity, .progress = FALSE)
str(y)
## List of 2
##  $ : int 1
##  $ : int 2

y <- furrr::future_map(1:2, identity, .progress = TRUE)
## Error in file(temp_file, "a") : cannot open the connection
## In addition: Warning message:
## In file(temp_file, "a") :
##   cannot open file '/tmp/henrik/Rtmp1HkyJ8/file4c4b864a028ac.txt': No such file or directory
于 2020-01-08T23:09:10.530 回答