[Swift-commit] r7871 - in SwiftTutorials/swift-cloud-tutorial: . part07

wilde at ci.uchicago.edu wilde at ci.uchicago.edu
Thu May 15 14:19:58 CDT 2014


Author: wilde
Date: 2014-05-15 14:19:57 -0500 (Thu, 15 May 2014)
New Revision: 7871

Added:
   SwiftTutorials/swift-cloud-tutorial/part07/
   SwiftTutorials/swift-cloud-tutorial/part07/apps
   SwiftTutorials/swift-cloud-tutorial/part07/p7.swift
   SwiftTutorials/swift-cloud-tutorial/part07/simulate.sh
   SwiftTutorials/swift-cloud-tutorial/part07/sites.xml
   SwiftTutorials/swift-cloud-tutorial/part07/stats.sh
Modified:
   SwiftTutorials/swift-cloud-tutorial/setup.sh
Log:
initial part07: genetic algorithm framework example.

Added: SwiftTutorials/swift-cloud-tutorial/part07/apps
===================================================================
--- SwiftTutorials/swift-cloud-tutorial/part07/apps	                        (rev 0)
+++ SwiftTutorials/swift-cloud-tutorial/part07/apps	2014-05-15 19:19:57 UTC (rev 7871)
@@ -0,0 +1 @@
+localhost sh /bin/bash

Added: SwiftTutorials/swift-cloud-tutorial/part07/p7.swift
===================================================================
--- SwiftTutorials/swift-cloud-tutorial/part07/p7.swift	                        (rev 0)
+++ SwiftTutorials/swift-cloud-tutorial/part07/p7.swift	2014-05-15 19:19:57 UTC (rev 7871)
@@ -0,0 +1,72 @@
+type file;
+
+# app() functions for application programs to be called:
+
+app (file out) genseed (int nseeds, file seed_script)
+{
+  sh "simulate.sh" "-r" 2000000 "-n" nseeds stdout=@out;
+}
+
+app (file out) genbias (int bias_range, int nvalues, file bias_script)
+{
+  sh "simulate.sh" "-r" bias_range "-n" nvalues stdout=@out;
+}
+
+app (file out, file log) simulation (int timesteps, int sim_range,
+                                     file bias_file, int scale, int sim_count, 
+                                     file sim_script, file seed_file)
+{
+  sh "simulate.sh" "-t" timesteps "-r" sim_range "-B" @bias_file "-x" scale
+           "-n" sim_count "-S" @seed_file stdout=@out stderr=@log;
+}
+
+app (file out, file log) analyze (file s[], file stat_script)
+{
+  sh "stats.sh" @filenames(s) stdout=@out stderr=@log;
+}
+
+(file simout, file simlog) simulate (int biasrange, int biascount, int timesteps, int sim_range,
+                                     int scale, int sim_count, file sim_script, file seed_file)
+{
+  file biasfile = genbias(biasrange, biascount, sim_script);
+  (simout,simlog) = simulation(timesteps, sim_range, biasfile, 1000000, sim_count, sim_script, seed_file);
+}
+
+generation(file seedfile)
+{
+  # Command line arguments
+  
+  int  nsim  = @toInt(@arg("nsim",   "10"));  # number of simulation programs to run
+  int  steps = @toInt(@arg("steps",  "1"));   # number of timesteps (seconds) per simulation
+  int  range = @toInt(@arg("range",  "100")); # range of the generated random numbers
+  int  values = @toInt(@arg("values", "10"));  # number of values generated per simulation
+  
+  # Main script and data
+  
+  file stats_script <"stats.sh">;
+  
+  tracef("\n*** Script parameters: nsim=%i range=%i num values=%i\n\n", nsim, range, values);
+  
+  file sims[];                      # Array of files to hold each simulation output
+  
+  foreach i in [0:nsim-1] {
+  # file biasfile <single_file_mapper; file=@strcat("output/bias_",i,".dat")>;
+    file simout   <single_file_mapper; file=@strcat("output/sim_",i,".out")>;
+    file simlog   <single_file_mapper; file=@strcat("output/sim_",i,".log")>;
+    (simout,simlog) = simulate(1000, 20, steps, range, 1000000, values, simulate_script, seedfile);
+    sims[i] = simout;
+  }
+  
+  file stats_out<"output/average.out">;
+  file stats_log<"output/average.log">;
+  (stats_out,stats_log) = analyze(sims, stats_script);
+}
+
+file seedfile <"output/seed.dat">;        # Dynamically generated bias for simulation ensemble
+
+global file simulate_script <"simulate.sh">;
+
+seedfile = genseed(1,simulate_script);
+
+
+generation(seedfile);

