BiocParallel (version 1.0.3)

bpresume: Resume computation with partial results

Description

Resume partial successful calls to bplapply or bpmapply

Usage

bplasterror() bpresume(expr)

Arguments

expr
expression

Usage

The resume mechanism is triggered if the argument catch.errors of the BiocParallelParam class is set to TRUE. The methods bplapply and bpmapply then store the current state of computation. Recalling the call directory with argument BPRESUME set to TRUE will then only compute the missing parts of the previous call and merge the results. Alternatively, if the call to bplapply and bpmapply is inside a function not accessible directly by the user, the last call can be embedded into bpresume which sets an option accordingly to enable the resume feature down in the call stack. The function bplasterror returns a LastError object containing the partial results and errors to investigate. Note that nested calls of the apply functions can cause troubles in some scenarios.

Examples

Run this code

## -----------------------------------------------------------------------
## Catch errors: 
## -----------------------------------------------------------------------

## By default 'catch.errors' is TRUE in BiocParallelParam objects.
SnowParam(workers = 2)

## If 'catch.errors' is FALSE an ill-fated bplapply() simply stops
## displaying the error message.
snowp <- SnowParam(workers = 2, catch.errors = FALSE)
## Not run: 
# > res <- bplapply(list(1, "two", 3), sqrt, BPPARAM = snowp)
# Error in checkForRemoteErrors(val) : 
#   one node produced an error: non-numeric argument to mathematical function
# ## End(Not run)

## When 'catch.errors' is TRUE the same call provides traceback
## information (truncated here) and suggests use of bplasterror() and
## bpresume().
snowp <- SnowParam(workers = 2)
## Not run: 
# > res <- bplapply(list(1, "two", 3), sqrt, BPPARAM = snowp)
# Error: 1 errors; first error:
#   Error in FUN(...): non-numeric argument to mathematical function
# 
# For more information, use bplasterror(). To resume calculation, re-call
#   the function and set the argument 'BPRESUME' to TRUE or wrap the
#   previous call in bpresume().
# 
# First traceback:
#   19: parallel:::.slaveRSOCK()
#   18: slaveLoop(makeSOCKmaster(master, port, timeout, useXDR))
# ...
# ## End(Not run)

## bplasterror() reports the number of successful results and error message.
## Not run: 
# > bplasterror()
# 2 / 3 partial results stored. First 1 error messages:
# [2]: Error in FUN(...): non-numeric argument to mathematical function
# ## End(Not run)

## -----------------------------------------------------------------------
## Resume calculations: 
## -----------------------------------------------------------------------

## The 'resume' mechanism attempts to re-run the data element that failed.
## In our example the character "two" list element will never succeed. In 
## the runs below we replace the character with a numeric and compute the
## result.

## There are two methods for resuming a suspended calculation, one 
## approach is to wrap the original call in bpresume().
## Not run: 
# > bpresume(res <- bplapply(list(1, 2, 3), sqrt, BPPARAM = snowp))
# Resuming previous calculation... 
# > res
# [[1]]
# [1] 1
# 
# [[2]]
# [1] 1.414214
# 
# [[3]]
# [1] 1.732051
# ## End(Not run)

## An equivalent approach is to set 'BPRESUME = TRUE' in bplapply().
## Not run: 
# res <- bplapply(list(1, 2, 3), sqrt, BPPARAM = snowp, BPRESUME = TRUE)
# ## End(Not run)

Run the code above in your browser using DataLab