From dc7f7b8a8ca79e9fc9accb69d53bb53621f2feb3 Mon Sep 17 00:00:00 2001 From: ned-procogia <91500603+ned-procogia@users.noreply.github.com> Date: Wed, 19 Jan 2022 14:22:52 -0800 Subject: [PATCH 1/2] bug fix - parallel error handling catch parallel processes which fail and repeat - append to results --- R/NBthDE.R | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/R/NBthDE.R b/R/NBthDE.R index b9f6c1e..b429afd 100644 --- a/R/NBthDE.R +++ b/R/NBthDE.R @@ -350,6 +350,27 @@ fitNBthDE_funct = function(form, annot, preci1, threshold_mean * probenum[features_high[start_index:end_index]], preci2, startpara, sizescalebythreshold, (iter == iterations)) }, mc.cores = n_parallel) + bad = sapply(result,is.null) + to_retry = 1:n_parallel + to_retry = to_retry[bad] + print("need to retry") + print(to_retry) + if(sum(bad)>0){ + more_results = mclapply(to_retry, function(i) { + my_len = length(features_all) + start_index = (round(((i-1)*my_len/n_parallel))+1) + end_index = round(i*my_len/n_parallel) + NBthDE_paraOptall( + t(object[features_all, ])[,start_index:end_index], X, sizefact_BG, sizefact, + preci1, threshold_mean * probenum[features_all[start_index:end_index]], preci2, + startpara, sizescalebythreshold, (iter == iterations)) + }, mc.cores = sum(bad)) + for(i in 1:length(to_retry)){ + print("changed entry") + print(to_retry[i]) + result[to_retry[i]] = more_results[i] + } + } new_result= list('par'=matrix(,nrow=NROW(result[[1]]$par),ncol=0), 'hes', 'conv'=matrix(,nrow=0,ncol=1)) @@ -386,6 +407,27 @@ fitNBthDE_funct = function(form, annot, preci1, threshold_mean * probenum[features_all[start_index:end_index]], preci2, startpara, sizescalebythreshold, (iter == iterations)) }, mc.cores = n_parallel) + bad = sapply(result,is.null) + to_retry = 1:n_parallel + to_retry = to_retry[bad] + if(sum(bad)>0){ + print("need to retry") + print(to_retry) + more_results = mclapply(to_retry, function(i) { + my_len = length(features_all) + start_index = (round(((i-1)*my_len/n_parallel))+1) + end_index = round(i*my_len/n_parallel) + NBthDE_paraOptall( + t(object[features_all, ])[,start_index:end_index], X, sizefact_BG, sizefact, + preci1, threshold_mean * probenum[features_all[start_index:end_index]], preci2, + startpara, sizescalebythreshold, (iter == iterations)) + }, mc.cores = sum(bad)) + for(i in 1:length(to_retry)){ + print("changed entry") + print(to_retry[i]) + result[to_retry[i]] = more_results[i] + } + } new_result= list('par'=matrix(,nrow=NROW(result[[1]]$par),ncol=0), 'hes', 'conv'=matrix(,nrow=0,ncol=1)) @@ -397,6 +439,8 @@ fitNBthDE_funct = function(form, annot, result=new_result } para <- result$par + print(length(para)) + print(length(features_all)) colnames(para) <- features_all conv <- result$conv names(conv) <- features_all From 7006145ed6db5361a0638bd9badce3a68eb403c5 Mon Sep 17 00:00:00 2001 From: ned-procogia <91500603+ned-procogia@users.noreply.github.com> Date: Wed, 19 Jan 2022 15:11:14 -0800 Subject: [PATCH 2/2] bug fix - parallel processing --- R/NBthDE.R | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/R/NBthDE.R b/R/NBthDE.R index b429afd..e42bd54 100644 --- a/R/NBthDE.R +++ b/R/NBthDE.R @@ -353,9 +353,9 @@ fitNBthDE_funct = function(form, annot, bad = sapply(result,is.null) to_retry = 1:n_parallel to_retry = to_retry[bad] - print("need to retry") - print(to_retry) if(sum(bad)>0){ + print("need to retry") + print(to_retry) more_results = mclapply(to_retry, function(i) { my_len = length(features_all) start_index = (round(((i-1)*my_len/n_parallel))+1) @@ -402,7 +402,7 @@ fitNBthDE_funct = function(form, annot, my_len = length(features_all) start_index = (round(((i-1)*my_len/n_parallel))+1) end_index = round(i*my_len/n_parallel) - NBthDE_paraOptall( + GeoDiff:::NBthDE_paraOptall( t(object[features_all, ])[,start_index:end_index], X, sizefact_BG, sizefact, preci1, threshold_mean * probenum[features_all[start_index:end_index]], preci2, startpara, sizescalebythreshold, (iter == iterations)) @@ -417,7 +417,7 @@ fitNBthDE_funct = function(form, annot, my_len = length(features_all) start_index = (round(((i-1)*my_len/n_parallel))+1) end_index = round(i*my_len/n_parallel) - NBthDE_paraOptall( + GeoDiff:::NBthDE_paraOptall( t(object[features_all, ])[,start_index:end_index], X, sizefact_BG, sizefact, preci1, threshold_mean * probenum[features_all[start_index:end_index]], preci2, startpara, sizescalebythreshold, (iter == iterations))