Added: SwiftTutorials/swift-cloud-tutorial/part07/simulate.sh
===================================================================
--- SwiftTutorials/swift-cloud-tutorial/part07/simulate.sh	                        (rev 0)
+++ SwiftTutorials/swift-cloud-tutorial/part07/simulate.sh	2014-05-15 19:19:57 UTC (rev 7871)
@@ -0,0 +1,135 @@
+#! /bin/bash
+
+printparams()
+{
+  printf "\nSimulation parameters:\n\n"
+  echo bias=$bias
+  echo biasfile=$biasfile
+  echo initseed=$initseed
+  echo log=$log
+  echo paramfile=$paramfile
+  echo range=$range
+  echo scale=$scale
+  echo seedfile=$seedfile
+  echo timesteps=$timesteps
+  echo output width=$width
+}
+
+log() {
+  printf "\nCalled as: $0: $cmdargs\n\n"
+  printf "Start time: "; /bin/date
+  printf "Running as user: "; /usr/bin/id
+  printf "Running on node: "; /bin/hostname
+  printf "Node IP address: "; /bin/hostname -I
+  printparams
+  printf "\nEnvironment:\n\n"
+  printenv | sort
+}
+
+addsims() {
+  while read f1 ; do
+    read -u 3 f2 
+    if [ _$f1 = _ ]; then f1=$lastf1; fi
+    if [ _$f2 = _ ]; then f2=$lastf2; fi
+    printf "%${width}d\n" $(($f1+$f2)) 
+    lastf1=$f1
+    lastf2=$f2
+  done <$1 3<$2
+}
+
+# set defaults
+
+bias=0
+biasfile=none
+initseed=none
+log=yes
+paramfile=none
+range=100
+scale=1
+seedfile=none
+timesteps=0
+nvalues=1
+width=8
+cmdargs="$*"
+
+usage()
+{
+  echo $0: usage:
+  cat <<END
+    -b|--bias       offset bias: add this integer to all results
+    -B|--biasfile   file of integer biases to add to results
+    -l|--log        generate a log in stderr if not null
+    -n|--nvalues    print this many values per simulation            
+    -r|--range      range (limit) of generated results
+    -s|--seed       use this integer [0..32767] as a seed
+    -S|--seedfile   use this file (containing integer seeds [0..32767]) one per line
+    -t|--timesteps  number of simulated "timesteps" in seconds (determines runtime)
+    -x|--scale      scale the results by this integer
+    -h|-?|?|--help  print this help
+END
+}
+
+# FIXME: NOT YET IMPLEMENTED:
+#    -p|--paramfile  take these parameters (in form param=value) from this file 
+#    -p|--paramfile) paramfile=$2 ;;
+
+while [ $# -gt 0 ]; do
+  case $1 in
+    -b|--bias)      bias=$2      ;;
+    -B|--biasfile)  biasfile=$2  ;;
+    -l|--log)       log=$2       ;;
+    -n|--nvalues)   nvalues=$2   ;;       
+    -s|--seed)      initseed=$2  ;;
+    -S|--seedfile)  seedfile=$2  ;;
+    -t|--timesteps) timesteps=$2 ;;
+    -r|--range)     range=$2     ;;   
+    -w|--width)     width=$2     ;;
+    -x|--scale)     scale=$2     ;;
+    -h|-?|--help|*) usage; exit  ;;
+  esac
+  shift 2
+done
+    
+# process initial seed
+
+if [ $initseed != none ]; then
+  RANDOM=$initseed
+fi
+
+# process file of seeds
+
+if [ $seedfile != none ]; then
+  seed=0
+  while read $seedfile s; do
+    seed=$(($seed+$s))
+  done <$seedfile
+  RANDOM=$seed
+fi
+
+# run for some number of "timesteps"
+
+sleep $timesteps
+
+# emit N (nvalues) "simulation results" scaled and biased by argument values
+
+simout=$(mktemp simout.XXXX)
+for ((i=0;i<nvalues;i++)); do
+  # value=$(( (($RANDOM)*(2**16))+$RANDOM ))
+  value=$(( (($RANDOM)*(2**48)) + (($RANDOM)*(2**32)) + (($RANDOM)*(2**16)) + $RANDOM ))
+  printf "%${width}d\n" $(( ($value%range)*scale+bias))
+done  >$simout
+
+# process file of biases
+
+if [ $biasfile != none ]; then
+  addsims $simout $biasfile
+else
+  cat $simout
+fi
+rm $simout
+
+# log environmental data
+
+if [ $log != off ]; then
+  log 1>&2
+fi


