[Swift-commit] r3609 - in SwiftApps/SwiftR/Swift: R exec tests

noreply at svn.ci.uchicago.edu noreply at svn.ci.uchicago.edu
Tue Sep 7 14:36:39 CDT 2010


Author: wilde
Date: 2010-09-07 14:36:39 -0500 (Tue, 07 Sep 2010)
New Revision: 3609

Modified:
   SwiftApps/SwiftR/Swift/R/Swift.R
   SwiftApps/SwiftR/Swift/exec/RunSwiftScript.sh
   SwiftApps/SwiftR/Swift/exec/swiftapply.swift
   SwiftApps/SwiftR/Swift/tests/TestSwift.R
Log:
Added initialize= string option to execute initialization statements in the remote R service. WIth this change we pass the RunR.R script as a Swift aergument and include the initialization statements in that script.

Modified: SwiftApps/SwiftR/Swift/R/Swift.R
===================================================================
--- SwiftApps/SwiftR/Swift/R/Swift.R	2010-09-07 17:22:04 UTC (rev 3608)
+++ SwiftApps/SwiftR/Swift/R/Swift.R	2010-09-07 19:36:39 UTC (rev 3609)
@@ -2,12 +2,14 @@
 {
   # Set Swift default options if not passed as keyword paramets or pre-set by user
 
+if(FALSE){
   if (is.null(getOption("swift.callsperbatch")))
     options(swift.callsperbatch=1)
   if (is.null(getOption("swift.manualmode")))
     options(swift.manualmode = FALSE)
   if (is.null(getOption("swift.initialize")))
     options(swift.initialize = "")
+} # FALSE
 
   if(is.null(site))
     site <- getOption("swift.site")
@@ -25,8 +27,9 @@
     manualmode <- FALSE
 
   if(is.null(initialize))
-    initialExpr <- getOption("swift.initialize")
-  # else leave NULL
+    initialize <- getOption("swift.initialize")
+  if(is.null(initialize))
+    initialize <- "";
 
   cat("\nSwift properties:\n")
   cat("  site =",site,"\n");
@@ -39,9 +42,8 @@
 
   rundir <- system("mktemp -d SwiftR.run.XXX",intern=TRUE)
   cat("Swift running in",rundir,"\n")
-  if(! is.null(initialize) ) {
-    cat(initialize,file=paste(rundir,"/initialize.R",sep=""))
-  }
+  cat(initialize,file=paste(rundir,"/initialize.R",sep=""))
+
   narglists <- length(arglists) # number of arglists to process
   batch <- 1   # Next arglist batch number to fill
   arglist <- 1 # Next arglist number to insert
@@ -64,7 +66,8 @@
   }
   nbatches <- batch - 1
   RunSwiftScript <- system.file(package="Swift","exec/RunSwiftScript.sh")
-  RunRScript <- system.file(package="Swift","exec/RunR.sh")
+#  RunRScript <- system.file(package="Swift","exec/RunR.sh")
+#  RunRScript <- system.file(package="Swift","exec/RunR.R")
   swiftapplyScript <- system.file(package="Swift","exec/swiftapply.swift")
 
   if( manualmode ) { # Prompt for return (empty line) to continue; assumes user ran a manual R to process the call.
@@ -72,13 +75,14 @@
     cat("  swift script: ", RunSwiftScript, "\n")
     cat("  site: ", site,"\n")
     cat("  swiftapplyScript: ", swiftapplyScript,"\n")
-    cat("  RunRScript: ", RunRScript,"\n\n")
+#    cat("  RunRScript: ", RunRScript,"\n\n")
     cat("  Use RunAllR.sh to process and press return when complete:")
     system(paste("cp ", system.file(package="Swift","exec/RunAllR.sh"), rundir))
     readLines(n=1)
   }
   else {
-    system(paste(RunSwiftScript,rundir,site,swiftapplyScript,RunRScript))
+    system(paste(RunSwiftScript,rundir,site,swiftapplyScript))
+#    system(paste(RunSwiftScript,rundir,site,swiftapplyScript,RunRScript))
 #    system(paste(RunSwiftScript,rundir,site,swiftapplyScript,RunRScript,sep=" "))
   }
 

Modified: SwiftApps/SwiftR/Swift/exec/RunSwiftScript.sh
===================================================================
--- SwiftApps/SwiftR/Swift/exec/RunSwiftScript.sh	2010-09-07 17:22:04 UTC (rev 3608)
+++ SwiftApps/SwiftR/Swift/exec/RunSwiftScript.sh	2010-09-07 19:36:39 UTC (rev 3609)
@@ -1,9 +1,9 @@
 rundir=$1
 site=$2
 script=$3
-runR=$4
+# runR=$4
 
-cp $script $rundir
+cp $script $runR $rundir
 
 # FIXME: rework this script to transfer all shells and rscripts
 # needed, and to copy in the R prelude for the R server processes (to
