-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmultiBatchScript.R
More file actions
100 lines (70 loc) · 3 KB
/
multiBatchScript.R
File metadata and controls
100 lines (70 loc) · 3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# multiBatchScript.R
# A wrapper script to run multiple parallel batches
# with limited user input - likely worth
# creating two versions of this for the two
# Mac Pros
library(parallel)
source("ms3R.r")
# source("makeResultPlots.R")
batchControlFiles <- c( #"omniRuns_econYield_noCorr.bch",
"omniRuns_priceDevPED.bch")
#"omniRuns_econYield_noCorr_sens.bch")
nBatchJobs <- length( batchControlFiles )
baseControlFiles <- c( #"simCtlFileBase.txt",
"simCtlFileBase_NULLprice.txt")
#"simCtlFileBase.txt" )
prefixes <- c( #"omniRuns_noCorr_apr26",
"omniRuns_noCorr_demCurveSens")
#"omniRuns_Sens_May14" )
saveDirName <- prefixes
baseLine <- c( NULL,NULL,NULL,NULL,NULL )
nCores <- c(24,24,24)
par <- c(FALSE,FALSE,FALSE)
# Create a directory to hold completed mseR batch
# jobs
for( s in saveDirName)
if(!dir.exists( here::here("Outputs",s) ))
dir.create(here::here("Outputs",s))
for( bIdx in 1:nBatchJobs )
{
message( "Starting batch for ",
batchControlFiles[bIdx], ".\n", sep = "")
# Make the batch
makeBatch( baseCtlFile = baseControlFiles[bIdx],
batchCtlFile = batchControlFiles[bIdx])
# Run the batch in parallel - new
# format should stop errors from
# crashing runParBatch
tryPar <- try(.runBatchJob( par = par[bIdx],
nCores = nCores[bIdx],
prefix = prefixes[bIdx] ) )
# Calculate loss functions - need to detect our
# batch sims here
outputDirList <- list.dirs("./Outputs",recursive = FALSE, full.names = FALSE)
outputDirList <- outputDirList[grepl("sim_",outputDirList)]
outputDirList <- outputDirList[order(outputDirList)]
ourSimIndices <- which(grepl(prefixes[bIdx],outputDirList))
if(!is.null(baseLine[bIdx]))
lapply( X = ourSimIndices, FUN = calcLoss, baseline = baseLine[bIdx], groupFolder = "" )
# Tidy up memory
gc()
# Now copy fits to a subfolder location for easier filing
destFolder <- file.path(".","Outputs",saveDirName[bIdx])
projFolderContents <- list.dirs( "./Outputs",
recursive = FALSE,
full.names = FALSE )
# Restrict to the fits with this prefix
projFolderContents <- projFolderContents[grepl("sim_",projFolderContents)]
projFolderContents <- projFolderContents[grepl(prefixes[bIdx],projFolderContents)]
oldPath <- here::here("Outputs/",projFolderContents)
newPath <- file.path(destFolder,projFolderContents)
for( k in 1:length(oldPath))
fs::dir_copy(oldPath[k], newPath[k], overwrite = TRUE)
fs::dir_delete(oldPath)
# Run makeResultsPlots
# makeResultPlots(saveDirName[bIdx])
message( "Parallel batch complete for ",
batchControlFiles[bIdx],
" and fits copied and tidied up for next batch.\n",sep = "")
}
message( "All batch jobs complete!\n" )