[Swift-commit] r3253 - SwiftApps/SwiftR
noreply at svn.ci.uchicago.edu
noreply at svn.ci.uchicago.edu
Tue Feb 23 12:32:38 CST 2010
Author: wilde
Date: 2010-02-23 12:32:38 -0600 (Tue, 23 Feb 2010)
New Revision: 3253
Modified:
SwiftApps/SwiftR/RunSwiftScript.sh
SwiftApps/SwiftR/Swift.R
SwiftApps/SwiftR/TestSwift.R
SwiftApps/SwiftR/bootstrapdemo.R
SwiftApps/SwiftR/pboot.R
Log:
Incremental commit: Added swiftopts; adjusted boot() demo; changed = to <- to slowly get R-ified.
Modified: SwiftApps/SwiftR/RunSwiftScript.sh
===================================================================
--- SwiftApps/SwiftR/RunSwiftScript.sh 2010-02-23 04:36:05 UTC (rev 3252)
+++ SwiftApps/SwiftR/RunSwiftScript.sh 2010-02-23 18:32:38 UTC (rev 3253)
@@ -22,7 +22,7 @@
<execution provider="coaster" url="none" jobManager="local:pbs"/>
<profile namespace="globus" key="workersPerNode">8</profile>
<profile namespace="karajan" key="initialScore">10000</profile>
- <profile namespace="karajan" key="jobThrottle">.00</profile>
+ <profile namespace="karajan" key="jobThrottle">5.99</profile>
<filesystem provider="local"/>
<workdirectory>$(pwd)</workdirectory>
</pool>
Modified: SwiftApps/SwiftR/Swift.R
===================================================================
--- SwiftApps/SwiftR/Swift.R 2010-02-23 04:36:05 UTC (rev 3252)
+++ SwiftApps/SwiftR/Swift.R 2010-02-23 18:32:38 UTC (rev 3253)
@@ -1,38 +1,63 @@
-swiftapply <- function( func, arglists, site="local", callsperbatch=1 )
+if(is.null(swiftprops)) {
+ swiftprops.site <- "local"
+ swiftprops$callsperbatch <- 1
+}
+
+swiftapply <- function( func, arglists, site=NULL, callsperbatch=NULL )
{
- rundir = system("mktemp -d SwiftR.run.XXX",intern=TRUE)
- cat("Running in ",rundir,"\n")
- narglists = length(arglists) # number of arglists to process
- batch=1 # Next arglist batch number to fill
- arglist=1 # Next arglist number to insert
+ # Set Swift properties
+
+ if(is.null(site))
+ if( is.null(swiftprops) || is.null(swiftprops$site))
+ site <- "local"
+ else
+ site <- swiftprops$site
+ if(is.null(callsperbatch))
+ if( is.null(swiftprops) || is.null(swiftprops$callsperbatch))
+ callsperbatch <- 1
+ else
+ callsperbatch <- swiftprops$callsperbatch
+ cat("\nSwift R properties:\n")
+ cat(" site =",site,"\n");
+ cat(" callsperbatch =",callsperbatch,"\n")
+
+ # Execute the calls in batches
+
+ rundir <- system("mktemp -d SwiftR.run.XXX",intern=TRUE)
+ cat("Swift running in",rundir,"\n")
+ narglists <- length(arglists) # number of arglists to process
+ batch <- 1 # Next arglist batch number to fill
+ arglist <- 1 # Next arglist number to insert
while(arglist <= narglists) {
- arglistsleft = narglists - arglist + 1
+ arglistsleft <- narglists - arglist + 1
if(arglistsleft >= callsperbatch) {
- batchsize = callsperbatch
+ batchsize <- callsperbatch
}
else {
- batchsize = arglistsleft
+ batchsize <- arglistsleft
}
- arglistbatch = list()
+ arglistbatch <- list()
for(i in 1 : batchsize) {
- arglistbatch[[i]] = arglists[[arglist]]
- arglist = arglist +1
+ arglistbatch[[i]] <- arglists[[arglist]]
+ arglist <- arglist +1
}
- rcall = list(func=func,arglistbatch=arglistbatch)
+ rcall <- list(func=func,arglistbatch=arglistbatch)
save(rcall,file=paste(rundir,"/cbatch.",as.character(batch),".Rdata",sep=""))
- batch = batch + 1;
+ batch <- batch + 1;
}
- nbatches = batch - 1
+ nbatches <- batch - 1
system(paste("./RunSwiftScript.sh",rundir,site,sep=" "))
- rno = 1
- rlist = list()
+ # Fetch the batch results
+
+ rno <- 1
+ rlist <- list()
for(batch in 1:nbatches) {
load(paste(rundir,"/rbatch.",as.character(batch),".Rdata",sep=""))
- nresults = length(result)
+ nresults <- length(result)
for(r in 1:nresults) {
- rlist[[rno]] = result[[r]]
- rno = rno + 1
+ rlist[[rno]] <- result[[r]]
+ rno <- rno + 1
}
}
return(rlist)
@@ -42,14 +67,14 @@
x n args
x batch
- into svn
- unique dirs
- select sites and swift args (throttles etc)
+x into svn
+x unique dirs
+_ select sites and swift args (throttles etc)
R docs
R package (SwiftR)
Swift docs
async exec
- clean up boot: fix all calls to statistics
+ clean up boot: fix all calls to statistics; update boot package w/ pboot() or swiftboot()
error handling and null and missing values: ensure res#s correspond to arg#s
status
specify swift scripts
@@ -60,7 +85,7 @@
pass extra vals
pass extra files
specifiy unique swift scritps ala Dirk's tools
- setup the R envs
+ setup the R envs (???)
coasters for persistent R Servers
test suites
use littleR
Modified: SwiftApps/SwiftR/TestSwift.R
===================================================================
--- SwiftApps/SwiftR/TestSwift.R 2010-02-23 04:36:05 UTC (rev 3252)
+++ SwiftApps/SwiftR/TestSwift.R 2010-02-23 18:32:38 UTC (rev 3253)
@@ -1,42 +1,48 @@
require(boot)
source("Swift.R")
-SKIP=FALSE
sumcrits <- function(duckdata,dogdata) { sum( duckdata$plumage, dogdata$mvo ) }
args=list(ducks,dogs)
arglist = rep(list(args),9)
-if(SKIP) {
+if(TRUE) { # Basic tests
-res = do.call(sumcrits,args)
-cat("Test of do.call(sumcrits)\n")
-print(res)
+ res = do.call(sumcrits,args)
+ cat("Test of do.call(sumcrits)\n")
+ print(res)
-cat("\nTest of swiftapply(sumcrits,arglist)\n")
-res = swiftapply(sumcrits,arglist)
-print(res)
+ cat("\nTest of swiftapply(sumcrits,arglist)\n")
+ res = swiftapply(sumcrits,arglist)
+ print(res)
+}
-cat("\nTest of swiftapply(sumcrits,arglist,callsperbatch=10)\n")
-res = swiftapply(sumcrits,arglist,callsperbatch=10)
-print(res)
+if(FALSE) { # Test various batch sizes
-cat("\nTest of swiftapply(sumcrits,arglist,callsperbatch=2)\n")
-res = swiftapply(sumcrits,arglist,callsperbatch=2)
-print(res)
+ cat("\nTest of swiftapply(sumcrits,arglist,callsperbatch=10)\n")
+ res = swiftapply(sumcrits,arglist,callsperbatch=10)
+ print(res)
-cat("\nTest of swiftapply(sumcrits,arglist,callsperbatch=3)\n")
-res = swiftapply(sumcrits,arglist,callsperbatch=3)
-print(res)
+ cat("\nTest of swiftapply(sumcrits,arglist,callsperbatch=2)\n")
+ res = swiftapply(sumcrits,arglist,callsperbatch=2)
+ print(res)
-cat("\nTest of swiftapply(sumcrits,arglist,callsperbatch=20)\n")
-res = swiftapply(sumcrits,arglist,callsperbatch=20)
-print(res)
+ cat("\nTest of swiftapply(sumcrits,arglist,callsperbatch=3)\n")
+ res = swiftapply(sumcrits,arglist,callsperbatch=3)
+ print(res)
-} # END SKIP
+ cat("\nTest of swiftapply(sumcrits,arglist,callsperbatch=20)\n")
+ res = swiftapply(sumcrits,arglist,callsperbatch=20)
+ print(res)
+}
-cat("\nTest of swiftapply(sumcrits,arglist[1000],callsperbatch=1)\n")
-arglist = rep(list(args),1000)
-res = swiftapply(sumcrits,arglist,callsperbatch=2,site="pbs")
-print(res[[1]])
-print(res[[1000]])
+if(FALSE) { # Larger-scale tests
+
+ cat("\nTest of swiftapply(sumcrits,arglist[1000],callsperbatch=1)\n")
+
+ arglist = rep(list(args),1000)
+ res = swiftapply(sumcrits,arglist,callsperbatch=2,site="pbs")
+
+ print(res[[1]])
+ print(res[[1000]])
+}
Modified: SwiftApps/SwiftR/bootstrapdemo.R
===================================================================
--- SwiftApps/SwiftR/bootstrapdemo.R 2010-02-23 04:36:05 UTC (rev 3252)
+++ SwiftApps/SwiftR/bootstrapdemo.R 2010-02-23 18:32:38 UTC (rev 3253)
@@ -8,6 +8,13 @@
require(OpenMx)
require(boot)
+# Update the boot() function to call swiftapply() for parallel execution.
+
+if(FALSE) {
+ source("pboot.R")
+ assignInNamespace("boot",boot,"boot")
+}
+
# Define a function called mles which will return maximum likelihood estimates
# It uses the demoOneFactor dataset and one factor model on the OpenMx homepage
# http://openmx.psyc.virginia.edu
@@ -32,12 +39,8 @@
# Run 100 bootstraps (a smallish number)
-boot.out=list()
+system.time(boot(demoOneFactor,mles,R=10000))
-boot.out[[1]] = pboot(demoOneFactor,mles,R=100)
-#boot.out[[2]] = boot(demoOneFactor,mles,R=8)
-#boot.out[[3]] = boot(demoOneFactor,mles,R=9)
-
print("done booting - boot.out is:")
print(boot.out)
print("end of boot.out")
Modified: SwiftApps/SwiftR/pboot.R
===================================================================
--- SwiftApps/SwiftR/pboot.R 2010-02-23 04:36:05 UTC (rev 3252)
+++ SwiftApps/SwiftR/pboot.R 2010-02-23 18:32:38 UTC (rev 3253)
@@ -1,4 +1,4 @@
-pboot =
+boot =
function (data, statistic, R, sim = "ordinary", stype = "i",
strata = rep(1, n), L = NULL, m = 0, weights = NULL,
ran.gen = function(d, p) d, mle = NULL, simple = FALSE, ...)
@@ -106,7 +106,7 @@
# for (r in 1L:sum(R)) t.star[r, ] <- statistic(data, i[r, ], ...)
alists = list()
for (r in 1L:sum(R)) alists[[r]] <- list(data,i[r,],...)
- reslist = swiftapplyb(statistic,alists,callsperbatch=25)
+ reslist = swiftapply(statistic,alists,callsperbatch=25)
for (r in 1L:sum(R)) t.star[r, ] <- reslist[[r]]
}
}
More information about the Swift-commit
mailing list