From davidk at ci.uchicago.edu Wed Apr 2 17:04:22 2014 From: davidk at ci.uchicago.edu (davidk at ci.uchicago.edu) Date: Wed, 2 Apr 2014 17:04:22 -0500 (CDT) Subject: [Swift-commit] r7753 - trunk/docs/userguide Message-ID: <20140402220422.C0A249D6FA@svn.ci.uchicago.edu> Author: davidk Date: 2014-04-02 17:04:22 -0500 (Wed, 02 Apr 2014) New Revision: 7753 Modified: trunk/docs/userguide/configuration Log: Fix formatting Modified: trunk/docs/userguide/configuration =================================================================== --- trunk/docs/userguide/configuration 2014-03-28 18:10:53 UTC (rev 7752) +++ trunk/docs/userguide/configuration 2014-04-02 22:04:22 UTC (rev 7753) @@ -318,9 +318,9 @@ |true, false |true |By default, Swift will generate a run directory that contains logs, scheduler submit scripts, -|debug directories, and other files associated with a particular Swift run. Setting this value -|to false disables the creation of run directories and causes all logs and directories to be -|created in the current working directory. +debug directories, and other files associated with a particular Swift run. Setting this value +to false disables the creation of run directories and causes all logs and directories to be +created in the current working directory. |execution.retries |Positive integer From yadunandb at ci.uchicago.edu Thu Apr 3 16:32:19 2014 From: yadunandb at ci.uchicago.edu (yadunandb at ci.uchicago.edu) Date: Thu, 3 Apr 2014 16:32:19 -0500 (CDT) Subject: [Swift-commit] r7754 - in trunk: libexec src/org/griphyn/vdl/engine src/org/griphyn/vdl/karajan/lib/swiftscript Message-ID: <20140403213219.3462E178884@svn.ci.uchicago.edu> Author: yadunandb Date: 2014-04-03 16:32:18 -0500 (Thu, 03 Apr 2014) New Revision: 7754 Modified: trunk/libexec/swift-lib.k trunk/src/org/griphyn/vdl/engine/ProcedureSignature.java trunk/src/org/griphyn/vdl/karajan/lib/swiftscript/Misc.java Log: Committing changes for system built-in command. Allows for easy specification of files to mappers using common unix commands. Tested with "ls" and "find -type f" Tests in next commit Modified: trunk/libexec/swift-lib.k =================================================================== --- trunk/libexec/swift-lib.k 2014-04-02 22:04:22 UTC (rev 7753) +++ trunk/libexec/swift-lib.k 2014-04-03 21:32:18 UTC (rev 7754) @@ -9,6 +9,7 @@ export(strcut, def("org.griphyn.vdl.karajan.lib.swiftscript.Misc$StrCut")) export(strstr, def("org.griphyn.vdl.karajan.lib.swiftscript.Misc$StrStr")) export(strsplit, def("org.griphyn.vdl.karajan.lib.swiftscript.Misc$StrSplit")) + export(system, def("org.griphyn.vdl.karajan.lib.swiftscript.Misc$ExecSystem")) export(strjoin, def("org.griphyn.vdl.karajan.lib.swiftscript.Misc$StrJoin")) export(regexp, def("org.griphyn.vdl.karajan.lib.swiftscript.Misc$Regexp")) export(toInt, def("org.griphyn.vdl.karajan.lib.swiftscript.Misc$ToInt")) @@ -21,7 +22,7 @@ export(trace, def("org.griphyn.vdl.karajan.lib.swiftscript.Misc$Trace")) export(tracef, def("org.griphyn.vdl.karajan.lib.swiftscript.Tracef")) export(fprintf, def("org.griphyn.vdl.karajan.lib.swiftscript.Fprintf")) - + /* included for backwards compatibility */ export(readdata, def("org.griphyn.vdl.karajan.lib.swiftscript.ReadData")) export(readdata2, def("org.griphyn.vdl.karajan.lib.swiftscript.ReadStructured")) Modified: trunk/src/org/griphyn/vdl/engine/ProcedureSignature.java =================================================================== --- trunk/src/org/griphyn/vdl/engine/ProcedureSignature.java 2014-04-02 22:04:22 UTC (rev 7753) +++ trunk/src/org/griphyn/vdl/engine/ProcedureSignature.java 2014-04-03 21:32:18 UTC (rev 7754) @@ -197,6 +197,7 @@ add(functionsMap, "strcut", returns(STRING), args(STRING, STRING)); add(functionsMap, "strstr", returns(INT), args(STRING, STRING)); add(functionsMap, "strsplit", returns(STRING_ARRAY), args(STRING, STRING)); + add(functionsMap, "system", returns(STRING_ARRAY), args(STRING)); add(functionsMap, "strjoin", returns(STRING), args(ANY, STRING)); add(functionsMap, "toInt", returns(INT), args(ANY)); add(functionsMap, "toFloat", returns(FLOAT), args(ANY)); Modified: trunk/src/org/griphyn/vdl/karajan/lib/swiftscript/Misc.java =================================================================== --- trunk/src/org/griphyn/vdl/karajan/lib/swiftscript/Misc.java 2014-04-02 22:04:22 UTC (rev 7753) +++ trunk/src/org/griphyn/vdl/karajan/lib/swiftscript/Misc.java 2014-04-03 21:32:18 UTC (rev 7754) @@ -18,6 +18,9 @@ package org.griphyn.vdl.karajan.lib.swiftscript; import java.io.IOException; +import java.io.InputStreamReader; +import java.io.BufferedReader; + import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -277,6 +280,51 @@ } } + public static class ExecSystem extends AbstractSingleValuedFunction { + private ArgRef input; + //private ArgRef pattern; + + @Override + protected Signature getSignature() { + return new Signature(params("input")); + } + + @Override + public Object function(Stack stack) { + AbstractDataNode hinput = this.input.getValue(stack); + String input = SwiftFunction.unwrap(this, hinput); + + DSHandle handle = new RootArrayDataNode(Types.STRING.arrayType()); + StringBuffer out = new StringBuffer(); + Process p; + int i = 0; + + try { + p = Runtime.getRuntime().exec(input); + p.waitFor(); + BufferedReader reader = new BufferedReader( new InputStreamReader(p.getInputStream())); + String line = ""; + while ( (line = reader.readLine()) != null ) { + DSHandle el; + el = handle.getField(i++); + el.setValue(line); + //out.append(line + "\n"); + } + + } catch (Exception e) { + e.printStackTrace(); + } + handle.closeDeep(); + + if (PROVENANCE_ENABLED) { + int provid = SwiftFunction.nextProvenanceID(); + SwiftFunction.logProvenanceResult(provid, handle, "system"); + SwiftFunction.logProvenanceParameter(provid, hinput, "input"); + } + return handle; + } + } + public static class StrSplit extends AbstractSingleValuedFunction { private ArgRef input; private ArgRef pattern; @@ -601,7 +649,7 @@ return handle; } } - + public static class Length extends AbstractSingleValuedFunction { private ArgRef array; From davidk at ci.uchicago.edu Thu Apr 3 23:11:45 2014 From: davidk at ci.uchicago.edu (davidk at ci.uchicago.edu) Date: Thu, 3 Apr 2014 23:11:45 -0500 (CDT) Subject: [Swift-commit] r7755 - in trunk: bin docs/userguide Message-ID: <20140404041145.C62FA178884@svn.ci.uchicago.edu> Author: davidk Date: 2014-04-03 23:11:45 -0500 (Thu, 03 Apr 2014) New Revision: 7755 Modified: trunk/bin/swiftrun trunk/docs/userguide/configuration Log: Add pe to config option Modified: trunk/bin/swiftrun =================================================================== --- trunk/bin/swiftrun 2014-04-03 21:32:18 UTC (rev 7754) +++ trunk/bin/swiftrun 2014-04-04 04:11:45 UTC (rev 7755) @@ -47,6 +47,7 @@ 'maxnodesperjob' => 'globus.maxNodes', 'maxsubmitrate' => 'karajan.maxSubmitRate', 'overallocationdecayfactor' => 'globus.overallocationDecayFactor', + 'pe' => 'globus.pe', 'providerattributes' => 'globus.providerAttributes', 'remotemonitorenabled' => 'globus.remoteMonitorEnabled', 'slurm' => 'globus.slurm', Modified: trunk/docs/userguide/configuration =================================================================== --- trunk/docs/userguide/configuration 2014-04-03 21:32:18 UTC (rev 7754) +++ trunk/docs/userguide/configuration 2014-04-04 04:11:45 UTC (rev 7755) @@ -212,15 +212,20 @@ The maximum number of nodes to request per scheduler job. |site.westmere.maxNodesPerJob=2 +|pe +|The parallel environment to use for SGE schedulers +|site.sunhpc.pe=mpi + |providerAttributes| Allows user to pass attributes through directly to scheduler submit script. Currently only implemented for sites that use PBS. |site.beagle.providerAttributes=pbs.aprun;pbs.mpp;depth=24 -|slurm| -Pass parameters directly through to the submit script generated for the slurm +|slurm +|Pass parameters directly through to the submit script generated for the slurm scheduler. For example, the setting "site.midway.slurm.mail-user=username" generates the line "#SBATCH --mail-user=username". +|site.midway.slurm.mail-user=username |taskDir| Tasks will be run from this directory. In the absence of a taskDir definition, From davidk at ci.uchicago.edu Thu Apr 3 23:13:18 2014 From: davidk at ci.uchicago.edu (davidk at ci.uchicago.edu) Date: Thu, 3 Apr 2014 23:13:18 -0500 (CDT) Subject: [Swift-commit] r7756 - branches/release-0.95/bin Message-ID: <20140404041318.46322178884@svn.ci.uchicago.edu> Author: davidk Date: 2014-04-03 23:13:18 -0500 (Thu, 03 Apr 2014) New Revision: 7756 Modified: branches/release-0.95/bin/swiftrun Log: pe config option Modified: branches/release-0.95/bin/swiftrun =================================================================== --- branches/release-0.95/bin/swiftrun 2014-04-04 04:11:45 UTC (rev 7755) +++ branches/release-0.95/bin/swiftrun 2014-04-04 04:13:18 UTC (rev 7756) @@ -47,6 +47,7 @@ 'maxnodesperjob' => 'globus.maxNodes', 'maxsubmitrate' => 'karajan.maxSubmitRate', 'overallocationdecayfactor' => 'globus.overallocationDecayFactor', + 'pe' => 'globus.pe', 'providerattributes' => 'globus.providerAttributes', 'remotemonitorenabled' => 'globus.remoteMonitorEnabled', 'slurm' => 'globus.slurm', From davidk at ci.uchicago.edu Fri Apr 4 11:53:01 2014 From: davidk at ci.uchicago.edu (davidk at ci.uchicago.edu) Date: Fri, 4 Apr 2014 11:53:01 -0500 (CDT) Subject: [Swift-commit] r7757 - trunk/tests/functions Message-ID: <20140404165301.327CC9CFE8@svn.ci.uchicago.edu> Author: davidk Date: 2014-04-04 11:53:00 -0500 (Fri, 04 Apr 2014) New Revision: 7757 Added: trunk/tests/functions/system_commandnotfound.setup.sh trunk/tests/functions/system_commandnotfound.swift trunk/tests/functions/system_find_arraymapper.setup.sh trunk/tests/functions/system_find_arraymapper.swift trunk/tests/functions/system_nonzero.setup.sh trunk/tests/functions/system_nonzero.swift Log: Tests for system() Added: trunk/tests/functions/system_commandnotfound.setup.sh =================================================================== --- trunk/tests/functions/system_commandnotfound.setup.sh (rev 0) +++ trunk/tests/functions/system_commandnotfound.setup.sh 2014-04-04 16:53:00 UTC (rev 7757) @@ -0,0 +1 @@ +link system_find_arraymapper.setup.sh \ No newline at end of file Property changes on: trunk/tests/functions/system_commandnotfound.setup.sh ___________________________________________________________________ Added: svn:special + * Added: trunk/tests/functions/system_commandnotfound.swift =================================================================== --- trunk/tests/functions/system_commandnotfound.swift (rev 0) +++ trunk/tests/functions/system_commandnotfound.swift 2014-04-04 16:53:00 UTC (rev 7757) @@ -0,0 +1,8 @@ +type file; + +# *_THIS-SCRIPT-SHOULD-FAIL_* + +string results[] = system("fdjskflsdk"); +foreach r in results { + tracef("%s\n", r); +} Added: trunk/tests/functions/system_find_arraymapper.setup.sh =================================================================== --- trunk/tests/functions/system_find_arraymapper.setup.sh (rev 0) +++ trunk/tests/functions/system_find_arraymapper.setup.sh 2014-04-04 16:53:00 UTC (rev 7757) @@ -0,0 +1,10 @@ +#!/bin/bash + +data="fjkdlsfjlkdsjflka" +mkdir -p data/foo_a +mkdir -p data/foo_b +echo $data >> data/foo_a/foo_a.txt +echo $data >> data/foo_a/foo_b.txt +echo $data >> data/foo_b/bar_1 +echo $data >> data/foo_b/bar_2 +echo $data >> data/data.txt Property changes on: trunk/tests/functions/system_find_arraymapper.setup.sh ___________________________________________________________________ Added: svn:executable + * Added: trunk/tests/functions/system_find_arraymapper.swift =================================================================== --- trunk/tests/functions/system_find_arraymapper.swift (rev 0) +++ trunk/tests/functions/system_find_arraymapper.swift 2014-04-04 16:53:00 UTC (rev 7757) @@ -0,0 +1,13 @@ +type file; + +app check_files (file inputs[]) +{ + ls "data/foo_a/foo_a.txt" "data/foo_a/foo_b.txt" "data/foo_b/bar_1" "data/foo_b/bar_2" "data/data.txt"; +} + +file inputs[] ; +foreach i in inputs { + tracef("%s\n", filename(i)); +} + +check_files(inputs); Added: trunk/tests/functions/system_nonzero.setup.sh =================================================================== --- trunk/tests/functions/system_nonzero.setup.sh (rev 0) +++ trunk/tests/functions/system_nonzero.setup.sh 2014-04-04 16:53:00 UTC (rev 7757) @@ -0,0 +1 @@ +link system_find_arraymapper.setup.sh \ No newline at end of file Property changes on: trunk/tests/functions/system_nonzero.setup.sh ___________________________________________________________________ Added: svn:special + * Added: trunk/tests/functions/system_nonzero.swift =================================================================== --- trunk/tests/functions/system_nonzero.swift (rev 0) +++ trunk/tests/functions/system_nonzero.swift 2014-04-04 16:53:00 UTC (rev 7757) @@ -0,0 +1,8 @@ +type file; + +# *_THIS-SCRIPT-SHOULD-FAIL_* + +string results[] = system("false"); +foreach r in results { + tracef("%s\n", r); +} From yadunandb at ci.uchicago.edu Fri Apr 4 12:07:30 2014 From: yadunandb at ci.uchicago.edu (yadunandb at ci.uchicago.edu) Date: Fri, 4 Apr 2014 12:07:30 -0500 (CDT) Subject: [Swift-commit] r7758 - trunk/src/org/griphyn/vdl/karajan/lib/swiftscript Message-ID: <20140404170730.BD9F29CFE8@svn.ci.uchicago.edu> Author: yadunandb Date: 2014-04-04 12:07:30 -0500 (Fri, 04 Apr 2014) New Revision: 7758 Modified: trunk/src/org/griphyn/vdl/karajan/lib/swiftscript/Misc.java Log: Updates for reporting exitcodes and stderr to swift stdout from system builtin Modified: trunk/src/org/griphyn/vdl/karajan/lib/swiftscript/Misc.java =================================================================== --- trunk/src/org/griphyn/vdl/karajan/lib/swiftscript/Misc.java 2014-04-04 16:53:00 UTC (rev 7757) +++ trunk/src/org/griphyn/vdl/karajan/lib/swiftscript/Misc.java 2014-04-04 17:07:30 UTC (rev 7758) @@ -279,16 +279,16 @@ return result; } } - + public static class ExecSystem extends AbstractSingleValuedFunction { private ArgRef input; //private ArgRef pattern; - + @Override protected Signature getSignature() { return new Signature(params("input")); } - + @Override public Object function(Stack stack) { AbstractDataNode hinput = this.input.getValue(stack); @@ -296,26 +296,36 @@ DSHandle handle = new RootArrayDataNode(Types.STRING.arrayType()); StringBuffer out = new StringBuffer(); - Process p; + Process proc; int i = 0; - + try { - p = Runtime.getRuntime().exec(input); - p.waitFor(); - BufferedReader reader = new BufferedReader( new InputStreamReader(p.getInputStream())); + proc = Runtime.getRuntime().exec(input); + proc.waitFor(); + int exitcode = proc.exitValue(); + // If the shell returned a non-zero exit code, attempt to print stderr + if ( exitcode != 0 ) { + BufferedReader reader = new BufferedReader( new InputStreamReader(proc.getErrorStream()) ); + String line = ""; + StringBuffer stderr = new StringBuffer(); + while ( (line = reader.readLine()) != null ) { + stderr.append(line); + } + logger.warn("swift:system returned exitcode :" + exitcode); + logger.warn("swift:system stderr:\n " + stderr ); + } + BufferedReader reader = new BufferedReader( new InputStreamReader(proc.getInputStream()) ); String line = ""; - while ( (line = reader.readLine()) != null ) { - DSHandle el; - el = handle.getField(i++); - el.setValue(line); - //out.append(line + "\n"); - } - + while ( (line = reader.readLine()) != null ) { + DSHandle el; + el = handle.getField(i++); + el.setValue(line); + } } catch (Exception e) { e.printStackTrace(); } handle.closeDeep(); - + if (PROVENANCE_ENABLED) { int provid = SwiftFunction.nextProvenanceID(); SwiftFunction.logProvenanceResult(provid, handle, "system"); @@ -324,8 +334,8 @@ return handle; } } - - public static class StrSplit extends AbstractSingleValuedFunction { + + public static class StrSplit extends AbstractSingleValuedFunction { private ArgRef input; private ArgRef pattern; From yadunandb at ci.uchicago.edu Sat Apr 5 22:25:27 2014 From: yadunandb at ci.uchicago.edu (yadunandb at ci.uchicago.edu) Date: Sat, 5 Apr 2014 22:25:27 -0500 (CDT) Subject: [Swift-commit] r7759 - trunk/src/org/griphyn/vdl/karajan/lib/swiftscript Message-ID: <20140406032527.36DCA9D065@svn.ci.uchicago.edu> Author: yadunandb Date: 2014-04-05 22:25:26 -0500 (Sat, 05 Apr 2014) New Revision: 7759 Modified: trunk/src/org/griphyn/vdl/karajan/lib/swiftscript/Misc.java Log: Fixing minor bug which strings passed to system builtin did not expand wildcards correctly as they would in a shell. So, pipes are also working. Tested with the following strings: system("ls run*/*.log") system("ls *"); #this doesn't give us a reasonable format system("find *"); system("ls run???/*.???"); system("ls run???/*.??? | grep log"); system("find run* -type f"); Modified: trunk/src/org/griphyn/vdl/karajan/lib/swiftscript/Misc.java =================================================================== --- trunk/src/org/griphyn/vdl/karajan/lib/swiftscript/Misc.java 2014-04-04 17:07:30 UTC (rev 7758) +++ trunk/src/org/griphyn/vdl/karajan/lib/swiftscript/Misc.java 2014-04-06 03:25:26 UTC (rev 7759) @@ -300,7 +300,7 @@ int i = 0; try { - proc = Runtime.getRuntime().exec(input); + proc = Runtime.getRuntime().exec(new String[] {"bash", "-c", input}); proc.waitFor(); int exitcode = proc.exitValue(); // If the shell returned a non-zero exit code, attempt to print stderr From wilde at ci.uchicago.edu Sun Apr 6 16:28:59 2014 From: wilde at ci.uchicago.edu (wilde at ci.uchicago.edu) Date: Sun, 6 Apr 2014 16:28:59 -0500 (CDT) Subject: [Swift-commit] r7760 - SwiftApps Message-ID: <20140406212859.306179CFE8@svn.ci.uchicago.edu> Author: wilde Date: 2014-04-06 16:28:58 -0500 (Sun, 06 Apr 2014) New Revision: 7760 Added: SwiftApps/SimulatedAnnealing/ Log: New project: generalized example of simulated annealing in Swift. From wilde at ci.uchicago.edu Sun Apr 6 17:47:27 2014 From: wilde at ci.uchicago.edu (wilde at ci.uchicago.edu) Date: Sun, 6 Apr 2014 17:47:27 -0500 (CDT) Subject: [Swift-commit] r7761 - in SwiftApps/SimulatedAnnealing: . params Message-ID: <20140406224727.099A09CFE8@svn.ci.uchicago.edu> Author: wilde Date: 2014-04-06 17:47:26 -0500 (Sun, 06 Apr 2014) New Revision: 7761 Added: SwiftApps/SimulatedAnnealing/README SwiftApps/SimulatedAnnealing/annealing.swift SwiftApps/SimulatedAnnealing/colortext.swift SwiftApps/SimulatedAnnealing/math.swift SwiftApps/SimulatedAnnealing/params/ SwiftApps/SimulatedAnnealing/params/ARFull SwiftApps/SimulatedAnnealing/params/ARtest01 SwiftApps/SimulatedAnnealing/params/ARtest02 SwiftApps/SimulatedAnnealing/params/ARtest03 SwiftApps/SimulatedAnnealing/params/ARtest04 SwiftApps/SimulatedAnnealing/params/ARtest05 SwiftApps/SimulatedAnnealing/params/ARtest06 SwiftApps/SimulatedAnnealing/params/BetaTest SwiftApps/SimulatedAnnealing/params/Fast01 SwiftApps/SimulatedAnnealing/params/KMtest01 SwiftApps/SimulatedAnnealing/params/MWtest01 SwiftApps/SimulatedAnnealing/params/MWtest02 SwiftApps/SimulatedAnnealing/params/MWtest03 SwiftApps/SimulatedAnnealing/params/MWtest04 SwiftApps/SimulatedAnnealing/params/MWtest05 SwiftApps/SimulatedAnnealing/params/MWtest06 SwiftApps/SimulatedAnnealing/params/MWtest07 SwiftApps/SimulatedAnnealing/swiftopt.sh Log: Initial revision. Started recoding SciCol to generalize as an example annealing function. Added: SwiftApps/SimulatedAnnealing/README =================================================================== --- SwiftApps/SimulatedAnnealing/README (rev 0) +++ SwiftApps/SimulatedAnnealing/README 2014-04-06 22:47:26 UTC (rev 7761) @@ -0,0 +1,338 @@ + +*** Getting started + + +To run shorter tests on single local hosts (Mac, Linux, Beagle +Sandbox, Swift lab machines): + + cd $HOME + svn co https://svn.ci.uchicago.edu/svn/vdl2/SwiftApps/SciColSim + cd SciColSim + + ./setup.sh # just do this once. Will install Boost and Swift, and compile the optimizer + + ./swiftopt.sh -s local -p Fast01 & # Tells you what run dir its in. Note the "&" !!! + + cd runNNN # cd to that run dir eg run007 + tail -f swift.out # to view progress + tail -f best_some_opt_swift.txt # to view optimization results + + ./swiftopt.sh -s pads -p params/ARtest01 # Etc. + + +swiftopt.sh command line arguments: + + -s site to run on: can be local, pads, beagle + + -p param set to use, from param/ dir + + FIXME: specify the variants and how to speciy params. + + FIXME: Params for gensites can also be in the -p file I think. + + FIXME: create a few more tet variations + + +Contents of parameter file: + +#-------- params/Fast01 + +min_target_innovation 58 # starting target innovation value to try +max_target_innovation 109 # stops before this target innovation value +target_innovation_increment 50 # increment target innovation by this amount + +annealing_repeats 1 # times to repeate the entire optimization process for each target_innovation +annealing_cycles 10 # times to perform the simulated annealing loop for all non-fixed parameters + +evolve_reruns 8 # times to perform evolve_to_target_and_save() (objective function - is batched) +nworkers 1 # number of parallel threads (cores) to use per invocation of C++ optimizer +reruns_per_opt_invocation 2 # reruns_per_opt_invocation mod nworkers must == 0 !!! <=== NOTE WELL !!! + +alpha_i 0.0 # 5 evolve() parameters: must be decimal values !!! +alpha_m 0.0 # alpha_i and alpha_m are fixed for now +beta 4.0 # rest are varied by the optimization process +gamma 50.0 +delta -1.0 + +#------- + +You can add new param sets in the param dir (or anywhere): just copy an existing one and change the params. + +You can add new sites in the conf/ dir. FIXME: for now, add gen.SITENAME files. Limited flexibility w/ tc + + +*** QuickStart + +mkdir $HOME/SciColSim # scientific collaboration simulation application +cd SciColSim +svn co https://svn.ci.uchicago.edu/svn/vdl2/SwiftApps/SciColSim src +cd src +cp /home/wilde/AndreysOptimizer/src/ + +wget http://sourceforge.net/projects/boost/files/boost/1.47.0/boost_1_47_0.tar.gz/download +tar zxf boost_1_47_0.tar.gz + +make # should make openmp-optimizer executable + +./testopt.py >& testopt.out + +# Needs Swift 0.93 in PATH + +./test-swift.sh >& test-swift.out + +*** OSG + +To run on OSG, run the following commands; +voms-proxy-init -voms Engage -valid 72:00 +./start-osg +./swiftopt.sh -s grid -p Fast01 -w & + +This has only been tested with the Fast01 parameter set as of now. The "-w" +option sets file transfers to be handled by using wget. If you are using OSG +with another site, you can use the -l option of swiftopt to separate short and +long runs based on the value of target_innovation. For example, you can use +Ranger for short runs, and OSG for long runs. Adjust conf/grid.cf app +definitions for bash_short and bash_long according to your needs. + +*** Overview + +The code simulates the exploration of a chemical network by a research +community. The five major parameters determine the strategy of +exploration, "target" is the number of new interactions discovered and +"loss" is the number of experiments per one new positive finding. + +Terminology and application logic: + + optimizer: the C++ based optimizer that performs simulated annealing + optimizetion of parameters to the evolve() function. + + evolve(): the actual science code which does the "collaboration + simulation" desribed in Overview above. Implemented as a + function within optimizer. Uses the boost graph lib. + Calculates "loss" - amount of effort expended in rerunning + scientific experiments. + + multi_annealing(): the function within optimizer that does the + simulated annealing optimization logic (multiple times) + + multi_loss: performs a total of N independent repetitions of evolve() + on NWorker cores, in parallel. Each evolve() returns one loss + value, a scalar double. Returns average loss over all evolve() + simulations, and std dev. + +*** Files + +Code: + +testopt.py: top-most script to run the C++ optimizer (with no + swift). Based on a simpler Python script provided by + Andrey to run the C++ optimizer. + +test-orig.sh: original python script test script for optimizer, + provided by Andrey with some mods by Mike. + +optirun.swift: replaces top-level py script for the outermost loops + (temporarily deprecated: has not been maintained to match changes in optimizer) + +annealing.swift: the annealing logic of optimizer, moved to + swift. Calls optimizer(op=m) to run 1 multi_loss() of N + evolve() runs on NWorker cores. Implements a higher-level multi_loss + which spreads the N reruns of evolve() between M runs of optimizer(m) + each of which does R evolve runs. N = P*R. Eg, n=2400, P=100, R=24, + would use 100 nodes (invocations) of 24 cores each. + + +tc specifies: + + optimizer.sh (old) / evolve.sh (current) + + sumloss.sh: calculates avg loss and its std dev + did this as a separate app because it was hard to do the sum() + logic in swift. How best to do that? Try recursion? fold()? + + +Data: + + input: movie_data.txt + + output: best_??? max? itermiediate? FIX + + +*** How to build + +Copy and untar boost graph library to the current dir: +Needs: boost_1_47_0.tar.gz +Available for now from: CI: /home/wilde/AndreysOptimizer/src + +Should create dir "boost_1_47_0" in the current directory +(svn checkout dir, which is: + https://svn.ci.uchicago.edu/svn/vdl2/SwiftApps/SciColSim +) + +Then run "make" -> uses Makefile + + on mac, makes: openmp-optimizer (multi_loss() changed to use OpenMP), + dispatch-optimizer (orig code logic, only slight corrections) + + on linux, makes: openmp-optimizer + + +*** How to Run + +* Non-swift tests (py calling C++ optimizer app): + + cp testopt.py t1.py etc; then edit t1.py etc to set the params you want. + +An example of a modified parameter set for testing a fast optimization +loop on communicado/local.xml is: + +> paramset="mw" +71a73,86 +> elif paramset == "mw": # FAST TEST PARAMETERS by Mike +> +> startTarget = 58 +> endTarget = 59 +> incrTarget = 50 +> optimizerRepeats = 1 +> evolveReruns = 100 +> annealingSteps = 5 +> NWorkers = "4" +> openmp = "OMP_NUM_THREADS=" + NWorkers +> operation = "n" # n=normal, m=manual (runs 1 multi_loss call) +> seed = "1234567" +> app = "./openmp-optimizer"; +> + +Sample output is in sample.testopt.py.output + +* Swift tests: + + /test-swift.sh >&ts3.out & + +(currently, parameters are set in a few different places in annealing.swift) + +Sample output (w/ bugs remaining) is in sample.test-swift.output + + +Optimizer output (both from C++ optimizer and Swift) generates text +with escape sequences to display colored text. Some versions of more +and less need special options set (eg in env var?) to display the +colors correctly. + + +*** C++ Command line args + +Usage: super_optimizer alpha_i alpha_m beta gamma delta target_innov [n_epochs n_steps n_reruns] [range] [verbose_level] + [T_start T_end Annealing_steps Target_rejection Starting_jump] + [FREEZE_alpha_i FREEZE_alpha_m FREEZE_beta FREEZE_gamma FREEZE_delta] + +*** Swift command line args and internal control vars + The command line options are: + -nworkers= + + -minrange= + Starting number for the target innovation value(Inclusive) + + -maxrange= + Ending number for the target innovation value(exclusive) + + -rangeinc= + How much to increment the target innovation value by + + -tstart= + + -tend= + + -trejection= + + -evoreruns= + How many times to re-run the evolve.sh app // MW: # times to rerun evolve() not evolve.sh ??? + + -startingjump= + Controls the dx and/or rejection variable + + -alphai= + parameter to the annealing process + + -alpham= + parameter to the annealing process + + -beta= + parameter to the annealing process + + -gamma= + parameter to the annealing process + + -delta= + parameter to the annealing process + + -annealingcycles= + Number of times to run the annealing process for a given target innovation + + -rerunsperapp= + Number of evolve reruns to do per app call + + -nreps= + How many times to repeat the annealing process for a given target innovation + + +*** C++ app flow logic === + +for target in range(58, 1009 (used 209), 50): // 20 values Target Values + for i in range(15): Optimization repeats (runs?) + # P0: P1: D: P2: P3: + optimizer |0 0 4 50 -1 target | 40000 20 1000 2 | 1 | 2. 0.01 100 0.3 2.3 | 1 1 0 0 0 + + multi_annealing( un[NW], T_start, T_end, Target_rejection, Annealing_repeats, + starting_jump, Results, Counters, params0, Annealing_repeats); + + Res = multi_loss(un, Results, Counters, x); // Initial + curr_x = Res.first; + curr_err = Res.second; + + for i = 0 to annealing_cycles - 1 (100 from .py script) + for j = 0 to 4 // 5X: 0..4 is fixed constant - one iteration for each of 5 evolve() parameters + setParameters (for a round of parallel Annealing_repeats + Res = multi_loss(un, Results, Counters, Annealing_repeats); + In parallel: for 1 to AnnealingRepeats (1,000; 10,000 desired) + group repeats among NWorkers + evolve() + setParameters again here, conditionally? (check) + +TODO: Merge these two outlines into one: + +P 20 targets - py (target loss) +P 15 repeats - py +S 1 initial multi_loss: 1000 to 10000 annealing_repeats +S 100 Annealing_cycles (groups of 10? : cycle=10 ) (fast:50) +S 5 repeats (fast: 1) +P multi_loss: 1000 to 10000 evolve re-runs +S evolve() (leaf) => 2 mins to 10 mins (is that time for one or for 1000?) + +# a) 20 targets (parallel) +# b) 15 repeats (parallel) of optimizer (optimizer == multi_annealing): +# 1 multi_loss to initialize +# c) 100 Annealing_cycles (serial) +# d) 5 repeats (1 per param, serial) of multi_loss: +# e) 1000 to 10000 annealing_repeats (parallel) == multi_loss +# f) evolve() + +Plots +===== + +In order to generate plots from the swift stdout/stderr file, do the following + +./extract4plots +gnuplot plotit + +gnuplot must be installed and should be in PATH. + +Following plots will be generated: +activeplot.png: number of active jobs over time +cumulativeplot.png: Cumulative number of jobs completed +cumulativeplot-openmp.png: Cumulative number of openmp threads completed +scs.png: SciColSim T value evolution +scs_loss.png: Scicolsim Loss +multiloss.png: Scicolsim loss with stddev + + Added: SwiftApps/SimulatedAnnealing/annealing.swift =================================================================== --- SwiftApps/SimulatedAnnealing/annealing.swift (rev 0) +++ SwiftApps/SimulatedAnnealing/annealing.swift 2014-04-06 22:47:26 UTC (rev 7761) @@ -0,0 +1,487 @@ +import "math"; +import "colortext"; + +type file; + +type Res +{ + float loss; + float sdev; + float tavg; + float tsdev; +} + +type Checkpoint +{ + int i; + int j; + float dx0, dx1, dx2, dx3, dx4; + float rej0, rej1, rej2, rej3, rej4; + float target_innov; + float loss; + float alpha_i; + float alpha_m; + float beta; + float gamma; + float delta; + float sdev; +} + +global boolean restart = (@arg("restart","false") == "true"); +tracef("Restart flag is %b\n", restart); + +global int iterate_adjust = @toint(@arg("iterate_adjust","1")); // FIXME!!! : 1 for 0.93, 0 for 0.94 + +global boolean FIX_VARIABLES = true; +global int var_fixed[] = [0,0,0,0,0]; +global int Nworkers = @toint(@arg("nworkers","4")); +global int rerunsPerApp= @toint(@arg("rerunsperapp", "100")); + +( float nx ) newx( float x, float dx ) +{ + float r = (random()); + + if (r > 0.5) { + nx = x + (random())*dx; //Java already returns a float between [0-1] + } + else { + nx = x - (random())*dx; + } + // tracef("newx(%f,%f)=%f\n",x,dx,nx); +} + +app (/*file outfile,*/ file objout ) orig_objective ( string args[], file objdata ) +{ + # evolve @objout args /*stdout=@outfile*/; // FIXME: objdata file is passed implicitly +} + +/* +function y = simple_objective(x) + y = (4 - 2.1*x(1)^2 + x(1)^4/3)*x(1)^2 + x(1)*x(2) + ... + (-4 + 4*x(2)^2)*x(2)^2; +*/ + +(float y) objective ( float x[], file objdata ) +{ + float x0 = x[0]; + float x1 = x[1]; + float x0s = x0 * x0; + float x1s = x1 * x1; + y = (4.0 - 2.1*x0s + pow(x[0],4.0/3.0))*x0s + x0*x1 + (-4.0 + 4.0*x1s)*x1s; +} + +app (file outfile, file logfile ) sumobjective( file loss[] ) +{ + sumloss @filename(logfile) @filenames(loss) stdout=@filename(outfile); +} + +/* Program structure: + + main + optimizer_sweep() - do N complete annealing optimizations + multi_annealing() + N_objective() + objective() + sumobjective() +*/ + +(file bestfile, file maxfile) multi_annealing (string best_filename, # app + float T_start, # ann + float T_end, # ann + float Target_rejection,# ann + int obj_runs, # app + float starting_jump, # ann + float params0[], # app f(x) + int annealing_cycles) # ann +{ + int cycle = 10; // const + int NEVOPARAMS = 5; // const - 5 params: alpha_i, alpha_m, beta, gamma, delta + + float rejection[][]; // [i][j] where i is cycle and j is evolve-parameter (alpha_i, alpha_m, beta, gamma, delta) + float trejection[][]; + + float x[][], dx[][], curr_loss[], curr_sdev[]; + + Res mlres[][]; + + file ckptFile ; + Checkpoint ckpt; + int restartIndex; + + if (restart) { + ckpt = readData(ckptFile); + restartIndex = ckpt.i; + } + else { + restartIndex = -1; + mlres[0][0] = multi_loss(T_start, T_end, annealing_cycles, Target_rejection, + starting_jump, 0, 0, params0, target_innov, evolve_reruns ); // FIXME: serves for all evolve-params ??? + tracef( "multi_annealing: AR: initial: %f +- %f\n", mlres[0][0].loss, mlres[0][0].sdev ); + + foreach j in [0:NEVOPARAMS-1] { + x[0][j] = params0[j]; + dx[0][j] = starting_jump; + rejection[0][j] = 0.0; + curr_loss[j] = mlres[0][0].loss; + curr_sdev[j] = mlres[0][0].sdev; + } + } + + iterate iter_i { // number of annealing cycles + int i = iter_i + 1; // i ranges [1:n] in the swift script so that [0] can be the initial condition + + // set new temperature, rejection threshold, and dx values for this cycle + float temperature = T_start*exp( @tofloat( i-1 ) * ( jlog( T_end ) - jlog( T_start ) ) / @tofloat( annealing_cycles ) ); + + tracef( @strcat( "multi_annealing: AR: i=%i ....T = ", color( 3, "%f" ),"\n" ), i, temperature ); + + if ( i < restartIndex ) { + tracef( "skipping index %i - less than restart index %i\n", i, restartIndex ); + } + else { if ( i == restartIndex ) { // reset variables from the restart file + dx[i] = [ckpt.dx0, ckpt.dx1, ckpt.dx2, ckpt.dx3, ckpt.dx4]; + rejection[i] = [ckpt.rej0, ckpt.rej1, ckpt.rej2, ckpt.rej3, ckpt.rej4]; + x[i][0] = ckpt.alpha_i; + x[i][1] = ckpt.alpha_m; + x[i][2] = ckpt.beta; + x[i][3] = ckpt.gamma; + x[i][4] = ckpt.delta; + curr_loss[((i+1)*NEVOPARAMS)-1] = ckpt.loss; + curr_sdev[((i+1)*NEVOPARAMS)-1] = ckpt.sdev; + } + else { // i > restartIndex: proceed as normal whether restarting or not + + // On each new "major" cycle within the annealing_cycles (other than the first) set new rejection and dx values + + if (i %% cycle == 1 && i > 1) { + tracef( "multi_annealing: new cycle at i=%i\n", i ); + tracef( color( Pink, "multi_annealing: AR: New cycle at %i: prev dx[0-4]=[%f %f %f %f %f]\n" ), + i, dx[i-1][0], dx[i-1][1], dx[i-1][2], dx[i-1][3], dx[i-1][4] ); + foreach k in [0:NEVOPARAMS-1] { + float newrejection = rejection[i-1][k] / @tofloat( cycle ); + if (newrejection > 0.0) { + dx[i][k] = dx[i-1][k] / ( newrejection / Target_rejection ); + // FIXME: re-enable: rejection[i][k]=0.0; + trejection[i][k]=0.0; + } + else { + dx[i][k] = dx[i-1][k] * 2.0; + // FIXME: re-enable: rejection[i][k]=rejection[i-1][k]; + trejection[i][k]=newrejection; + } + // FIXME: HANGS? : tracef(color(Red,"Recomputed rejection: i=%d k=%d dx[i][k]=%f\n"), i, k, dx[i][k]); + } + tracef( color( Blue, "multi_annealing: AR: New cycle at %i: dx[0-4]=[%f %f %f %f %f]\n" ), + i, dx[i][0], dx[i][1], dx[i][2], dx[i][3], dx[i][4] ); + } + else { // If not new cycle, set dx[i][*] from previous dx ([i-1]). rejection[i][j] is set later. + foreach k in [0:NEVOPARAMS-1] { + dx[i][k] = dx[i-1][k]; + } + } + iterate j { // Try a new value for each non-fixed param; then write results and accept or reject + int curr = ( i * NEVOPARAMS ) + j; + int prev = curr-1; + + if ( /* (!FIX_VARIABLES) || */ ( var_fixed[j] == 0 ) ) { // Adjustable vars + // fixed=1,1,0,0,0: FIXME: FIX_VARIABLES flag has faulty logic but OK when TRUE + float try_x[]; + foreach k in [0:NEVOPARAMS-1] { // Select the evolve params to try + if (k < j) { + try_x[k] = x[i][k]; // already set x[i][k] + } + else { + if (k == j) { + try_x[k] = newx(x[i-1][j], dx[i-1][j]); // permute x[i-1][j] + } + else { // k > j + try_x[k] = x[i-1][k]; // use x[i-1][k] (from prior cycle) + } + } + } + tracef( @strcat( "multi_annealing: AR: ", color( 10,"%f" ), " ", color( 9,"%i" ),"\n" ), try_x[j], j ); + + # Call objective function here: + +# mlres[i][j] = multi_loss( T_start, T_end, annealing_cycles, Target_rejection, starting_jump, + i, j, try_x, target_innov, evolve_reruns ); // do the N evolve()'s, N=evolve_rerusn + mlres[i][j] = multi_loss( try_x, target_innov, evolve_reruns ); // do the N evolve()'s, N=evolve_reruns + + tracef( "multi_annealing: AR: %f +- %f\n", mlres[i][j].loss, mlres[i][j].sdev ); + // Beyond this point, x[] and dx[] are being set for this i,j + float ALOT = 100000000000.0; // 100,000,000,000. = 10^11 + if (mlres[i][j].loss < ALOT) { + fprintf( best_filename, "N, %fs, %i, %i, %f, %f, |, %i, %f, [, %f, %f, %f, %f, %f, ], %f\n", + mlres[i][j].tavg, i-1, j, dx[i][j], rejection[i][j], @toint(target_innov), mlres[i][j].loss, + try_x[0], try_x[1], try_x[2], try_x[3], try_x[4], mlres[i][j].sdev ); + // Note i-1 field: print that way to match with C++ output + + // fprintf( "max_dist_swift.txt", color( Red,"multi_annealing: AF: max_dist.txt - tbd\n" ) ); + // FIXME: max_dist is global set in evolve() + } + else { // does this ever occur? if so did we want to still do the ratio computation above??? + fprintf( best_filename, "A, %fs, %i, %i, %f, %f, |, %i, %f, [, %f, %f, %f, %f, %f, ], %f\n", + mlres[i][j].tavg, i-1, j, dx[i][j], rejection[i][j], @toint(target_innov), mlres[i][j].loss, + try_x[0], try_x[1], try_x[2], try_x[3], try_x[4], mlres[i][j].sdev ); + // Note i-1 field: print that way to match with C++ output + //tracef( "multi_annealing: Loss %f > ALOT at [i][j] = [%d][%d]\n", mlres[i][j].loss, i ,j ); + } + float ratio = min( 1.0, exp( -( mlres[i][j].loss - curr_loss[prev] ) / temperature ) ); + float r = (random()); //Java already returns a random float between [0.0-1.0] + tracef("multi_annealing: AR: %f vs %f\n", r, ratio); + if (r > ratio) { // Reject new parameter + x[i][j] = x[i-1][j]; + if (i %% cycle == 1 && i > 1) { + rejection[i][j] = trejection[i][j] + 1.0; // FIXME: triple-check this! + } + else { + rejection[i][j] = rejection[i-1][j] + 1.0; // FIXME: AR: Is this correct? incr rejection? + } + curr_loss[curr] = curr_loss[prev]; + curr_sdev[curr] = curr_sdev[prev]; + // FIXME: AR: the following prints seem to replicate values in the .cpp version - please clarify. + tracef( "multi_annealing: AR: %i,%i %i Did not accept: %f (%i)\n", i, j, i, try_x[j], j ); + tracef( "multi_annealing: AR: %f %f %f %f %f\n", try_x[0],try_x[1],try_x[2],try_x[3],try_x[4] ); + } + else { // Accept new parameter + tracef( "multi_annealing: Accepting try_x[j], i=%i j=%i\n",i,j ); + x[i][j] = try_x[j]; + if (i %% cycle == 1 && i > 1) { + rejection[i][j] = trejection[i][j]; // FIXME: triple-check this! + } + else { + rejection[i][j] = rejection[i-1][j]; // FIXME: AR: Is this correct? no incr of rejection? + } + curr_loss[curr] = mlres[i][j].loss; + curr_sdev[curr] = mlres[i][j].sdev; + tracef( "multi_annealing: Accepting try_x[j], i=%i j=%i try_x[j]=%f\n", i, j, try_x[j] ); + float rj[]; + foreach k in [0:NEVOPARAMS-1] { + if (k <= j) { + rj[k] = rejection[i][k]; // Was either set from previous j or just set for this j + } + else { + rj[k] = rejection[i-1][k]; // Not yet set, use previous + } + } + tracef(@strcat("multi_annealing: AR: [%i][%i] ", color(8,"Rejection counts: "), + color(1,"%f"), " ", color(7,"%f"), " ", color(5,"%f"), " ", color(9,"%f"), " ", color(6,"%f"), "\n\n"), + i, j, rj[0], rj[1], rj[2], rj[3], rj[4]); + tracef(@strcat("multi_annealing: AR: %i ", color(8,"***** Did accept! "), + color(1,"%f"), " ", color(7,"%f"), " ", color(5,"%f"), " ", color(9,"%f"), " ", color(6,"%f"), "\n\n"), + i, try_x[0], try_x[1], try_x[2], try_x[3], try_x[4]); + } + } + else {// Fixed Vars + x[i][j] = x[i-1][j]; + rejection[i][j] = rejection[i-1][j]; + curr_loss[curr] = curr_loss[prev]; + curr_sdev[curr] = curr_sdev[prev]; + // dx[i][j] not set for fixed vars + } + } until( j == (NEVOPARAMS-iterate_adjust) ); + }} // of if/else + } until( iter_i == (annealing_cycles-iterate_adjust) ); +} + +/* +(Res r) multi_loss(float t_start, float t_end, int annealing_steps, float t_rejection, float starting_jump, + int ci, int cj, float x[], float target_innov, int evolve_reruns) +*/ + +(Res r) N_objective(float x[], int obj_runs) +{ + tracef("%q\n", x); + file rfile[]; + //file ofile[]; // FIXME: to obtain timings and other stats + + tracef( "N_objective: entered: obj_runs=%i x=%q\n", obj_runs, x ); + + int appCalls = @toint(@tofloat(obj_runs)/@tofloat(runsPerApp)); // FIXME: handle fractional issues and rounding etc. + // For now must divide evenly + tracef("N_objective appCalls=%i\n", appCalls); + + foreach i in [1:appCalls] { // repeats of the objective() - same as n_reruns + //file outfile; // FIXME: map and save in future + string args[] = [ // FIXME: move this to a setargs() function + // alpha_i alpha_m beta gamma delta + @strcat(x[0]), @strcat(x[1]), @strcat(x[2]), @strcat(x[3]), @strcat(x[4]), + // n_epochs n_steps n_runs range + "40000", "20", @strcat(rerunsPerApp), "2", + // verbose_level + "1", + // operation-code:(m,a) Nworkers seed + "m", @strcat(Nworkers), @arg("seed", "0" ) ]; + + file graph <"movie_graph.txt">; + + (/*outfile,*/ rfile[i]) = objective(args, graph); + tracef("multi_loss: i=%i calling objective, args=%q\n", i, args); + // tracef("multi_objective: after objective: i=%i %k %k\n", i, outfile, rfile[i]); + } + + string anneal_cycle; + if(ci==0) { + anneal_cycle="init"; + } + else { + anneal_cycle=@strcat(ci-1); + } + + file sumfile; + file logfile; + + (sumfile, logfile) = sumloss(rfile); + r = readData(sumfile); + + tracef("multi_loss: returning: ci=%i cj=%i r.loss=%f r.sdev=%f\n",ci,cj,r.loss,r.sdev); + // file statfile = sumstats(ofile); FIXME: to obtain timings and other stats + // s = readStat(statsfile); FIXME: to obtain timings and other stats +} + +optimizer_serial_sweep() // Implements logic of python driver script +{ + + int minrange = @toint(@arg("minrange", "58")); + int maxrange = @toint(@arg("maxrange", "59")); + int rangeinc = @toint(@arg("rangeinc", "50")); + + // FIXME: add provision for random priming and random param values when x[i] == -100 (see optimizer.cpp main()) + + int nreps = @toint(@arg("nreps", "1")); + +//file bestfile ; +//file maxfile ; + +# foreach target_innov in [minrange:maxrange:rangeinc] { + iterate i { + int target_innov = minrange + (i*rangeinc); + foreach rep in [1:nreps] { + + string best_filename = @strcat( "best.T", @strcat(target_innov), ".R", @strcat(rep), ".txt" ); + file outfile; // ; + file lossfile; // ; + + (outfile,lossfile) = multi_annealing(best_filename, + @tofloat(@arg("tstart", "2.0")), + @tofloat(@arg("tend", "0.01")), + @tofloat(@arg("trejection", "0.3")), + @toint(@arg("evoreruns", "100")), + @tofloat(@arg("startingjump", "2.3")), + [ @tofloat(@arg("alphai", "0.0")), + @tofloat(@arg("alpham", "0.0")), + @tofloat(@arg("beta", "4.0")), + @tofloat(@arg("gamma", "50.0")), + @tofloat(@arg("delta", "-1.0")) + ], + @tofloat(target_innov), + @toint(@arg("annealingcycles", "50")) ); + } + } until(target_innov >= (maxrange-rangeinc)); +} + +optimizer_sweep() // Implements logic of python driver script +{ + + int minrange = @toint(@arg("minrange", "58")); + int maxrange = @toint(@arg("maxrange", "59")); + int rangeinc = @toint(@arg("rangeinc", "50")); + + // FIXME: add provision for random priming and random param values when x[i] == -100 (see optimizer.cpp main()) + + int nreps = @toint(@arg("nreps", "1")); + +//file bestfile ; +//file maxfile ; + + foreach target_innov in [minrange:maxrange:rangeinc] { + foreach rep in [1:nreps] { + + string best_filename = @strcat( "best.T", @strcat(target_innov), ".R", @strcat(rep), ".txt" ); + file outfile; // ; + file lossfile; // ; + + (outfile,lossfile) = multi_annealing(best_filename, + @tofloat(@arg("tstart", "2.0")), + @tofloat(@arg("tend", "0.01")), + @tofloat(@arg("trejection", "0.3")), + @toint(@arg("evoreruns", "100")), + @tofloat(@arg("startingjump", "2.3")), + [ @tofloat(@arg("alphai", "0.0")), + @tofloat(@arg("alpham", "0.0")), + @tofloat(@arg("beta", "4.0")), + @tofloat(@arg("gamma", "50.0")), + @tofloat(@arg("delta", "-1.0")) + ], + @tofloat(target_innov), + @toint(@arg("annealingcycles", "50")) ); + } + } +} + +main() +{ + optimizer_sweep(); +} + +main(); + +/* + + Program structure: + + main + optimizer_sweep() + multi_annealing() + multi_loss() + evolve() + sumloss() + + Example parameter sets: + + for target in range(58,59,50): + for i in range(1): + args="./toptimizer 0 0 4 50 -1 "+target+" 40000 20 75 2 1 2. 0.01 2 0.3 2.3 1 1 1 0 0 m // > out.T"+str(target)+".i"+str(i) + os.system(args); + + string fastargs1[] = [ + "0", "0", "4", "50", "-1", @strcat(target), + "40000", "20", "1000", "2", + "1", + "2.", "0.01", "100", "0.3", "2.3", + "1", "1", "0", "0", "0"]; + string fastargs2[] = [ + "0", "0", "4", "50", "-1", @strcat(target), + "40000", "20", "1000", "2", + "1", + "2.", "0.01", "5", "0.3", "2.3", + "1", "1", "0", "0", "0", "m"]; + string fastargs3[] = [ + "0", "0", "4", "50", "-1", @strcat(target), + "40000", "20", @strcat(repeats), "2", + "1", + "2.", "0.01", "2", "0.3", "2.3", + "1", "1", "0", "0", "0", "m"]; +*/ + +(string args[]) setargs() +{ + // string longargs[] = @strcat("0 0 4 50 -1 ",target," 40000 20 1000 2 1 2. 0.01 100 0.3 2.3 1 1 0 0 0 m"); + + // [alpha_i alpha_m beta gamma delta target_innov + // [n_epochs n_steps n_reruns] [range] + // [verbose_level] + // [T_start T_end Annealing_steps Target_rejection Starting_jump] + // [FREEZE_alpha_i FREEZE_alpha_m FREEZE_beta FREEZE_gamma FREEZE_delta] [operation-code:(m,a) Nworkers] +} + +////////////////// HOLD JUNK + +// tracef(@strcat("multi_annealing: AR: %i ", color(8,"Rejection counts: "), +// color( /* 2 */ 1," %f"), "\n\n"), +// i, rejection[i][j] ); // , rejection[i][1], rejection[i][2], rejection[i][3], rejection[i][4]); +// FIXME: determine correct rejection[] values to avoid hanging: +// tracef(@strcat("multi_annealing: AR: %i ", color(8,"Rejection counts: "), +// color( /* 2 */ 1," %f"), color(7," %f"), color(5," %f"), color(9," %f"), color(6," %f"), "\n\n"), +// rejection[i][0], rejection[i][1], rejection[i][2], rejection[i][3], rejection[i][4]); +// END FIXME Added: SwiftApps/SimulatedAnnealing/colortext.swift =================================================================== --- SwiftApps/SimulatedAnnealing/colortext.swift (rev 0) +++ SwiftApps/SimulatedAnnealing/colortext.swift 2014-04-06 22:47:26 UTC (rev 7761) @@ -0,0 +1,90 @@ +global string e33; // = @sprintf("\\e") or @arg("e33"); + +if( @arg("e33","null") == "null" ) { + e33 = @sprintf("\\e"); +} +else { + e33 = @arg("e33"); +} + +global string endEscape = "[0m"; + +// Color codes used in Andrey's cpp optimizer: + +global int Black = 0; +global int Blue = 1; +global int BlackOnBlue = 2; +global int Pink = 3; +global int GoldOnBlue = 4; +global int BlueOnGray = 5; +global int Red = 6; +global int Gold = 7; +global int BlueOnGold = 8; +global int Gray = 9; +global int BlackOnGray = 10; + +# Black = 0; +# Blue = 1; +# BlackOnBlue = 2; +# Pink = 3; +# GoldOnBlue = 4; +# BlueOnGray = 5; +# Red = 6; +# Gold = 7; +# BlueOnGold = 8; +# Gray = 9; +# BlackOnGray = 10; + +global string colorCode[] = [ + "[1;29m", # Black = 0; + "[1;34m", # Blue = 1; + "[1;44m", # BlackOnBlue = 2; + "[1;35m", # Pink = 3; + "[1;33;44m", # GoldOnBlue = 4; + "[1;47;34m", # BlueOnGray = 5; + "[1;1;31m", # Red = 6; + "[1;1;33m", # Gold = 7; + "[1;1;43;34m", # BlueOnGold = 8; + "[1;1;37m", # Gray = 9; + "[1;30;47m", # BlackOnGray = 10; +]; + +(string s) color(int c, string ins) +{ + s = @strcat(e33,colorCode[c],ins,e33,endEscape); +} + +(string s) ncolor(int c, string ins) // Can use this version if \\e handling is available in current Swift +{ + s = @sprintf(@strcat("\\e",colorCode[c],ins,"\\e",endEscape)); // sprintf applies \\e escape processing +} + +(string s) OLDcolor(int c, string ins) +{ + switch(c){ + case 0: + s = @strcat(e33,"[1;29m",ins,e33,"[0m"); + case 1: + s = @strcat(e33,"[1;34m",ins,e33,"[0m"); + case 2: + s = @strcat(e33,"[1;44m",ins,e33,"[0m"); + case 3: + s = @strcat(e33,"[1;35m",ins,e33,"[0m"); + case 4: + s = @strcat(e33,"[1;33;44m",ins,e33,"[0m"); + case 5: + s = @strcat(e33,"[1;47;34m",ins,e33,"[0m"); + case 6: + s = @strcat(e33,"[1;1;31m",ins,e33,"[0m"); + case 7: + s = @strcat(e33,"[1;1;33m",ins,e33,"[0m"); + case 8: + s = @strcat(e33,"[1;1;43;34m",ins,e33,"[0m"); + case 9: + s = @strcat(e33,"[1;1;37m",ins,e33,"[0m"); + case 10: + s = @strcat(e33,"[1;30;47m",ins,e33,"[0m"); + default: + s = ins; + } +} Added: SwiftApps/SimulatedAnnealing/math.swift =================================================================== --- SwiftApps/SimulatedAnnealing/math.swift (rev 0) +++ SwiftApps/SimulatedAnnealing/math.swift 2014-04-06 22:47:26 UTC (rev 7761) @@ -0,0 +1,76 @@ + +(float result) sin(float x) +{ + result = @java("java.lang.Math", "sin", x); +} + +(float result) exp(float x) +{ + result = @java("java.lang.Math", "exp", x); +} + +(float result) jlog(float x) +{ + result = @java("java.lang.Math", "log", x); +} + +(float result) log10(float x) +{ + result = @java("java.lang.Math", "log10", x); +} + +(float result) ceil(float x) +{ + result = @java("java.lang.Math", "ceil", x); +} + +(float result) floor (float x) +{ + result = @java("java.lang.Math", "floor", x); +} + +(float result) min (float a, float b) +{ + //result = @java("java.lang.Math", "min", a, b); + if ( a < b ) { + result = a; + } + else { + result = b; + } + tracef("math/min: result=%f\n",result); +} + +(float result) pow (float x, float y) +{ + result = @java("java.lang.Math", "pow", x, y); +} + +(float result) random () +{ + result = @java("java.lang.Math","random"); +} + +// Functions below are exprimental and do not work +// FIXME: fix 0.93 problems casting ints as doubles internally. +// This breaks the @java interface for Swift ints. + +(string result) itos (int i) +{ + result = @java("java.lang.Integer","toString",i); +} + +(string result) itos2 (int i) +{ + result = @java("java.lang.String","valueOf",i); +} + +(string result) ctos (int i) +{ + result = @java("java.lang.Character","valueOf",i); +} + +(string result) format (string f, int c) +{ + result = @java("java.lang.String", "format", f, c ); +} Added: SwiftApps/SimulatedAnnealing/params/ARFull =================================================================== --- SwiftApps/SimulatedAnnealing/params/ARFull (rev 0) +++ SwiftApps/SimulatedAnnealing/params/ARFull 2014-04-06 22:47:26 UTC (rev 7761) @@ -0,0 +1,18 @@ + +min_target_innovation 58 # starting target innovation value to try +max_target_innovation 1009 # stops before this target innovation value +target_innovation_increment 50 # increment target innovation by this amount + +annealing_repeats 1 # times to repeate the entire optimization process for each target_innovation +annealing_cycles 100 # times to perform the simulated annealing loop for all non-fixed parameters + +evolve_reruns 10000 # times to perform evolve_to_target_and_save() (objective function - is batched) +nworkers 24 # number of parallel threads (cores) to use per invocation of C++ optimizer +reruns_per_opt_invocation 240 # reruns_per_opt_invocation mod nworkers must == 0 !!! <=== NOTE WELL !!! + +alpha_i 0.0 # 5 evolve() parameters: must be decimal values !!! +alpha_m 0.0 +beta 4.0 +gamma 50.0 +delta -1.0 + Added: SwiftApps/SimulatedAnnealing/params/ARtest01 =================================================================== --- SwiftApps/SimulatedAnnealing/params/ARtest01 (rev 0) +++ SwiftApps/SimulatedAnnealing/params/ARtest01 2014-04-06 22:47:26 UTC (rev 7761) @@ -0,0 +1,18 @@ + +min_target_innovation = 58 # starting target innovation value to try +max_target_innovation = 209 # stops before this target innovation value +target_innovation_increment = 50 # increment target innovation by this amount + +annealing_repeats = 15 # times to repeate the entire optimization process for each target_innovation +annealing_cycles = 100 # times to perform the simulated annealing loop for all non-fixed parameters + +evolve_reruns = 1000 # times to perform evolve_to_target_and_save() (objective function - is batched) +nworkers = 2 # number of parallel threads (cores) to use per invocation of C++ optimizer +reruns_per_opt_invocation = 100 # reruns_per_opt_invocation mod nworkers must == 0 !!! <=== NOTE WELL !!! + +alpha_i = 0.0 # 5 evolve() parameters: must be decimal values !!! +alpha_m = 0.0 # alpha_i and alpha_m are fixed for now +beta = 4.0 # rest are varied by the optimization process +gamma = 50.0 +delta = -1.0 + Added: SwiftApps/SimulatedAnnealing/params/ARtest02 =================================================================== --- SwiftApps/SimulatedAnnealing/params/ARtest02 (rev 0) +++ SwiftApps/SimulatedAnnealing/params/ARtest02 2014-04-06 22:47:26 UTC (rev 7761) @@ -0,0 +1,18 @@ + +min_target_innovation 58 # starting target innovation value to try +max_target_innovation 59 # stops before this target innovation value +target_innovation_increment 50 # increment target innovation by this amount + +annealing_repeats 1 # times to repeate the entire optimization process for each target_innovation +annealing_cycles 100 # times to perform the simulated annealing loop for all non-fixed parameters + +evolve_reruns 10000 # times to perform evolve_to_target_and_save() (objective function - is batched) +nworkers 24 # number of parallel threads (cores) to use per invocation of C++ optimizer +reruns_per_opt_invocation 48 # reruns_per_opt_invocation mod nworkers must == 0 !!! <=== NOTE WELL !!! + +alpha_i 0.0 # 5 evolve() parameters: must be decimal values !!! +alpha_m 0.0 # alpha_i and alpha_m are fixed for now +beta 4.0 # rest are varied by the optimization process +gamma 50.0 +delta -1.0 + Added: SwiftApps/SimulatedAnnealing/params/ARtest03 =================================================================== --- SwiftApps/SimulatedAnnealing/params/ARtest03 (rev 0) +++ SwiftApps/SimulatedAnnealing/params/ARtest03 2014-04-06 22:47:26 UTC (rev 7761) @@ -0,0 +1,18 @@ + +min_target_innovation 50 # starting target innovation value to try +max_target_innovation 51 # stops before this target innovation value +target_innovation_increment 135 # increment target innovation by this amount + +annealing_repeats 1 # times to repeate the entire optimization process for each target_innovation +annealing_cycles 25 # times to perform the simulated annealing loop for all non-fixed parameters + +evolve_reruns 96 # times to perform evolve_to_target_and_save() (objective function - is batched) +nworkers 24 # number of parallel threads (cores) to use per invocation of C++ optimizer +reruns_per_opt_invocation 24 # reruns_per_opt_invocation mod nworkers must == 0 !!! <=== NOTE WELL !!! + +alpha_i 0.0 # 5 evolve() parameters: must be decimal values !!! +alpha_m 0.0 # alpha_i and alpha_m are fixed for now +beta 0.0 # rest are varied by the optimization process +gamma 0.0 +delta 0.0 + Added: SwiftApps/SimulatedAnnealing/params/ARtest04 =================================================================== --- SwiftApps/SimulatedAnnealing/params/ARtest04 (rev 0) +++ SwiftApps/SimulatedAnnealing/params/ARtest04 2014-04-06 22:47:26 UTC (rev 7761) @@ -0,0 +1,18 @@ + +min_target_innovation 270 # starting target innovation value to try +max_target_innovation 1357 # stops before this target innovation value +target_innovation_increment 540 # increment target innovation by this amount + +annealing_repeats 1 # times to repeate the entire optimization process for each target_innovation +annealing_cycles 100 # times to perform the simulated annealing loop for all non-fixed parameters + +evolve_reruns 10080 # times to perform evolve_to_target_and_save() (objective function - is batched) +nworkers 24 # number of parallel threads (cores) to use per invocation of C++ optimizer +reruns_per_opt_invocation 24 # reruns_per_opt_invocation mod nworkers must == 0 !!! <=== NOTE WELL !!! + +alpha_i 0.0 # 5 evolve() parameters: must be decimal values !!! +alpha_m 0.0 # alpha_i and alpha_m are fixed for now +beta 0.0 # rest are varied by the optimization process +gamma 0.0 +delta 0.0 + Added: SwiftApps/SimulatedAnnealing/params/ARtest05 =================================================================== --- SwiftApps/SimulatedAnnealing/params/ARtest05 (rev 0) +++ SwiftApps/SimulatedAnnealing/params/ARtest05 2014-04-06 22:47:26 UTC (rev 7761) @@ -0,0 +1,17 @@ + +min_target_innovation 67 # starting target innovation value to try: 67 134 201 268 335 402 469 536 603 670 +max_target_innovation 672 # stops before this target innovation value +target_innovation_increment 67 # increment target innovation by this amount + +annealing_repeats 1 # times to repeate the entire optimization process for each target_innovation +annealing_cycles 100 # times to perform the simulated annealing loop for all non-fixed parameters + +evolve_reruns 5040 # times to perform evolve_to_target_and_save() (objective function - is batched) +nworkers 24 # number of parallel threads (cores) to use per invocation of C++ optimizer +reruns_per_opt_invocation 240 # reruns_per_opt_invocation mod nworkers must == 0 !!! <=== NOTE WELL !!! + +alpha_i 0.0 # 5 evolve() parameters: must be decimal values !!! +alpha_m 0.0 # alpha_i and alpha_m are fixed for now +beta 0.0 # rest are varied by the optimization process +gamma 0.0 +delta 0.0 Added: SwiftApps/SimulatedAnnealing/params/ARtest06 =================================================================== --- SwiftApps/SimulatedAnnealing/params/ARtest06 (rev 0) +++ SwiftApps/SimulatedAnnealing/params/ARtest06 2014-04-06 22:47:26 UTC (rev 7761) @@ -0,0 +1,19 @@ + +min_target_innovation 67 # starting target innovation value to try: 67 134 201 268 335 402 469 536 603 670 +max_target_innovation 672 # stops before this target innovation value +target_innovation_increment 67 # increment target innovation by this amount + +annealing_repeats 1 # times to repeate the entire optimization process for each target_innovation +annealing_cycles 100 # times to perform the simulated annealing loop for all non-fixed parameters + +evolve_reruns 5040 # times to perform evolve_to_target_and_save() (objective function - is batched) +nworkers 24 # number of parallel threads (cores) to use per invocation of C++ optimizer +reruns_per_opt_invocation 120 # reruns_per_opt_invocation mod nworkers must == 0 !!! <=== NOTE WELL !!! + +alpha_i 0.0 # 5 evolve() parameters: must be decimal values !!! +alpha_m 0.0 # alpha_i and alpha_m are fixed for now +beta 0.0 # rest are varied by the optimization process +gamma 0.0 +delta 0.0 + +starting_jump 0.3 Added: SwiftApps/SimulatedAnnealing/params/BetaTest =================================================================== --- SwiftApps/SimulatedAnnealing/params/BetaTest (rev 0) +++ SwiftApps/SimulatedAnnealing/params/BetaTest 2014-04-06 22:47:26 UTC (rev 7761) @@ -0,0 +1,20 @@ + +min_target_innovation 58 # starting target innovation value to try +max_target_innovation 59 # stops before this target innovation value +target_innovation_increment 50 # increment target innovation by this amount + +annealing_repeats 1 # times to repeate the entire optimization process for each target_innovation +annealing_cycles 100 # times to perform the simulated annealing loop for all non-fixed parameters + +evolve_reruns 60 # times to perform evolve_to_target_and_save() (objective function - is batched) +nworkers 1 # number of parallel threads (cores) to use per invocation of C++ optimizer +reruns_per_opt_invocation 2 # reruns_per_opt_invocation mod nworkers must == 0 !!! <=== NOTE WELL !!! + +alpha_i 0.0 # 5 evolve() parameters: must be decimal values !!! +alpha_m 0.0 # alpha_i and alpha_m are fixed for now +beta 4.0 # rest are varied by the optimization process +gamma 50.0 +delta -1.0 + + +JOB_THROTTLE .26 Added: SwiftApps/SimulatedAnnealing/params/Fast01 =================================================================== --- SwiftApps/SimulatedAnnealing/params/Fast01 (rev 0) +++ SwiftApps/SimulatedAnnealing/params/Fast01 2014-04-06 22:47:26 UTC (rev 7761) @@ -0,0 +1,20 @@ + +min_target_innovation 58 # starting target innovation value to try +max_target_innovation 59 # stops before this target innovation value +target_innovation_increment 50 # increment target innovation by this amount + +annealing_repeats 1 # times to repeate the entire optimization process for each target_innovation +annealing_cycles 10 # times to perform the simulated annealing loop for all non-fixed parameters + +evolve_reruns 100 # times to perform evolve_to_target_and_save() (objective function - is batched) +nworkers 24 # number of parallel threads (cores) to use per invocation of C++ optimizer +reruns_per_opt_invocation 48 # reruns_per_opt_invocation mod nworkers must == 0 !!! <=== NOTE WELL !!! + +alpha_i 0.0 # 5 evolve() parameters: must be decimal values !!! +alpha_m 0.0 # alpha_i and alpha_m are fixed for now +beta 4.0 # rest are varied by the optimization process +gamma 50.0 +delta -1.0 + + +JOB_THROTTLE .05 Added: SwiftApps/SimulatedAnnealing/params/KMtest01 =================================================================== --- SwiftApps/SimulatedAnnealing/params/KMtest01 (rev 0) +++ SwiftApps/SimulatedAnnealing/params/KMtest01 2014-04-06 22:47:26 UTC (rev 7761) @@ -0,0 +1,20 @@ + +min_target_innovation 58 # starting target innovation value to try +max_target_innovation 70 # stops before this target innovation value +target_innovation_increment 1 # increment target innovation by this amount + +annealing_repeats 1 # times to repeate the entire optimization process for each target_innovation +annealing_cycles 100 # times to perform the simulated annealing loop for all non-fixed parameters + +evolve_reruns 1000 # times to perform evolve_to_target_and_save() (objective function - is batched) +nworkers 20 # number of parallel threads (cores) to use per invocation of C++ optimizer +reruns_per_opt_invocation 200 # reruns_per_opt_invocation mod nworkers must == 0 !!! <=== NOTE WELL !!! + +alpha_i 0.0 # 5 evolve() parameters: must be decimal values !!! +alpha_m 0.0 # alpha_i and alpha_m are fixed for now +beta 4.0 # rest are varied by the optimization process +gamma 50.0 +delta -1.0 + + +JOB_THROTTLE 9.99 Added: SwiftApps/SimulatedAnnealing/params/MWtest01 =================================================================== --- SwiftApps/SimulatedAnnealing/params/MWtest01 (rev 0) +++ SwiftApps/SimulatedAnnealing/params/MWtest01 2014-04-06 22:47:26 UTC (rev 7761) @@ -0,0 +1,17 @@ + +min_target_innovation = 58 +max_target_innovation = 1009 +target_innovation_increment = 50 + +annealing_repeats = 1 +annealing_cycles = 100 +evolve_reruns = 1000 + +alpha_i = 0.0 # 5 parameters: must be decimal values !!! +alpha_m = 0.0 +beta = 4.0 +gamma = 50.0 +delta = -1.0 + +nworkers = 2 +reruns_per_opt_invocation = 100 # reruns_per_opt_invocation mod nworkers must == 0 !!! <=== NOTE WELL !!! Added: SwiftApps/SimulatedAnnealing/params/MWtest02 =================================================================== --- SwiftApps/SimulatedAnnealing/params/MWtest02 (rev 0) +++ SwiftApps/SimulatedAnnealing/params/MWtest02 2014-04-06 22:47:26 UTC (rev 7761) @@ -0,0 +1,21 @@ + +# Test with one target_innovation and few evolve_reruns to verify numeric behavior + +min_target_innovation 67 # starting target innovation value to try +max_target_innovation 68 # stops before this target innovation value +target_innovation_increment 135 # increment target innovation by this amount + +annealing_repeats 1 # times to repeate the entire optimization process for each target_innovation +annealing_cycles 20 # times to perform the simulated annealing loop for all non-fixed parameters + +evolve_reruns 4 # times to perform evolve_to_target_and_save() (objective function - is batched) +nworkers 1 # number of parallel threads (cores) to use per invocation of C++ optimizer +reruns_per_opt_invocation 4 # reruns_per_opt_invocation mod nworkers must == 0 !!! <=== NOTE WELL !!! + +alpha_i 0.0 # 5 evolve() parameters: must be decimal values !!! +alpha_m 0.0 # alpha_i and alpha_m are fixed for now +beta 0.0 # rest are varied by the optimization process +gamma 0.0 +delta 0.0 + +starting_jump 0.3 Added: SwiftApps/SimulatedAnnealing/params/MWtest03 =================================================================== --- SwiftApps/SimulatedAnnealing/params/MWtest03 (rev 0) +++ SwiftApps/SimulatedAnnealing/params/MWtest03 2014-04-06 22:47:26 UTC (rev 7761) @@ -0,0 +1,19 @@ + +min_target_innovation 58 # starting target innovation value to try +max_target_innovation 109 # stops before this target innovation value +target_innovation_increment 50 # increment target innovation by this amount + +annealing_repeats 3 # times to repeate the entire optimization process for each target_innovation +annealing_cycles 100 # times to perform the simulated annealing loop for all non-fixed parameters + +evolve_reruns 16 # times to perform evolve_to_target_and_save() (objective function - is batched) +nworkers 8 # number of parallel threads (cores) to use per invocation of C++ optimizer +reruns_per_opt_invocation 16 # reruns_per_opt_invocation mod nworkers must == 0 !!! <=== NOTE WELL !!! + +alpha_i 0.0 # 5 evolve() parameters: must be decimal values !!! +alpha_m 0.0 # alpha_i and alpha_m are fixed for now +beta 4.0 # rest are varied by the optimization process +gamma 50.0 +delta -1.0 + +JOB_THROTTLE .10 Added: SwiftApps/SimulatedAnnealing/params/MWtest04 =================================================================== --- SwiftApps/SimulatedAnnealing/params/MWtest04 (rev 0) +++ SwiftApps/SimulatedAnnealing/params/MWtest04 2014-04-06 22:47:26 UTC (rev 7761) @@ -0,0 +1,19 @@ + +min_target_innovation 58 # starting target innovation value to try +max_target_innovation 1009 # stops before this target innovation value +target_innovation_increment 50 # increment target innovation by this amount + +annealing_repeats 1 # times to repeate the entire optimization process for each target_innovation +annealing_cycles 100 # times to perform the simulated annealing loop for all non-fixed parameters + +evolve_reruns 160 # times to perform evolve_to_target_and_save() (objective function - is batched) +nworkers 8 # number of parallel threads (cores) to use per invocation of C++ optimizer +reruns_per_opt_invocation 80 # reruns_per_opt_invocation mod nworkers must == 0 !!! <=== NOTE WELL !!! + +alpha_i 0.0 # 5 evolve() parameters: must be decimal values !!! +alpha_m 0.0 # alpha_i and alpha_m are fixed for now +beta 4.0 # rest are varied by the optimization process +gamma 50.0 +delta -1.0 + +JOB_THROTTLE 3.99 Added: SwiftApps/SimulatedAnnealing/params/MWtest05 =================================================================== --- SwiftApps/SimulatedAnnealing/params/MWtest05 (rev 0) +++ SwiftApps/SimulatedAnnealing/params/MWtest05 2014-04-06 22:47:26 UTC (rev 7761) @@ -0,0 +1,19 @@ + +min_target_innovation 58 # starting target innovation value to try +max_target_innovation 109 # stops before this target innovation value +target_innovation_increment 50 # increment target innovation by this amount + +annealing_repeats 3 # times to repeate the entire optimization process for each target_innovation +annealing_cycles 100 # times to perform the simulated annealing loop for all non-fixed parameters + +evolve_reruns 48 # times to perform evolve_to_target_and_save() (objective function - is batched) +nworkers 24 # number of parallel threads (cores) to use per invocation of C++ optimizer +reruns_per_opt_invocation 48 # reruns_per_opt_invocation mod nworkers must == 0 !!! <=== NOTE WELL !!! + +alpha_i 0.0 # 5 evolve() parameters: must be decimal values !!! +alpha_m 0.0 # alpha_i and alpha_m are fixed for now +beta 4.0 # rest are varied by the optimization process +gamma 50.0 +delta -1.0 + +JOB_THROTTLE .10 Added: SwiftApps/SimulatedAnnealing/params/MWtest06 =================================================================== --- SwiftApps/SimulatedAnnealing/params/MWtest06 (rev 0) +++ SwiftApps/SimulatedAnnealing/params/MWtest06 2014-04-06 22:47:26 UTC (rev 7761) @@ -0,0 +1,18 @@ + +min_target_innovation 58 # starting target innovation value to try +max_target_innovation 1009 # stops before this target innovation value +target_innovation_increment 50 # increment target innovation by this amount + +annealing_repeats 2 # times to repeate the entire optimization process for each target_innovation +annealing_cycles 100 # times to perform the simulated annealing loop for all non-fixed parameters + +evolve_reruns 960 # times to perform evolve_to_target_and_save() (objective function - is batched) +nworkers 24 # number of parallel threads (cores) to use per invocation of C++ optimizer +reruns_per_opt_invocation 240 # reruns_per_opt_invocation mod nworkers must == 0 !!! <=== NOTE WELL !!! + +alpha_i 0.0 # 5 evolve() parameters: must be decimal values !!! +alpha_m 0.0 # alpha_i and alpha_m are fixed for now +beta 4.0 # rest are varied by the optimization process +gamma 50.0 +delta -1.0 + Added: SwiftApps/SimulatedAnnealing/params/MWtest07 =================================================================== --- SwiftApps/SimulatedAnnealing/params/MWtest07 (rev 0) +++ SwiftApps/SimulatedAnnealing/params/MWtest07 2014-04-06 22:47:26 UTC (rev 7761) @@ -0,0 +1,18 @@ + +min_target_innovation 58 # starting target innovation value to try +max_target_innovation 1009 # stops before this target innovation value +target_innovation_increment 50 # increment target innovation by this amount + +annealing_repeats 1 # times to repeate the entire optimization process for each target_innovation +annealing_cycles 100 # times to perform the simulated annealing loop for all non-fixed parameters + +evolve_reruns 400 # times to perform evolve_to_target_and_save() (objective function - is batched) +nworkers 8 # number of parallel threads (cores) to use per invocation of C++ optimizer +reruns_per_opt_invocation 40 # reruns_per_opt_invocation mod nworkers must == 0 !!! <=== NOTE WELL !!! + +alpha_i 0.0 # 5 evolve() parameters: must be decimal values !!! +alpha_m 0.0 # alpha_i and alpha_m are fixed for now +beta 4.0 # rest are varied by the optimization process +gamma 50.0 +delta -1.0 + Added: SwiftApps/SimulatedAnnealing/swiftopt.sh =================================================================== --- SwiftApps/SimulatedAnnealing/swiftopt.sh (rev 0) +++ SwiftApps/SimulatedAnnealing/swiftopt.sh 2014-04-06 22:47:26 UTC (rev 7761) @@ -0,0 +1,191 @@ +#!/bin/bash + +# Usage: swiftopt.sh [-s sitename] [-p paramfile] [-w] [-n # for dryrun ] +# +# NOTE: this command expects symlink "swift" in the cur dir to point +# to relese installed by setup.sh If you want to run with a different +# swift release, replace symlink "swift" with a link to your swift +# release dir. + +usage="$0 [-s sitename] [-p paramfile] [-n] [-w] [-l] # -n for dryrun: just print params and time estimates" + +# Function to run Swift +runswift() { + SWIFT_HEAP_MAX=$ram SWIFT_LIB=.. swift >> swift.out 2>&1 -tc.file tc.data -sites.file $1 -config cf annealing.swift -e33="$escapecode" \ + \ + -minrange=$min_target_innovation \ + -maxrange=$max_target_innovation \ + -rangeinc=$target_innovation_increment \ + \ + -nreps=$annealing_repeats \ + -annealingcycles=$annealing_cycles \ + -evoreruns=$evolve_reruns \ + \ + -alphai=$alpha_i \ + -alpham=$alpha_m \ + -beta=$beta \ + -gamma=$gamma \ + -delta=$delta \ + \ + -startingjump=$starting_jump \ + \ + -nworkers=$nworkers \ + -rerunsperapp=$reruns_per_opt_invocation \ + -wget=$wget \ + -longruns=$longruns \ + -restart=$restart +} + + +# Default settings +execsite=local +paramfile=Fast01 +ram=6000M +dryrun= +escapecode=$(printf '\033') +variable_params=5 # Currently CONSTANT, will want to have this vary +wget=false +longruns=false + +# Process command line arguments +while [ $# -gt 0 ]; do + case $1 in + -l) longruns=true; shift 1;; # FIXME + -n) dryrun=true; shift 1;; + -p) paramfile=$2; shift 2;; + -s) execsite=$2; shift 2;; + -w) wget=true; shift 1;; # FIXME + -r) resdir=$2; shift 2;; + *) echo $usage 1>&2 + exit 1;; + esac +done + +# Create next unique run id and run directory +rundir=$( echo run??? | sed -e 's/^.*run//' | awk '{ printf("run%03d\n", $1+1)}' ) + +#Exit if rundir already exits. Something is funky +if [ -d $rundir ]; +then + echo "$rundir already exists! exiting." >&2 + exit 2 +else + mkdir $rundir +fi + +if [ _$resdir != _ ]; then + if [ -d resdir ]; then + restart=true + cp $resdir/ckpt.* $rundir + else + echo $0: no restart directory $resdir found. + exit 1 + fi +else + restart=false +fi + +# Get optimization parameters +if [ ! -f params/$paramfile ]; +then + echo "Could not find parameter file $paramfile in params!" + exit 1 +fi +cp params/$paramfile $rundir/paramfile +sed -e '/^[[:space:]]*\(#.*\)*$/d' -e 's/#.*//' -e 's/ */=/' -e 's/^/export /' $rundir/params.annealing +source $rundir/params.annealing +#swift=../swift/bin/swift # relative to runNNN/ dirs +echo Optimization $rundir: site=$execsite paramfile=$paramfile + +# Report an error if configuration files are missing +if [ ! -f "conf/$execsite.xml" ] && [ ! -f "conf/$execsite.conf" ]; then + echo Unable to find requested configuration file for site $execsite + exit 1 +fi + +# Use start-coaster-service if site is a .conf file +if [ -f "conf/$execsite.conf" ]; then + USE_SCS=1 +fi + +# Check for missing .cf files +if [ -f "conf/$execsite.xml" ] && [ ! -f "conf/$execsite.cf" ]; then + echo Missing configuration file $execsite.cf +fi + +cp movie_graph.txt $rundir +cp annealing.swift $rundir +cp colortext.swift $rundir +cp math.swift $rundir + +# Echo parameters +echo Annealing parameters: +echo +cat $rundir/params.annealing +echo + +# Echo runtime estimates +total_jobs=`python -c "from math import ceil; print int(ceil(($max_target_innovation.00 - $min_target_innovation.00)/$target_innovation_increment.00) * $annealing_repeats * $variable_params * $annealing_cycles * $evolve_reruns/$reruns_per_opt_invocation)"` +echo Total jobs = $total_jobs + +cd $rundir + +# Do the run +export WORK=$PWD/swiftwork +mkdir -p $PWD/swiftwork/workers + +# Use start-coaster-service if the site uses a .conf file +if [ "$USE_SCS" == "1" ]; then + cp ../conf/$execsite.conf coaster-service.conf + cp ../conf/$execsite.cf cf + sed -i -e "s at _RUNDIR_@$rundir@" coaster-service.conf + start-coaster-service +fi + +# Run gensites +if [ ! "$USE_SCS" == 1 ]; then + cp ../conf/$execsite.cf cf + # SWIFT_HOME=../swift/bin ../swift/bin/gensites -p ../conf/$execsite.cf ../conf/$execsite.xml > $execsite.xml + gensites -p ../conf/$execsite.cf ../conf/$execsite.xml > $execsite.xml +fi + +echo "Run dir=$rundir" >> ABOUT +echo "Work dir=$WORK" >> ABOUT +echo "Total jobs=$total_jobs" >> ABOUT +echo "Run Command: SWIFT_HEAP_MAX=$ram SWIFT_LIB=.. swift >> swift.out 2>&1 -tc.file tc.data -sites.file $execsite.xml -config cf annealing.swift -minrange=$min_target_innovation -maxrange=$max_target_innovation-rangeinc=$target_innovation_increment -nreps=$annealing_repeats -annealingcycles=$annealing_cycles -evoreruns=$evolve_reruns -alphai=$alpha_i -alpham=$alpha_m -beta=$beta -gamma=$gamma -delta=$delta -nworkers=$nworkers -rerunsperapp=$reruns_per_opt_invocation -e33="$escapecode"" >> ABOUT + +if [ _$dryrun != _ ]; then + exit 0 +fi + +if [ "$USE_SCS" == "1" ]; then + runswift "sites.xml" + stop-coaster-service +else + runswift "$execsite.xml" +fi + +# Run the convertbest.sh script on the generated txt files from within the rundir +../bin/convertbest.sh *.txt + +exit + +# @arg("nworkers","4") +# @arg("rerunsperapp", "100") +# @arg("seed", "0" ) FIXME +# @arg("minrange", "58") +# @arg("maxrange", "59") +# @arg("rangeinc", "50") +# @arg("nreps", "1") +# @arg("tstart", "2.0") FIXME +# @arg("tend", "0.01") FIXME +# @arg("trejection", "0.3") FIXME +# @arg("evoreruns", "100") +# @arg("startingjump", "2.3") +# @arg("alphai", "0.0") +# @arg("alpham", "0.0") +# @arg("beta", "4.0") +# @arg("gamma", "50.0") +# @arg("delta", "-1.0") +# @arg("annealingcycles", "50") + Property changes on: SwiftApps/SimulatedAnnealing/swiftopt.sh ___________________________________________________________________ Added: svn:executable + * From wilde at ci.uchicago.edu Mon Apr 7 11:54:03 2014 From: wilde at ci.uchicago.edu (wilde at ci.uchicago.edu) Date: Mon, 7 Apr 2014 11:54:03 -0500 (CDT) Subject: [Swift-commit] r7762 - SwiftApps/SimulatedAnnealing Message-ID: <20140407165403.758DA9D62F@svn.ci.uchicago.edu> Author: wilde Date: 2014-04-07 11:54:02 -0500 (Mon, 07 Apr 2014) New Revision: 7762 Modified: SwiftApps/SimulatedAnnealing/annealing.swift Log: Converted to use generic objective function. Converted variable names to reflect more general terminology (eg loss -> result). Used simple avg() function to average N runs of objectve function. Modified: SwiftApps/SimulatedAnnealing/annealing.swift =================================================================== --- SwiftApps/SimulatedAnnealing/annealing.swift 2014-04-06 22:47:26 UTC (rev 7761) +++ SwiftApps/SimulatedAnnealing/annealing.swift 2014-04-07 16:54:02 UTC (rev 7762) @@ -1,30 +1,29 @@ import "math"; -import "colortext"; type file; type Res { - float loss; + float result; +/* float sdev; float tavg; float tsdev; +*/ } type Checkpoint { int i; int j; - float dx0, dx1, dx2, dx3, dx4; + float dx0, dx1, dx2, dx3, dx4; float rej0, rej1, rej2, rej3, rej4; - float target_innov; - float loss; + float result; float alpha_i; float alpha_m; float beta; float gamma; float delta; - float sdev; } global boolean restart = (@arg("restart","false") == "true"); @@ -50,31 +49,36 @@ // tracef("newx(%f,%f)=%f\n",x,dx,nx); } -app (/*file outfile,*/ file objout ) orig_objective ( string args[], file objdata ) -{ - # evolve @objout args /*stdout=@outfile*/; // FIXME: objdata file is passed implicitly -} - /* function y = simple_objective(x) - y = (4 - 2.1*x(1)^2 + x(1)^4/3)*x(1)^2 + x(1)*x(2) + ... - (-4 + 4*x(2)^2)*x(2)^2; + y = (4 - 2.1*x(1)^2 + x(1)^4/3)*x(1)^2 + x(1)*x(2) + (-4 + 4*x(2)^2)*x(2)^2; */ -(float y) objective ( float x[], file objdata ) +(float y) objective ( float x[] ) { float x0 = x[0]; float x1 = x[1]; float x0s = x0 * x0; float x1s = x1 * x1; - y = (4.0 - 2.1*x0s + pow(x[0],4.0/3.0))*x0s + x0*x1 + (-4.0 + 4.0*x1s)*x1s; + float r = random() * .1; + tracef("r=%f\n",r); + y = ( (4.0 - 2.1*x0s + pow(x[0],4.0/3.0))*x0s + x0*x1 + (-4.0 + 4.0*x1s)*x1s ) + r; } -app (file outfile, file logfile ) sumobjective( file loss[] ) +(float s) sum (float a[]) { - sumloss @filename(logfile) @filenames(loss) stdout=@filename(outfile); + string t[] = system("echo " + strjoin(a,"+") + "|bc"); + s = toFloat(t[0]); } +(float a) avg (float f[]) +{ + float n = toFloat( length(f) ); + float t1 = sum(f); + float t2 = t1 / n; + a = t2; +} + /* Program structure: main @@ -100,11 +104,11 @@ float rejection[][]; // [i][j] where i is cycle and j is evolve-parameter (alpha_i, alpha_m, beta, gamma, delta) float trejection[][]; - float x[][], dx[][], curr_loss[], curr_sdev[]; + float x[][], dx[][], curr_result[]; - Res mlres[][]; + Res objres[][]; - file ckptFile ; + file ckptFile ; Checkpoint ckpt; int restartIndex; @@ -114,16 +118,19 @@ } else { restartIndex = -1; +/* mlres[0][0] = multi_loss(T_start, T_end, annealing_cycles, Target_rejection, starting_jump, 0, 0, params0, target_innov, evolve_reruns ); // FIXME: serves for all evolve-params ??? - tracef( "multi_annealing: AR: initial: %f +- %f\n", mlres[0][0].loss, mlres[0][0].sdev ); +*/ + objres[0][0] = N_objective(params0, obj_runs ); // FIXME: serves for all evolve-params ??? + + tracef( "multi_annealing: initial: %f\n", objres[0][0].result ); foreach j in [0:NEVOPARAMS-1] { x[0][j] = params0[j]; dx[0][j] = starting_jump; rejection[0][j] = 0.0; - curr_loss[j] = mlres[0][0].loss; - curr_sdev[j] = mlres[0][0].sdev; + curr_result[j] = objres[0][0].result; } } @@ -133,7 +140,7 @@ // set new temperature, rejection threshold, and dx values for this cycle float temperature = T_start*exp( @tofloat( i-1 ) * ( jlog( T_end ) - jlog( T_start ) ) / @tofloat( annealing_cycles ) ); - tracef( @strcat( "multi_annealing: AR: i=%i ....T = ", color( 3, "%f" ),"\n" ), i, temperature ); + tracef("multi_annealing: i=%i ....T =%f\n", i, temperature ); if ( i < restartIndex ) { tracef( "skipping index %i - less than restart index %i\n", i, restartIndex ); @@ -146,8 +153,7 @@ x[i][2] = ckpt.beta; x[i][3] = ckpt.gamma; x[i][4] = ckpt.delta; - curr_loss[((i+1)*NEVOPARAMS)-1] = ckpt.loss; - curr_sdev[((i+1)*NEVOPARAMS)-1] = ckpt.sdev; + curr_result[((i+1)*NEVOPARAMS)-1] = ckpt.result; } else { // i > restartIndex: proceed as normal whether restarting or not @@ -155,7 +161,7 @@ if (i %% cycle == 1 && i > 1) { tracef( "multi_annealing: new cycle at i=%i\n", i ); - tracef( color( Pink, "multi_annealing: AR: New cycle at %i: prev dx[0-4]=[%f %f %f %f %f]\n" ), + tracef( "multi_annealing: New cycle at %i: prev dx[0-4]=[%f %f %f %f %f]\n", i, dx[i-1][0], dx[i-1][1], dx[i-1][2], dx[i-1][3], dx[i-1][4] ); foreach k in [0:NEVOPARAMS-1] { float newrejection = rejection[i-1][k] / @tofloat( cycle ); @@ -169,9 +175,9 @@ // FIXME: re-enable: rejection[i][k]=rejection[i-1][k]; trejection[i][k]=newrejection; } - // FIXME: HANGS? : tracef(color(Red,"Recomputed rejection: i=%d k=%d dx[i][k]=%f\n"), i, k, dx[i][k]); + // FIXME: HANGS? : tracef("Recomputed rejection: i=%d k=%d dx[i][k]=%f\n", i, k, dx[i][k]); } - tracef( color( Blue, "multi_annealing: AR: New cycle at %i: dx[0-4]=[%f %f %f %f %f]\n" ), + tracef( "multi_annealing: New cycle at %i: dx[0-4]=[%f %f %f %f %f]\n", i, dx[i][0], dx[i][1], dx[i][2], dx[i][3], dx[i][4] ); } else { // If not new cycle, set dx[i][*] from previous dx ([i-1]). rejection[i][j] is set later. @@ -199,34 +205,24 @@ } } } - tracef( @strcat( "multi_annealing: AR: ", color( 10,"%f" ), " ", color( 9,"%i" ),"\n" ), try_x[j], j ); + tracef( "multi_annealing: %f %i\n", try_x[j], j ); # Call objective function here: # mlres[i][j] = multi_loss( T_start, T_end, annealing_cycles, Target_rejection, starting_jump, - i, j, try_x, target_innov, evolve_reruns ); // do the N evolve()'s, N=evolve_rerusn - mlres[i][j] = multi_loss( try_x, target_innov, evolve_reruns ); // do the N evolve()'s, N=evolve_reruns +# i, j, try_x, target_innov, evolve_reruns ); // do the N evolve()'s, N=evolve_rerusn + objres[i][j] = N_objective( try_x, obj_runs ); - tracef( "multi_annealing: AR: %f +- %f\n", mlres[i][j].loss, mlres[i][j].sdev ); + tracef( "multi_annealing: %f\n", objres[i][j].result ); // Beyond this point, x[] and dx[] are being set for this i,j - float ALOT = 100000000000.0; // 100,000,000,000. = 10^11 - if (mlres[i][j].loss < ALOT) { - fprintf( best_filename, "N, %fs, %i, %i, %f, %f, |, %i, %f, [, %f, %f, %f, %f, %f, ], %f\n", - mlres[i][j].tavg, i-1, j, dx[i][j], rejection[i][j], @toint(target_innov), mlres[i][j].loss, - try_x[0], try_x[1], try_x[2], try_x[3], try_x[4], mlres[i][j].sdev ); + fprintf( best_filename, "%i, %i, %f, %f, | %f [ %f, %f, %f, %f, %f ]\n", + i-1, j, dx[i][j], rejection[i][j], objres[i][j].result, + try_x[0], try_x[1], try_x[2], try_x[3], try_x[4] ); // Note i-1 field: print that way to match with C++ output // fprintf( "max_dist_swift.txt", color( Red,"multi_annealing: AF: max_dist.txt - tbd\n" ) ); // FIXME: max_dist is global set in evolve() - } - else { // does this ever occur? if so did we want to still do the ratio computation above??? - fprintf( best_filename, "A, %fs, %i, %i, %f, %f, |, %i, %f, [, %f, %f, %f, %f, %f, ], %f\n", - mlres[i][j].tavg, i-1, j, dx[i][j], rejection[i][j], @toint(target_innov), mlres[i][j].loss, - try_x[0], try_x[1], try_x[2], try_x[3], try_x[4], mlres[i][j].sdev ); - // Note i-1 field: print that way to match with C++ output - //tracef( "multi_annealing: Loss %f > ALOT at [i][j] = [%d][%d]\n", mlres[i][j].loss, i ,j ); - } - float ratio = min( 1.0, exp( -( mlres[i][j].loss - curr_loss[prev] ) / temperature ) ); + float ratio = min( 1.0, exp( -( objres[i][j].result - curr_result[prev] ) / temperature ) ); float r = (random()); //Java already returns a random float between [0.0-1.0] tracef("multi_annealing: AR: %f vs %f\n", r, ratio); if (r > ratio) { // Reject new parameter @@ -237,11 +233,10 @@ else { rejection[i][j] = rejection[i-1][j] + 1.0; // FIXME: AR: Is this correct? incr rejection? } - curr_loss[curr] = curr_loss[prev]; - curr_sdev[curr] = curr_sdev[prev]; + curr_result[curr] = curr_result[prev]; // FIXME: AR: the following prints seem to replicate values in the .cpp version - please clarify. - tracef( "multi_annealing: AR: %i,%i %i Did not accept: %f (%i)\n", i, j, i, try_x[j], j ); - tracef( "multi_annealing: AR: %f %f %f %f %f\n", try_x[0],try_x[1],try_x[2],try_x[3],try_x[4] ); + tracef( "multi_annealing: %i,%i %i Did not accept: %f (%i)\n", i, j, i, try_x[j], j ); + tracef( "multi_annealing: %f %f %f %f %f\n", try_x[0],try_x[1],try_x[2],try_x[3],try_x[4] ); } else { // Accept new parameter tracef( "multi_annealing: Accepting try_x[j], i=%i j=%i\n",i,j ); @@ -252,8 +247,7 @@ else { rejection[i][j] = rejection[i-1][j]; // FIXME: AR: Is this correct? no incr of rejection? } - curr_loss[curr] = mlres[i][j].loss; - curr_sdev[curr] = mlres[i][j].sdev; + curr_result[curr] = objres[i][j].result; tracef( "multi_annealing: Accepting try_x[j], i=%i j=%i try_x[j]=%f\n", i, j, try_x[j] ); float rj[]; foreach k in [0:NEVOPARAMS-1] { @@ -264,19 +258,16 @@ rj[k] = rejection[i-1][k]; // Not yet set, use previous } } - tracef(@strcat("multi_annealing: AR: [%i][%i] ", color(8,"Rejection counts: "), - color(1,"%f"), " ", color(7,"%f"), " ", color(5,"%f"), " ", color(9,"%f"), " ", color(6,"%f"), "\n\n"), + tracef("multi_annealing: [%i][%i] Rejection counts: %f %f %f %f %f\n\n", i, j, rj[0], rj[1], rj[2], rj[3], rj[4]); - tracef(@strcat("multi_annealing: AR: %i ", color(8,"***** Did accept! "), - color(1,"%f"), " ", color(7,"%f"), " ", color(5,"%f"), " ", color(9,"%f"), " ", color(6,"%f"), "\n\n"), + tracef("multi_annealing: %i ***** Did accept! %f %f %f %f %f\n\n", i, try_x[0], try_x[1], try_x[2], try_x[3], try_x[4]); } } else {// Fixed Vars x[i][j] = x[i-1][j]; rejection[i][j] = rejection[i-1][j]; - curr_loss[curr] = curr_loss[prev]; - curr_sdev[curr] = curr_sdev[prev]; + curr_result[curr] = curr_result[prev]; // dx[i][j] not set for fixed vars } } until( j == (NEVOPARAMS-iterate_adjust) ); @@ -284,59 +275,19 @@ } until( iter_i == (annealing_cycles-iterate_adjust) ); } -/* -(Res r) multi_loss(float t_start, float t_end, int annealing_steps, float t_rejection, float starting_jump, - int ci, int cj, float x[], float target_innov, int evolve_reruns) -*/ - (Res r) N_objective(float x[], int obj_runs) { tracef("%q\n", x); - file rfile[]; - //file ofile[]; // FIXME: to obtain timings and other stats + float result[]; tracef( "N_objective: entered: obj_runs=%i x=%q\n", obj_runs, x ); - int appCalls = @toint(@tofloat(obj_runs)/@tofloat(runsPerApp)); // FIXME: handle fractional issues and rounding etc. - // For now must divide evenly - tracef("N_objective appCalls=%i\n", appCalls); - - foreach i in [1:appCalls] { // repeats of the objective() - same as n_reruns - //file outfile; // FIXME: map and save in future - string args[] = [ // FIXME: move this to a setargs() function - // alpha_i alpha_m beta gamma delta - @strcat(x[0]), @strcat(x[1]), @strcat(x[2]), @strcat(x[3]), @strcat(x[4]), - // n_epochs n_steps n_runs range - "40000", "20", @strcat(rerunsPerApp), "2", - // verbose_level - "1", - // operation-code:(m,a) Nworkers seed - "m", @strcat(Nworkers), @arg("seed", "0" ) ]; - - file graph <"movie_graph.txt">; - - (/*outfile,*/ rfile[i]) = objective(args, graph); - tracef("multi_loss: i=%i calling objective, args=%q\n", i, args); - // tracef("multi_objective: after objective: i=%i %k %k\n", i, outfile, rfile[i]); + foreach i in [1:obj_runs] { // repeats of the objective() - same as n_reruns + result[i] = objective(x); } - string anneal_cycle; - if(ci==0) { - anneal_cycle="init"; - } - else { - anneal_cycle=@strcat(ci-1); - } - - file sumfile; - file logfile; - - (sumfile, logfile) = sumloss(rfile); - r = readData(sumfile); - - tracef("multi_loss: returning: ci=%i cj=%i r.loss=%f r.sdev=%f\n",ci,cj,r.loss,r.sdev); - // file statfile = sumstats(ofile); FIXME: to obtain timings and other stats - // s = readStat(statsfile); FIXME: to obtain timings and other stats + r.result = avg(result); + tracef("multi_loss: returning: r.result=%f\n", r.result); } optimizer_serial_sweep() // Implements logic of python driver script @@ -353,14 +304,14 @@ //file bestfile ; //file maxfile ; -# foreach target_innov in [minrange:maxrange:rangeinc] { - iterate i { - int target_innov = minrange + (i*rangeinc); +# foreach target_innov in [minrange:maxrange:rangeinc] { +# iterate i { +# int target_innov = minrange + (i*rangeinc); foreach rep in [1:nreps] { - string best_filename = @strcat( "best.T", @strcat(target_innov), ".R", @strcat(rep), ".txt" ); - file outfile; // ; - file lossfile; // ; + string best_filename = @strcat( "best.R", @strcat(rep), ".txt" ); + file outfile; // ; + file lossfile; // ; (outfile,lossfile) = multi_annealing(best_filename, @tofloat(@arg("tstart", "2.0")), @@ -374,10 +325,9 @@ @tofloat(@arg("gamma", "50.0")), @tofloat(@arg("delta", "-1.0")) ], - @tofloat(target_innov), @toint(@arg("annealingcycles", "50")) ); } - } until(target_innov >= (maxrange-rangeinc)); + # } until(target_innov >= (maxrange-rangeinc)); } optimizer_sweep() // Implements logic of python driver script @@ -394,12 +344,12 @@ //file bestfile ; //file maxfile ; - foreach target_innov in [minrange:maxrange:rangeinc] { +# foreach target_innov in [minrange:maxrange:rangeinc] { foreach rep in [1:nreps] { - string best_filename = @strcat( "best.T", @strcat(target_innov), ".R", @strcat(rep), ".txt" ); - file outfile; // ; - file lossfile; // ; + string best_filename = @strcat( "best.R", @strcat(rep), ".txt" ); + file outfile; // ; + file lossfile; // ; (outfile,lossfile) = multi_annealing(best_filename, @tofloat(@arg("tstart", "2.0")), @@ -413,10 +363,9 @@ @tofloat(@arg("gamma", "50.0")), @tofloat(@arg("delta", "-1.0")) ], - @tofloat(target_innov), @toint(@arg("annealingcycles", "50")) ); } - } +# } } main() @@ -425,63 +374,3 @@ } main(); - -/* - - Program structure: - - main - optimizer_sweep() - multi_annealing() - multi_loss() - evolve() - sumloss() - - Example parameter sets: - - for target in range(58,59,50): - for i in range(1): - args="./toptimizer 0 0 4 50 -1 "+target+" 40000 20 75 2 1 2. 0.01 2 0.3 2.3 1 1 1 0 0 m // > out.T"+str(target)+".i"+str(i) - os.system(args); - - string fastargs1[] = [ - "0", "0", "4", "50", "-1", @strcat(target), - "40000", "20", "1000", "2", - "1", - "2.", "0.01", "100", "0.3", "2.3", - "1", "1", "0", "0", "0"]; - string fastargs2[] = [ - "0", "0", "4", "50", "-1", @strcat(target), - "40000", "20", "1000", "2", - "1", - "2.", "0.01", "5", "0.3", "2.3", - "1", "1", "0", "0", "0", "m"]; - string fastargs3[] = [ - "0", "0", "4", "50", "-1", @strcat(target), - "40000", "20", @strcat(repeats), "2", - "1", - "2.", "0.01", "2", "0.3", "2.3", - "1", "1", "0", "0", "0", "m"]; -*/ - -(string args[]) setargs() -{ - // string longargs[] = @strcat("0 0 4 50 -1 ",target," 40000 20 1000 2 1 2. 0.01 100 0.3 2.3 1 1 0 0 0 m"); - - // [alpha_i alpha_m beta gamma delta target_innov - // [n_epochs n_steps n_reruns] [range] - // [verbose_level] - // [T_start T_end Annealing_steps Target_rejection Starting_jump] - // [FREEZE_alpha_i FREEZE_alpha_m FREEZE_beta FREEZE_gamma FREEZE_delta] [operation-code:(m,a) Nworkers] -} - -////////////////// HOLD JUNK - -// tracef(@strcat("multi_annealing: AR: %i ", color(8,"Rejection counts: "), -// color( /* 2 */ 1," %f"), "\n\n"), -// i, rejection[i][j] ); // , rejection[i][1], rejection[i][2], rejection[i][3], rejection[i][4]); -// FIXME: determine correct rejection[] values to avoid hanging: -// tracef(@strcat("multi_annealing: AR: %i ", color(8,"Rejection counts: "), -// color( /* 2 */ 1," %f"), color(7," %f"), color(5," %f"), color(9," %f"), color(6," %f"), "\n\n"), -// rejection[i][0], rejection[i][1], rejection[i][2], rejection[i][3], rejection[i][4]); -// END FIXME From ketan at ci.uchicago.edu Fri Apr 11 14:12:06 2014 From: ketan at ci.uchicago.edu (ketan at ci.uchicago.edu) Date: Fri, 11 Apr 2014 14:12:06 -0500 (CDT) Subject: [Swift-commit] r7763 - SwiftApps/swift-galaxy/swift Message-ID: <20140411191206.5C9809CD1D@svn.ci.uchicago.edu> Author: ketan Date: 2014-04-11 14:12:06 -0500 (Fri, 11 Apr 2014) New Revision: 7763 Modified: SwiftApps/swift-galaxy/swift/swiftforeachlist.sh SwiftApps/swift-galaxy/swift/swiftforeachrange.sh Log: small fix Modified: SwiftApps/swift-galaxy/swift/swiftforeachlist.sh =================================================================== --- SwiftApps/swift-galaxy/swift/swiftforeachlist.sh 2014-04-07 16:54:02 UTC (rev 7762) +++ SwiftApps/swift-galaxy/swift/swiftforeachlist.sh 2014-04-11 19:12:06 UTC (rev 7763) @@ -18,10 +18,10 @@ shift outloc=$1 shift +logfile=$1 +shift outlistfile=$1 shift -logfile=$1 -shift stringargs=$1 shift Modified: SwiftApps/swift-galaxy/swift/swiftforeachrange.sh =================================================================== --- SwiftApps/swift-galaxy/swift/swiftforeachrange.sh 2014-04-07 16:54:02 UTC (rev 7762) +++ SwiftApps/swift-galaxy/swift/swiftforeachrange.sh 2014-04-11 19:12:06 UTC (rev 7763) @@ -23,10 +23,10 @@ shift outloc=$1 shift +logfile=$1 +shift outlistfile=$1 shift -logfile=$1 -shift stringargs=$1 shift From wilde at ci.uchicago.edu Fri Apr 11 16:43:06 2014 From: wilde at ci.uchicago.edu (wilde at ci.uchicago.edu) Date: Fri, 11 Apr 2014 16:43:06 -0500 (CDT) Subject: [Swift-commit] r7764 - SwiftApps/SimulatedAnnealing Message-ID: <20140411214306.A3C829CF85@svn.ci.uchicago.edu> Author: wilde Date: 2014-04-11 16:43:06 -0500 (Fri, 11 Apr 2014) New Revision: 7764 Added: SwiftApps/SimulatedAnnealing/sa.swift Log: New simpler kinder gentler annealer. Added: SwiftApps/SimulatedAnnealing/sa.swift =================================================================== --- SwiftApps/SimulatedAnnealing/sa.swift (rev 0) +++ SwiftApps/SimulatedAnnealing/sa.swift 2014-04-11 21:43:06 UTC (rev 7764) @@ -0,0 +1,388 @@ +import "math"; + +type file; + +type Res +{ + float result; +/* + float sdev; + float tavg; + float tsdev; +*/ +} + +type Checkpoint +{ + int i; + int j; + float dx0, dx1, dx2, dx3, dx4; + float rej0, rej1, rej2, rej3, rej4; + float result; + float alpha_i; + float alpha_m; + float beta; + float gamma; + float delta; +} + +global boolean restart = (@arg("restart","false") == "true"); +tracef("Restart flag is %b\n", restart); + +global int iterate_adjust = @toint(@arg("iterate_adjust","1")); // FIXME!!! : 1 for 0.93, 0 for 0.94 + +global boolean FIX_VARIABLES = true; +global int var_fixed[] = [0,0,0,0,0]; +global int Nworkers = @toint(@arg("nworkers","4")); +global int rerunsPerApp= @toint(@arg("rerunsperapp", "100")); + +( float nx ) newx( float x, float dx ) +{ + float r = (random()); + + if (r > 0.5) { + nx = x + (random())*dx; //Java already returns a float between [0-1] + } + else { + nx = x - (random())*dx; + } + // tracef("newx(%f,%f)=%f\n",x,dx,nx); +} + +/* +function y = simple_objective(x) + y = (4 - 2.1*x(1)^2 + x(1)^4/3)*x(1)^2 + x(1)*x(2) + (-4 + 4*x(2)^2)*x(2)^2; +*/ + +(float y) objective ( float x[] ) +{ + float x0 = x[0]; + float x1 = x[1]; + float x0s = x0 * x0; + float x1s = x1 * x1; + float r = random() * .1; + tracef("r=%f\n",r); + y = ( (4.0 - 2.1*x0s + pow(x[0],4.0/3.0))*x0s + x0*x1 + (-4.0 + 4.0*x1s)*x1s ) + r; +} + +(float s) sum (float a[]) +{ + string t[] = system("echo " + strjoin(a,"+") + "|bc"); + s = toFloat(t[0]); +} + +(float a) avg (float f[]) +{ + float n = toFloat( length(f) ); + float t1 = sum(f); + float t2 = t1 / n; + a = t2; +} + +/* Program structure: + + main + optimizer_sweep() - do N complete annealing optimizations + multi_annealing() + N_objective() + objective() + sumobjective() +*/ + +(file bestfile, file maxfile) multi_annealing (string best_filename, # app + float T_start, # ann + float T_end, # ann + float Target_rejection,# ann + int obj_runs, # app + float starting_jump, # ann + float params0[], # app f(x) + int annealing_cycles) # ann +{ + int cycle = 10; // const + int NEVOPARAMS = 5; // const - 5 params: alpha_i, alpha_m, beta, gamma, delta + + float rejection[][]; // [i][j] where i is cycle and j is evolve-parameter (alpha_i, alpha_m, beta, gamma, delta) + float trejection[][]; + + float x[][], dx[][], curr_result[]; + + Res objres[][]; + + file ckptFile ; + Checkpoint ckpt; + int restartIndex; + + if (restart) { + ckpt = readData(ckptFile); + restartIndex = ckpt.i; + } + else { + restartIndex = -1; +/* + mlres[0][0] = multi_loss(T_start, T_end, annealing_cycles, Target_rejection, + starting_jump, 0, 0, params0, target_innov, evolve_reruns ); // FIXME: serves for all evolve-params ??? +*/ + objres[0][0] = N_objective(params0, obj_runs ); // FIXME: serves for all evolve-params ??? + + tracef( "multi_annealing: initial: %f\n", objres[0][0].result ); + + foreach j in [0:NEVOPARAMS-1] { + x[0][j] = params0[j]; + dx[0][j] = starting_jump; + rejection[0][j] = 0.0; + curr_result[j] = objres[0][0].result; + } + } + + iterate iter_i { // number of annealing cycles + int i = iter_i + 1; // i ranges [1:n] in the swift script so that [0] can be the initial condition + + // set new temperature, rejection threshold, and dx values for this cycle + float temperature = T_start*exp( @tofloat( i-1 ) * ( jlog( T_end ) - jlog( T_start ) ) / @tofloat( annealing_cycles ) ); + + tracef("multi_annealing: i=%i ....T =%f\n", i, temperature ); + + if ( i < restartIndex ) { + tracef( "skipping index %i - less than restart index %i\n", i, restartIndex ); + } + else { if ( i == restartIndex ) { // reset variables from the restart file + dx[i] = [ckpt.dx0, ckpt.dx1, ckpt.dx2, ckpt.dx3, ckpt.dx4]; + rejection[i] = [ckpt.rej0, ckpt.rej1, ckpt.rej2, ckpt.rej3, ckpt.rej4]; + x[i][0] = ckpt.alpha_i; + x[i][1] = ckpt.alpha_m; + x[i][2] = ckpt.beta; + x[i][3] = ckpt.gamma; + x[i][4] = ckpt.delta; + curr_result[((i+1)*NEVOPARAMS)-1] = ckpt.result; + } + else { // i > restartIndex: proceed as normal whether restarting or not + + // On each new "major" cycle within the annealing_cycles (other than the first) set new rejection and dx values + + if (i %% cycle == 1 && i > 1) { + tracef( "multi_annealing: new cycle at i=%i\n", i ); + tracef( "multi_annealing: New cycle at %i: prev dx[0-4]=[%f %f %f %f %f]\n", + i, dx[i-1][0], dx[i-1][1], dx[i-1][2], dx[i-1][3], dx[i-1][4] ); + foreach k in [0:NEVOPARAMS-1] { + float newrejection = rejection[i-1][k] / @tofloat( cycle ); + if (newrejection > 0.0) { + dx[i][k] = dx[i-1][k] / ( newrejection / Target_rejection ); + // FIXME: re-enable: rejection[i][k]=0.0; + trejection[i][k]=0.0; + } + else { + dx[i][k] = dx[i-1][k] * 2.0; + // FIXME: re-enable: rejection[i][k]=rejection[i-1][k]; + trejection[i][k]=newrejection; + } + // FIXME: HANGS? : tracef("Recomputed rejection: i=%d k=%d dx[i][k]=%f\n", i, k, dx[i][k]); + } + tracef( "multi_annealing: New cycle at %i: dx[0-4]=[%f %f %f %f %f]\n", + i, dx[i][0], dx[i][1], dx[i][2], dx[i][3], dx[i][4] ); + } + else { // If not new cycle, set dx[i][*] from previous dx ([i-1]). rejection[i][j] is set later. + foreach k in [0:NEVOPARAMS-1] { + dx[i][k] = dx[i-1][k]; + } + } + iterate j { // Try a new value for each non-fixed param; then write results and accept or reject + int curr = ( i * NEVOPARAMS ) + j; + int prev = curr-1; + + if ( /* (!FIX_VARIABLES) || */ ( var_fixed[j] == 0 ) ) { // Adjustable vars + // fixed=1,1,0,0,0: FIXME: FIX_VARIABLES flag has faulty logic but OK when TRUE + float try_x[]; + foreach k in [0:NEVOPARAMS-1] { // Select the evolve params to try + if (k < j) { + try_x[k] = x[i][k]; // already set x[i][k] + } + else { + if (k == j) { + try_x[k] = newx(x[i-1][j], dx[i-1][j]); // permute x[i-1][j] + } + else { // k > j + try_x[k] = x[i-1][k]; // use x[i-1][k] (from prior cycle) + } + } + } + tracef( "multi_annealing: %f %i\n", try_x[j], j ); + + # Call objective function here: + +# mlres[i][j] = multi_loss( T_start, T_end, annealing_cycles, Target_rejection, starting_jump, +# i, j, try_x, target_innov, evolve_reruns ); // do the N evolve()'s, N=evolve_rerusn + objres[i][j] = N_objective( try_x, obj_runs ); + + tracef( "multi_annealing: %f\n", objres[i][j].result ); + // Beyond this point, x[] and dx[] are being set for this i,j + fprintf( best_filename, "%i, %i, %f, %f, | %f [ %f, %f, %f, %f, %f ]\n", + i-1, j, dx[i][j], rejection[i][j], objres[i][j].result, + try_x[0], try_x[1], try_x[2], try_x[3], try_x[4] ); + // Note i-1 field: print that way to match with C++ output + + // fprintf( "max_dist_swift.txt", color( Red,"multi_annealing: AF: max_dist.txt - tbd\n" ) ); + // FIXME: max_dist is global set in evolve() + float ratio = min( 1.0, exp( -( objres[i][j].result - curr_result[prev] ) / temperature ) ); + float r = (random()); //Java already returns a random float between [0.0-1.0] + tracef("multi_annealing: AR: %f vs %f\n", r, ratio); + if (r > ratio) { // Reject new parameter + x[i][j] = x[i-1][j]; + if (i %% cycle == 1 && i > 1) { + rejection[i][j] = trejection[i][j] + 1.0; // FIXME: triple-check this! + } + else { + rejection[i][j] = rejection[i-1][j] + 1.0; // FIXME: AR: Is this correct? incr rejection? + } + curr_result[curr] = curr_result[prev]; + // FIXME: AR: the following prints seem to replicate values in the .cpp version - please clarify. + tracef( "multi_annealing: %i,%i %i Did not accept: %f (%i)\n", i, j, i, try_x[j], j ); + tracef( "multi_annealing: %f %f %f %f %f\n", try_x[0],try_x[1],try_x[2],try_x[3],try_x[4] ); + } + else { // Accept new parameter + tracef( "multi_annealing: Accepting try_x[j], i=%i j=%i\n",i,j ); + x[i][j] = try_x[j]; + if (i %% cycle == 1 && i > 1) { + rejection[i][j] = trejection[i][j]; // FIXME: triple-check this! + } + else { + rejection[i][j] = rejection[i-1][j]; // FIXME: AR: Is this correct? no incr of rejection? + } + curr_result[curr] = objres[i][j].result; + tracef( "multi_annealing: Accepting try_x[j], i=%i j=%i try_x[j]=%f\n", i, j, try_x[j] ); + float rj[]; + foreach k in [0:NEVOPARAMS-1] { + if (k <= j) { + rj[k] = rejection[i][k]; // Was either set from previous j or just set for this j + } + else { + rj[k] = rejection[i-1][k]; // Not yet set, use previous + } + } + tracef("multi_annealing: [%i][%i] Rejection counts: %f %f %f %f %f\n\n", + i, j, rj[0], rj[1], rj[2], rj[3], rj[4]); + tracef("multi_annealing: %i ***** Did accept! %f %f %f %f %f\n\n", + i, try_x[0], try_x[1], try_x[2], try_x[3], try_x[4]); + } + } + else {// Fixed Vars + x[i][j] = x[i-1][j]; + rejection[i][j] = rejection[i-1][j]; + curr_result[curr] = curr_result[prev]; + // dx[i][j] not set for fixed vars + } + } until( j == (NEVOPARAMS-iterate_adjust) ); + }} // of if/else + } until( iter_i == (annealing_cycles-iterate_adjust) ); +} + +(Res r) N_objective(float x[], int obj_runs) +{ + tracef("%q\n", x); + float result[]; + + tracef( "N_objective: entered: obj_runs=%i x=%q\n", obj_runs, x ); + + foreach i in [1:obj_runs] { // repeats of the objective() - same as n_reruns + result[i] = objective(x); + } + + r.result = avg(result); + tracef("multi_loss: returning: r.result=%f\n", r.result); +} + +optimizer_serial_sweep() // Implements logic of python driver script +{ + + int minrange = @toint(@arg("minrange", "58")); + int maxrange = @toint(@arg("maxrange", "59")); + int rangeinc = @toint(@arg("rangeinc", "50")); + + // FIXME: add provision for random priming and random param values when x[i] == -100 (see optimizer.cpp main()) + + int nreps = @toint(@arg("nreps", "1")); + +//file bestfile ; +//file maxfile ; + +# foreach target_innov in [minrange:maxrange:rangeinc] { +# iterate i { +# int target_innov = minrange + (i*rangeinc); + foreach rep in [1:nreps] { + + string best_filename = @strcat( "best.R", @strcat(rep), ".txt" ); + file outfile; // ; + file lossfile; // ; + + (outfile,lossfile) = multi_annealing(best_filename, + @tofloat(@arg("tstart", "2.0")), + @tofloat(@arg("tend", "0.01")), + @tofloat(@arg("trejection", "0.3")), + @toint(@arg("evoreruns", "100")), + @tofloat(@arg("startingjump", "2.3")), + [ @tofloat(@arg("alphai", "0.0")), + @tofloat(@arg("alpham", "0.0")), + @tofloat(@arg("beta", "4.0")), + @tofloat(@arg("gamma", "50.0")), + @tofloat(@arg("delta", "-1.0")) + ], + @toint(@arg("annealingcycles", "50")) ); + } + # } until(target_innov >= (maxrange-rangeinc)); +} + +optimizer_sweep() // Implements logic of python driver script +{ + + int minrange = @toint(@arg("minrange", "58")); + int maxrange = @toint(@arg("maxrange", "59")); + int rangeinc = @toint(@arg("rangeinc", "50")); + + // FIXME: add provision for random priming and random param values when x[i] == -100 (see optimizer.cpp main()) + + int nreps = @toint(@arg("nreps", "1")); + +//file bestfile ; +//file maxfile ; + +# foreach target_innov in [minrange:maxrange:rangeinc] { + foreach rep in [1:nreps] { + + string best_filename = @strcat( "best.R", @strcat(rep), ".txt" ); + file outfile; // ; + file lossfile; // ; + + (outfile,lossfile) = multi_annealing(best_filename, + @tofloat(@arg("tstart", "2.0")), + @tofloat(@arg("tend", "0.01")), + @tofloat(@arg("trejection", "0.3")), + @toint(@arg("evoreruns", "100")), + @tofloat(@arg("startingjump", "2.3")), + [ @tofloat(@arg("alphai", "0.0")), + @tofloat(@arg("alpham", "0.0")), + @tofloat(@arg("beta", "4.0")), + @tofloat(@arg("gamma", "50.0")), + @tofloat(@arg("delta", "-1.0")) + ], + @toint(@arg("annealingcycles", "50")) ); + } +# } +} + +main() +{ + # optimizer_sweep(); + + float a[][]; + a[0] = [1.1,1.2,1.3,1.4]; + float y[]; + y[0] = objective(a[0]); + + iterate c { + float na[] = [ newx(a[0],0.5), newx(a[1],0.5), newx(a[2],0.5), newx(a[3],0.5) ]; + float ny = objective(na); + trace(c,ny); + } until (c==10); + +} + +main(); From wilde at ci.uchicago.edu Fri Apr 11 16:48:01 2014 From: wilde at ci.uchicago.edu (wilde at ci.uchicago.edu) Date: Fri, 11 Apr 2014 16:48:01 -0500 (CDT) Subject: [Swift-commit] r7765 - SwiftApps/SimulatedAnnealing Message-ID: <20140411214801.B96CC9CF85@svn.ci.uchicago.edu> Author: wilde Date: 2014-04-11 16:48:01 -0500 (Fri, 11 Apr 2014) New Revision: 7765 Modified: SwiftApps/SimulatedAnnealing/sa.swift Log: sa edit Modified: SwiftApps/SimulatedAnnealing/sa.swift =================================================================== --- SwiftApps/SimulatedAnnealing/sa.swift 2014-04-11 21:43:06 UTC (rev 7764) +++ SwiftApps/SimulatedAnnealing/sa.swift 2014-04-11 21:48:01 UTC (rev 7765) @@ -378,9 +378,10 @@ y[0] = objective(a[0]); iterate c { - float na[] = [ newx(a[0],0.5), newx(a[1],0.5), newx(a[2],0.5), newx(a[3],0.5) ]; - float ny = objective(na); - trace(c,ny); + int cy = c + 1; + float na[] = [ newx(a[0][0],0.5), newx(a[0][1],0.5), newx(a[0][2],0.5), newx(a[0][3],0.5) ]; + y[cy] = objective(na); + trace(c,y[c]); } until (c==10); } From wilde at ci.uchicago.edu Fri Apr 11 16:49:14 2014 From: wilde at ci.uchicago.edu (wilde at ci.uchicago.edu) Date: Fri, 11 Apr 2014 16:49:14 -0500 (CDT) Subject: [Swift-commit] r7766 - SwiftApps/SimulatedAnnealing Message-ID: <20140411214914.150839CF85@svn.ci.uchicago.edu> Author: wilde Date: 2014-04-11 16:49:13 -0500 (Fri, 11 Apr 2014) New Revision: 7766 Modified: SwiftApps/SimulatedAnnealing/sa.swift Log: sa edit Modified: SwiftApps/SimulatedAnnealing/sa.swift =================================================================== --- SwiftApps/SimulatedAnnealing/sa.swift 2014-04-11 21:48:01 UTC (rev 7765) +++ SwiftApps/SimulatedAnnealing/sa.swift 2014-04-11 21:49:13 UTC (rev 7766) @@ -379,8 +379,8 @@ iterate c { int cy = c + 1; - float na[] = [ newx(a[0][0],0.5), newx(a[0][1],0.5), newx(a[0][2],0.5), newx(a[0][3],0.5) ]; - y[cy] = objective(na); + a[cy] = [ newx(a[0][0],0.5), newx(a[0][1],0.5), newx(a[0][2],0.5), newx(a[0][3],0.5) ]; + y[cy] = objective(a[cy]); trace(c,y[c]); } until (c==10); From hategan at ci.uchicago.edu Sat Apr 12 16:33:33 2014 From: hategan at ci.uchicago.edu (hategan at ci.uchicago.edu) Date: Sat, 12 Apr 2014 16:33:33 -0500 (CDT) Subject: [Swift-commit] r7767 - trunk/src/org/griphyn/vdl/engine Message-ID: <20140412213333.CF2C99D65C@svn.ci.uchicago.edu> Author: hategan Date: 2014-04-12 16:33:33 -0500 (Sat, 12 Apr 2014) New Revision: 7767 Modified: trunk/src/org/griphyn/vdl/engine/Karajan.java Log: escape open curly bracket in strings (bug 1237) Modified: trunk/src/org/griphyn/vdl/engine/Karajan.java =================================================================== --- trunk/src/org/griphyn/vdl/engine/Karajan.java 2014-04-11 21:49:13 UTC (rev 7766) +++ trunk/src/org/griphyn/vdl/engine/Karajan.java 2014-04-12 21:33:33 UTC (rev 7767) @@ -1987,7 +1987,9 @@ case '"': sb.append("\\\""); break; - + case '{': + sb.append("\\{"); + break; default: sb.append(c); } From swift at ci.uchicago.edu Sat Apr 12 16:40:04 2014 From: swift at ci.uchicago.edu (swift at ci.uchicago.edu) Date: Sat, 12 Apr 2014 16:40:04 -0500 (CDT) Subject: [Swift-commit] cog r3891 Message-ID: <20140412214004.DDF4D8D000A6@bridled.ci.uchicago.edu> ------------------------------------------------------------------------ r3891 | hategan | 2014-04-12 16:39:49 -0500 (Sat, 12 Apr 2014) | 1 line don't enable stream compression by default (bug 1233) ------------------------------------------------------------------------ Index: modules/provider-coaster/src/org/globus/cog/coaster/channels/GSSChannel.java =================================================================== --- modules/provider-coaster/src/org/globus/cog/coaster/channels/GSSChannel.java (revision 3890) +++ modules/provider-coaster/src/org/globus/cog/coaster/channels/GSSChannel.java (working copy) @@ -37,6 +37,12 @@ public class GSSChannel extends AbstractTCPChannel { private static final Logger logger = Logger.getLogger(GSSChannel.class); + private static final boolean streamCompression; + + static { + streamCompression = "true".equals(System.getProperty("gss.channel.compression.enabled")); + } + private GssSocket socket; private String peerId; private boolean shuttingDown; @@ -161,12 +167,22 @@ @Override protected void setInputStream(InputStream inputStream) { - super.setInputStream(new InflaterInputStream(inputStream)); + if (streamCompression) { + super.setInputStream(new InflaterInputStream(inputStream)); + } + else { + super.setInputStream(inputStream); + } } @Override protected void setOutputStream(OutputStream outputStream) { - super.setOutputStream(new DeflaterOutputStream(outputStream, true)); + if (streamCompression) { + super.setOutputStream(new DeflaterOutputStream(outputStream, true)); + } + else { + super.setOutputStream(outputStream); + } } protected void register() { From hategan at ci.uchicago.edu Tue Apr 15 04:17:21 2014 From: hategan at ci.uchicago.edu (hategan at ci.uchicago.edu) Date: Tue, 15 Apr 2014 04:17:21 -0500 (CDT) Subject: [Swift-commit] r7768 - in trunk: resources src/org/griphyn/vdl/engine Message-ID: <20140415091721.E1DB49D537@svn.ci.uchicago.edu> Author: hategan Date: 2014-04-15 04:17:17 -0500 (Tue, 15 Apr 2014) New Revision: 7768 Modified: trunk/resources/swiftscript.g trunk/src/org/griphyn/vdl/engine/Karajan.java Log: fixed wrong procedure call prediction in parser and deal with the issue in the compiler (bug 1239) Modified: trunk/resources/swiftscript.g =================================================================== --- trunk/resources/swiftscript.g 2014-04-12 21:33:33 UTC (rev 7767) +++ trunk/resources/swiftscript.g 2014-04-15 09:17:17 UTC (rev 7768) @@ -653,36 +653,19 @@ : id=identifier ASSIGN - ( - (predictProcedurecallAssign) => code=procedurecallCode - { StringTemplate o = template("returnParam"); - o.setAttribute("name",id); - code.setAttribute("outputs",o); - } - | - code=variableAssign - { - code.setAttribute("lhs",id); - } - ) - ; + code=variableAssign { + code.setAttribute("lhs",id); + } +; appendStat returns [ StringTemplate code = null ] { StringTemplate id=null; } : id=identifier APPEND - ( - (predictProcedurecallAssign) => code=procedurecallCode { - StringTemplate o = template("returnParam"); - o.setAttribute("name",id); - code.setAttribute("outputs",o); - } - | - code=arrayAppend { - code.setAttribute("array", id); - } - ) + code=arrayAppend { + code.setAttribute("array", id); + } ; arrayAppend returns [ StringTemplate code = null ] @@ -705,9 +688,6 @@ } ; -predictProcedurecallAssign - : ID LPAREN ; - procedurecallCode returns [StringTemplate code=template("call")] {StringTemplate f=null;} : Modified: trunk/src/org/griphyn/vdl/engine/Karajan.java =================================================================== --- trunk/src/org/griphyn/vdl/engine/Karajan.java 2014-04-12 21:33:33 UTC (rev 7767) +++ trunk/src/org/griphyn/vdl/engine/Karajan.java 2014-04-15 09:17:17 UTC (rev 7768) @@ -597,47 +597,67 @@ public void assign(Assign assign, VariableScope scope) throws CompilationException { try { - StringTemplate assignST = template("assign"); - StringTemplate varST = expressionToKarajan(assign.getAbstractExpressionArray(0), scope, true); - String lValueType = datatype(varST); - - StringTemplate valueST = expressionToKarajan(assign.getAbstractExpressionArray(1), scope, false, lValueType); - - String rValueType = datatype(valueST); - - if (isAnyType(lValueType)) { - if (isAnyType(rValueType)) { - // any <- any - } - else { - // any <- someType, so infer lValueType as rValueType - setDatatype(varST, rValueType); - } - } - else { - if (isAnyType(rValueType)) { - // someType <- any - // only expressions that are allowed to return 'any' are procedures - // for example readData(ret, file). These are special procedures that - // need to look at the return type at run-time. - } - else if (!lValueType.equals(rValueType)){ - throw new CompilationException("You cannot assign value of type " + rValueType + - " to a variable of type " + lValueType); - } - } - - assignST.setAttribute("var", varST); - assignST.setAttribute("value", valueST); - assignST.setAttribute("line", getLine(assign)); - String rootvar = abstractExpressionToRootVariable(assign.getAbstractExpressionArray(0)); - scope.addWriter(rootvar, getRootVariableWriteType(assign.getAbstractExpressionArray(0)), assign, assignST); - scope.appendStatement(assignST); + XmlObject value = assign.getAbstractExpressionArray(1); + if (isCall(value)) { + Call call = (Call) value; + ActualParameter out = call.addNewOutput(); + XmlObject src = assign.getAbstractExpressionArray(0); + out.getDomNode().appendChild(src.getDomNode()); + call(call, scope, false); + } + else { + StringTemplate assignST = template("assign"); + StringTemplate varST = expressionToKarajan(assign.getAbstractExpressionArray(0), scope, true); + String lValueType = datatype(varST); + + + StringTemplate valueST = expressionToKarajan(assign.getAbstractExpressionArray(1), scope, false, lValueType); + + String rValueType = datatype(valueST); + + if (isAnyType(lValueType)) { + if (isAnyType(rValueType)) { + // any <- any + } + else { + // any <- someType, so infer lValueType as rValueType + setDatatype(varST, rValueType); + } + } + else { + if (isAnyType(rValueType)) { + // someType <- any + // only expressions that are allowed to return 'any' are procedures + // for example readData(ret, file). These are special procedures that + // need to look at the return type at run-time. + } + else if (!lValueType.equals(rValueType)){ + throw new CompilationException("You cannot assign value of type " + rValueType + + " to a variable of type " + lValueType); + } + } + + assignST.setAttribute("var", varST); + assignST.setAttribute("value", valueST); + assignST.setAttribute("line", getLine(assign)); + String rootvar = abstractExpressionToRootVariable(assign.getAbstractExpressionArray(0)); + scope.addWriter(rootvar, getRootVariableWriteType(assign.getAbstractExpressionArray(0)), assign, assignST); + scope.appendStatement(assignST); + } } catch(CompilationException re) { throw new CompilationException("Compile error in assignment at "+assign.getSrc()+": "+re.getMessage(),re); } } + private boolean isCall(XmlObject value) { + Node expressionDOM = value.getDomNode(); + String namespaceURI = expressionDOM.getNamespaceURI(); + String localName = expressionDOM.getLocalName(); + QName expressionQName = new QName(namespaceURI, localName); + return expressionQName.equals(CALL_EXPR); + } + + private boolean isAnyType(String type) { return ProcedureSignature.ANY.equals(type); } From davidk at ci.uchicago.edu Wed Apr 16 12:51:49 2014 From: davidk at ci.uchicago.edu (davidk at ci.uchicago.edu) Date: Wed, 16 Apr 2014 12:51:49 -0500 (CDT) Subject: [Swift-commit] r7769 - trunk/docs/userguide Message-ID: <20140416175149.D86419CFED@svn.ci.uchicago.edu> Author: davidk Date: 2014-04-16 12:51:49 -0500 (Wed, 16 Apr 2014) New Revision: 7769 Modified: trunk/docs/userguide/configuration Log: Add documentation for ticker properties Modified: trunk/docs/userguide/configuration =================================================================== --- trunk/docs/userguide/configuration 2014-04-15 09:17:17 UTC (rev 7768) +++ trunk/docs/userguide/configuration 2014-04-16 17:51:49 UTC (rev 7769) @@ -479,12 +479,25 @@ concurrent transfers can cause the network to be overloaded preventing various other signaling traffic from flowing properly. +|ticker.date.format +|String +| +|Describes how to format the ticker date output. The format of this string + is documented in the Java SimpleDateFormat class, at + http://docs.oracle.com/javase/6/docs/api/java/text/SimpleDateFormat.html + |ticker.disable |true, false |false |When set to true, suppresses the output progress ticker that Swift sends to the console every few seconds during a run +|ticker.prefix +|String +|Progress: +|String to prepend to ticker output + + |use.wrapper.staging |true, false |false @@ -543,4 +556,3 @@ ----- workdir=$RUNDIRECTORY ----- - From davidk at ci.uchicago.edu Wed Apr 16 16:07:52 2014 From: davidk at ci.uchicago.edu (davidk at ci.uchicago.edu) Date: Wed, 16 Apr 2014 16:07:52 -0500 (CDT) Subject: [Swift-commit] r7770 - in SwiftApps/tryswift: . css Message-ID: <20140416210752.097B39CFED@svn.ci.uchicago.edu> Author: davidk Date: 2014-04-16 16:07:51 -0500 (Wed, 16 Apr 2014) New Revision: 7770 Modified: SwiftApps/tryswift/css/tryswift.css SwiftApps/tryswift/getfiles.php SwiftApps/tryswift/index.php SwiftApps/tryswift/tryswift.php Log: Various updates to tryswift - remove twitter bootstrap, layout changes Modified: SwiftApps/tryswift/css/tryswift.css =================================================================== --- SwiftApps/tryswift/css/tryswift.css 2014-04-16 17:51:49 UTC (rev 7769) +++ SwiftApps/tryswift/css/tryswift.css 2014-04-16 21:07:51 UTC (rev 7770) @@ -1,79 +1,44 @@ -#header { - text-align: center; +#body,html { + height: 100%; } -#infoFrame { - width: 100%; - background: white; - overflow-y: scroll; +a { + text-decoration: none } -#editor { - width: 100%; - height: 50%; -} - #scriptNav { - position: relative; - left: 25%; - right: 25%; width: 100%; -} - -#scriptDropdown { - position: relative; - top: 5px; -} - -.b0b0 { - background: #b0b0b0; border: 1px solid black; + float: left; + line-height: 2em; } -#editorContainer { +#editor { + width: 100%; + height: 30%; border: 1px solid black; - border-bottom: 0px; } -#executeButton { - position: relative; - left: 47px; - width: 100px; - font-size: 1.2em; -} - -#resetButton { - position: relative; - left: 44px; - width: 100px; - font-size: 1.2em; -} - #editorButtons { - background: #fbf1d3; + width: 100%; + border: 1px solid black; } -#pre { - background: #fff; - margin: 0; - padding: 0; +#swiftOutputDiv { + width: 100%; + border: 1px solid black; } -#fileOutput { - width: 100%; - overflow-x: hidden; - overflow-y: scroll; - background: #fff; +#example { + float: left; } -#swiftOutput { - overflow-y: scroll; - overflow-x: hidden; - border: 1px solid black; - background: #fff; +#explanation { + float: left; + padding-left: 20px; + top:50% } -#.ace_editor { - line-height: normal; -} - +#outputs { + visibility: hidden; +} Modified: SwiftApps/tryswift/getfiles.php =================================================================== --- SwiftApps/tryswift/getfiles.php 2014-04-16 17:51:49 UTC (rev 7769) +++ SwiftApps/tryswift/getfiles.php 2014-04-16 21:07:51 UTC (rev 7770) @@ -1,5 +1,4 @@ $file [$size bytes]\n"; + # print "
$file [$size bytes]
\n"; + print "\n"; } } ?> Modified: SwiftApps/tryswift/index.php =================================================================== --- SwiftApps/tryswift/index.php 2014-04-16 17:51:49 UTC (rev 7769) +++ SwiftApps/tryswift/index.php 2014-04-16 21:07:51 UTC (rev 7770) @@ -2,58 +2,48 @@ Try Swift - - + -
+
+
+ Example: + +
+
+
+
+ + +
+ + +
- -
-
-
- -
- -
- - -
-
- - -
- -
- - -
-
-
+ +
+ + + +
+ + +
+
 
+     
-
-
-
Swift output
-
-
- -
-
-
Output files
-
-
-
-