[Swift-commit] r7215 - in SwiftTutorials/OSG-Swift: app doc part02

davidk at ci.uchicago.edu davidk at ci.uchicago.edu
Tue Oct 22 15:46:30 CDT 2013


Author: davidk
Date: 2013-10-22 15:46:30 -0500 (Tue, 22 Oct 2013)
New Revision: 7215

Added:
   SwiftTutorials/OSG-Swift/app/simulate.py
   SwiftTutorials/OSG-Swift/app/stats.py
Modified:
   SwiftTutorials/OSG-Swift/doc/README
   SwiftTutorials/OSG-Swift/doc/build_docs.sh
   SwiftTutorials/OSG-Swift/part02/apps
Log:
Python scripts for osgconnect tutorial
Updated build_docs
Updated README


Added: SwiftTutorials/OSG-Swift/app/simulate.py
===================================================================
--- SwiftTutorials/OSG-Swift/app/simulate.py	                        (rev 0)
+++ SwiftTutorials/OSG-Swift/app/simulate.py	2013-10-22 20:46:30 UTC (rev 7215)
@@ -0,0 +1,125 @@
+#!/usr/bin/env python
+import sys
+import os
+import socket
+import time
+import math
+import random
+import getpass
+
+def parse():
+    from optparse import OptionParser
+    parser=OptionParser()
+    parser.add_option("-b", "--bias", type="int", dest="bias", default=0,
+                      help="offset bias: add this integer to all results");
+
+    parser.add_option("-B", "--biasfile", type="string", dest="biasfile",
+                      default="none", help="file of integer biases to add to results" );
+
+    parser.add_option("-l", "--log", type="string", dest="log", default="yes",
+                      help="generate a log in stderr if not nul");
+
+    parser.add_option("-n", "--nvalues", type="int", dest="nvalues",default=1,
+                      help="print this many values per simulation" );
+
+    parser.add_option("-s", "--seed", type="int", dest="initseed", default=0,
+                      help="use this integer [0..32767] as a seed");
+
+    parser.add_option("-S", "--seedfile", type="string", dest="seedfile",
+                      default="none", help="use this file (containing integer seeds [0..32767]) one per line" );
+
+    parser.add_option("-t", "--timesteps", type="int", dest="timesteps",
+                      default=0, help='number of simulated "timesteps" in seconds (determines runtime)' );
+
+    parser.add_option("-r", "--range", type="int", dest="range", default=100,
+                      help="range (limit) of generated results" );
+
+    parser.add_option("-w", "--width", type="int", dest="width", default=8,
+                      help="Width ?" );
+
+    parser.add_option("-x", "--scale", type="int", dest="scale", default=1,
+                      help="scale the results by this integer" );
+    # Not implemented yet
+    parser.add_option("-p", "--paramfile", type="string", dest="paramfile", default="none",
+                      help="Not implemented yet" );
+    return (parser.parse_args());
+
+def log():
+    import datetime
+    print >> sys.stderr, "Called as: ", str(sys.argv)
+    print >> sys.stderr, "Start time: ", datetime.datetime.now()
+    print >> sys.stderr, "Running on node: ", socket.gethostname()
+    print >> sys.stderr, "Running as user: ", getpass.getuser()
+    print >> sys.stderr, "\nEnvironment:\n\n"
+    print >> sys.stderr, os.environ
+
+def printparams(options):
+    print 'bias =',options.bias
+    print 'biasfile = ',options.biasfile
+    print 'log = ', options.log
+    print 'nvalues = ',options.nvalues
+    print 'seed = ', options.initseed
+    print 'seedfile = ', options.seedfile
+    print 'timesteps = ', options.timesteps
+    print 'range = ', options.range
+    print 'width = ', options.width
+    print 'scale = ', options.scale
+    print 'paramfile = ', options.paramfile
+
+def simulate(options):
+    time.sleep(options.timesteps)
+    bias=[];
+    if (options.biasfile != "none"):
+        try:
+            with open(options.biasfile) as biasfile:
+                lines = biasfile.read().splitlines()
+                for line in lines:
+                    bias.append(int(line))
+        except IOError:
+            print "Error accessing content from file: ", options.biasfile 
+    bias_count = len(bias)
+
+    for i in range(options.nvalues):
+        value = (random.random() +
+        random.random()*math.pow(2,16) +
+        random.random()*math.pow(2,32) +
+        random.random()*math.pow(2,48))
+        value=( (int(value)%options.range) * options.scale + options.bias)
+        if ( i < bias_count ):
+            value = value + bias[i]
+        elif ( bias_count > 0 ):
+            value = value + bias[bias_count-1]
+
+        print '{num:{fill}{width}}'.format(num=value, fill=' ', width=options.width)
+
+
+def seed(options):
+    if (options.initseed != 0 ):
+        random.seed(options.initseed)
+    if (options.seedfile != "none"):
+        try:
+            with open(options.seedfile) as seedfile:
+                lines=seedfile.read().splitlines()
+                seed = 0
+                for line in lines:
+                    seed = seed + int(line)
+            random.seed(seed)
+        except IOError:
+            print "Could not open file: ", options.seedfile
+
+
+if __name__ == "__main__":
+    (options, args) = parse()
+    printparams(options)
+    seed(options)
+    simulate(options)
+    log()
+
+
+
+
+
+
+
+
+