Property changes on: SwiftTutorials/swift-cloud-tutorial/part07/simulate.sh
___________________________________________________________________
Added: svn:executable
   + *

Added: SwiftTutorials/swift-cloud-tutorial/part07/sites.xml
===================================================================
--- SwiftTutorials/swift-cloud-tutorial/part07/sites.xml	                        (rev 0)
+++ SwiftTutorials/swift-cloud-tutorial/part07/sites.xml	2014-05-15 19:19:57 UTC (rev 7871)
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<config xmlns="http://www.ci.uchicago.edu/swift/SwiftSites">
+   <pool handle="localhost">
+      <execution provider="local" />
+      <profile namespace="karajan" key="jobThrottle">.10</profile>
+      <profile namespace="karajan" key="initialScore">10000</profile>
+      <filesystem provider="local"/>
+      <workdirectory>.swift/tmp</workdirectory>
+      <profile namespace="swift" key="stagingMethod">local</profile>
+   </pool>
+</config>

Added: SwiftTutorials/swift-cloud-tutorial/part07/stats.sh
===================================================================
--- SwiftTutorials/swift-cloud-tutorial/part07/stats.sh	                        (rev 0)
+++ SwiftTutorials/swift-cloud-tutorial/part07/stats.sh	2014-05-15 19:19:57 UTC (rev 7871)
@@ -0,0 +1,19 @@
+#! /bin/sh
+
+log() {
+  printf "\nCalled as: $0: $cmdargs\n\n"
+  printf "Start time: "; /bin/date
+  printf "Running as user: "; /usr/bin/id
+  printf "Running on node: "; /bin/hostname
+  printf "Node IP address: "; /bin/hostname -I
+  printf "\nEnvironment:\n\n"
+  printenv | sort
+}
+
+awk '
+
+{ sum += $1}
+
+END { printf("%d\n",sum/NR) }
+' $*
+log 1>&2


Property changes on: SwiftTutorials/swift-cloud-tutorial/part07/stats.sh
___________________________________________________________________
Added: svn:executable
   + *

Modified: SwiftTutorials/swift-cloud-tutorial/setup.sh
===================================================================
--- SwiftTutorials/swift-cloud-tutorial/setup.sh	2014-05-13 16:29:19 UTC (rev 7870)
+++ SwiftTutorials/swift-cloud-tutorial/setup.sh	2014-05-15 19:19:57 UTC (rev 7871)
@@ -1,16 +1,13 @@
 # ensure that this script is being sourced
 
 if [[ $0 =~ .*bash ]] ; then 
-# Bash: 
   if [ ${BASH_VERSINFO[0]} -gt 2 -a "${BASH_SOURCE[0]}" = "${0}" ] ; then
     echo ERROR: script ${BASH_SOURCE[0]} must be executed as: source ${BASH_SOURCE[0]}
     exit 1
   fi
   # Lookup tutorial directory based on PATH entry for this script
   TUTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
-fi
-if [[ $ZSH_VERSION != "" ]] ; then 
-  # ZSH: 
+elif [[ $ZSH_VERSION != "" ]] ; then 
   if [[  ! $- =~ .*i.* ]] ; then 
     echo ERROR: script $0 must be executed as: source $0
     return 1
@@ -59,6 +56,8 @@
 
 END
 
+return # TEMP: for localhost execuiton on Mac
+
 # Start coaster-service and generate sites.xml
 cd scs
 start-coaster-service




More information about the Swift-commit mailing list