@@ -15,11 +15,12 @@
 # use /bin/sh and count on users PATH?
 # then add ENV::PATH as an option, e.g., from options(swift.remotepath and swift.remotepath.sitename)
 
-cat >tc <<EOF
-$site	RunR	$runR	null	null	ENV::R_TESTS="";ENV::PATH="$PATH"
-EOF
+cat >tc <<END
+$site	Rscript	Rscript	null	null	ENV::R_TESTS="";ENV::PATH="$PATH"
+# $site	RunR	$runR	null	null	ENV::R_TESTS="";ENV::PATH="$PATH"
+END
 
-cat >sites.xml <<EOF
+cat >sites.xml <<END
 <config>
   <pool handle="local">
     <execution provider="local" url="none" />
@@ -39,7 +40,27 @@
     <workdirectory>$(pwd)</workdirectory>
   </pool>
 </config>
-EOF
+END
 
+cat >RunR.R <<END  # Note: \$ escapes in "here document" below 
+
+# User initialization statements (if specified):
+$(cat initialize.R 2>/dev/null)
+# End of user initialization statements
+
+argv = commandArgs(TRUE)
+
+load(argv[1]);
+
+result=list()
+for(c in 1:length(rcall\$arglistbatch)) {
+    # FIXME: run this under try/catch and save error status in results object (need to make it a list: rval + error status)
+    result[[c]] = do.call( rcall\$func, rcall\$arglistbatch[[c]] )
+}
+
+save(result,file=argv[2])
+
+END
+
 script=$(basename $script)
 swift -tc.file tc -sites.file sites.xml $script

Modified: SwiftApps/SwiftR/Swift/exec/swiftapply.swift
===================================================================
--- SwiftApps/SwiftR/Swift/exec/swiftapply.swift	2010-09-07 17:22:04 UTC (rev 3608)
+++ SwiftApps/SwiftR/Swift/exec/swiftapply.swift	2010-09-07 19:36:39 UTC (rev 3609)
@@ -1,16 +1,19 @@
 type file;
-type RFile;
+type RData;
+type RScript;
 
-app (RFile result, file stout, file sterr) RunR (RFile rcall)
+app (RData result, file stout, file sterr) RunR (RScript rscript, RData rcall)
 {
-  RunR @rcall @result stdout=@stout stderr=@sterr;
+  Rscript @rscript @rcall @result stdout=@stout stderr=@sterr;
+#  RunR @rcall @result stdout=@stout stderr=@sterr;
 }
 
-RFile rcalls[]  <simple_mapper; prefix="cbatch.", suffix=".Rdata", padding=0>;
-RFile results[] <simple_mapper; prefix="rbatch.", suffix=".Rdata", padding=0>;
+RData rcalls[]  <simple_mapper; prefix="cbatch.", suffix=".Rdata", padding=0>;
+RData results[] <simple_mapper; prefix="rbatch.", suffix=".Rdata", padding=0>;
 file  stout[]   <simple_mapper; prefix="stdout.", suffix=".txt", padding=0>;
 file  sterr[]   <simple_mapper; prefix="stderr.", suffix=".txt", padding=0>;
+RScript rs      <"RunR.R">;
 
 foreach c, i in rcalls {
-  (results[i],stout[i], sterr[i]) = RunR(c);
+  (results[i],stout[i], sterr[i]) = RunR(rs,c);
 }

Modified: SwiftApps/SwiftR/Swift/tests/TestSwift.R
===================================================================
--- SwiftApps/SwiftR/Swift/tests/TestSwift.R	2010-09-07 17:22:04 UTC (rev 3608)
+++ SwiftApps/SwiftR/Swift/tests/TestSwift.R	2010-09-07 19:36:39 UTC (rev 3609)
@@ -276,9 +276,37 @@
   failures=failures+1
 }
 
+##### Test Group 4 # test initializer string
 
+cat("\n*** Starting test group 4 - test remote R service initialization string ***\n")
 
+sumivars <- function() { initVar1+initVar2 }
 
+initcmds <- "
+initVar1 <- 19
+initVar2 <- sqrt(400)+3
+"
+
+options(swift.initialize=initcmds)
+
+args=list()
+arglist = rep(list(args),1)
+
+localres = 42
+
+cat("\nTest of swiftapply(sumivars,arglist)\n")
+swiftres = swiftapply(sumivars,arglist)
+cat("Swift result:\n")
+print(swiftres)
+
+if(identical(localres,swiftres[[1]])) {
+  cat("\n==> test 4.1 passed\n")
+} else {
+  cat("\n==> test 4.1 FAILED !!!!!\n")
+}
+
+
+
 if(FALSE) { # Test various batch sizes
 
     cat("\nTest of swiftapply(sumcrits,arglist,callsperbatch=10)\n")




More information about the Swift-commit mailing list