Property changes on: SwiftTutorials/OSG-Swift/app/simulate.py
___________________________________________________________________
Added: svn:executable
   + *

Added: SwiftTutorials/OSG-Swift/app/stats.py
===================================================================
--- SwiftTutorials/OSG-Swift/app/stats.py	                        (rev 0)
+++ SwiftTutorials/OSG-Swift/app/stats.py	2013-10-22 20:46:30 UTC (rev 7215)
@@ -0,0 +1,31 @@
+#!/usr/bin/env python
+import socket
+import sys
+import os
+
+def log():
+    import datetime
+    print >> sys.stderr, "Called as: ", str(sys.argv)
+    print >> sys.stderr, "Start time: ", datetime.datetime.now()
+    print >> sys.stderr, "Running on node: ", socket.gethostname()
+    print >> sys.stderr, "Running as user: ",os.getlogin()
+    print >> sys.stderr, "\nEnvironment:\n\n"
+    print >> sys.stderr, os.environ
+
+def stat():
+    total = 0
+    count = 0
+    for f in sys.argv[1:]:
+        try:
+            with open(f) as ifile:
+                lines = ifile.read().splitlines()
+                for line in lines:
+                    total += int(line)
+                    count += 1
+        except IOError:
+            print "Error accessing content from file: ", options.biasfile
+        print total/count
+
+if __name__ == "__main__":
+    log()
+    stat()


Property changes on: SwiftTutorials/OSG-Swift/app/stats.py
___________________________________________________________________
Added: svn:executable
   + *

Modified: SwiftTutorials/OSG-Swift/doc/README
===================================================================
--- SwiftTutorials/OSG-Swift/doc/README	2013-10-22 20:29:02 UTC (rev 7214)
+++ SwiftTutorials/OSG-Swift/doc/README	2013-10-22 20:46:30 UTC (rev 7215)
@@ -324,6 +324,16 @@
 
 image::part02.png[align="center"]
 
+In part 2, we also update the apps file. Instead of using shell script (simulate.sh), we use  
+the equivalent python version (simulate.py). The new apps file now looks like this:
+
+-----
+sys::[cat ../part02/apps]
+-----
+
+Swift does not need to know anything about the language an application is written in. The application 
+can be written in Perl, Python, Java, Fortran, or any other language.
+
 .p2.swift
 -----
 sys::[cat -n ../part02/p2.swift]

Modified: SwiftTutorials/OSG-Swift/doc/build_docs.sh
===================================================================
--- SwiftTutorials/OSG-Swift/doc/build_docs.sh	2013-10-22 20:29:02 UTC (rev 7214)
+++ SwiftTutorials/OSG-Swift/doc/build_docs.sh	2013-10-22 20:46:30 UTC (rev 7215)
@@ -1,13 +1,4 @@
 #!/bin/bash -e
 
-if false; then
-  echo skipping
-pushd part11-swift-py-r/code >& /dev/null
-# Strip comments, blank lines; prepend shell prompt ($)
-grep -A 20 stc run-dets.sh | \
-  grep -v -e "^$\|#" | \
-  sed 's/^/$ /' > run-dets.sh.txt
-popd >& /dev/null
-fi
+asciidoc -a icons -a toc -a toplevels=2 -a stylesheet=$PWD/asciidoc.css -a max-width=800px -o tutorial.html README
 
-asciidoc -a icons -a "src_tab=3 --line-number=' '" -a toc -a toplevels=2 -a stylesheet=$PWD/asciidoc.css -a max-width=800px -o cic-tutorial.html README

Modified: SwiftTutorials/OSG-Swift/part02/apps
===================================================================
--- SwiftTutorials/OSG-Swift/part02/apps	2013-10-22 20:29:02 UTC (rev 7214)
+++ SwiftTutorials/OSG-Swift/part02/apps	2013-10-22 20:46:30 UTC (rev 7215)
@@ -1 +1 @@
-localhost simulate simulate.sh
+localhost simulate simulate.py




More information about the Swift-commit mailing list