coderunner 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "shoulda", ">= 0"
10
+ gem "rdoc", "~> 3.12"
11
+ gem "bundler", "> 1.0.0"
12
+ gem "jeweler", "~> 1.8.4"
13
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Edmund Highcock
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,4 @@
1
+ coderunner
2
+ ==========
3
+
4
+ CodeRunner is a framework for the automated running and analysis of simulations. It automatically generates any necessary input files, organises the output data and analyses it. Because it is a modular system, it can easily be customised to work with any system and any simulation code.
data/README.rdoc ADDED
@@ -0,0 +1,19 @@
1
+ = coderunner
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to coderunner
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
9
+ * Fork the project.
10
+ * Start a feature/bugfix branch.
11
+ * Commit and push until you are happy with your contribution.
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2012 Edmund Highcock. See LICENSE.txt for
18
+ further details.
19
+
data/Rakefile ADDED
@@ -0,0 +1,54 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "coderunner"
18
+ gem.homepage = "http://coderunner.sourceforge.net"
19
+ gem.license = "GPLv3"
20
+ gem.rubyforge_project = gem.name
21
+ gem.summary = %Q{A framework for the automated running and analysis of simulations.}
22
+ gem.description = %Q{CodeRunner is a framework for the automated running and analysis of simulations. It automatically generates any necessary input files, organises the output data and analyses it. Because it is a modular system, it can easily be customised to work with any system and any simulation code. One of its greatest strengths is that it is independent of any one simulation code; thus it can easily plot and compare the data from different codes.}
23
+ gem.email = "edmundhighcock@sourceforge.net"
24
+ gem.authors = ["Edmund Highcock"]
25
+ # dependencies defined in Gemfile
26
+ end
27
+ Jeweler::RubygemsDotOrgTasks.new
28
+
29
+ require 'rake/testtask'
30
+ Rake::TestTask.new(:test) do |test|
31
+ test.libs << 'lib' << 'test'
32
+ test.pattern = 'test/**/test_*.rb'
33
+ test.verbose = true
34
+ end
35
+
36
+ #require 'rcov/rcovtask'
37
+ #Rcov::RcovTask.new do |test|
38
+ #test.libs << 'test'
39
+ #test.pattern = 'test/**/test_*.rb'
40
+ #test.verbose = true
41
+ #test.rcov_opts << '--exclude "gems/*"'
42
+ #end
43
+
44
+ task :default => :test
45
+
46
+ require 'rdoc/task'
47
+ Rake::RDocTask.new do |rdoc|
48
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
49
+
50
+ rdoc.rdoc_dir = 'rdoc'
51
+ rdoc.title = "coderunner #{version}"
52
+ rdoc.rdoc_files.include('README*')
53
+ rdoc.rdoc_files.include('lib/**/*.rb')
54
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.11.0
data/lib/coderunner.rb ADDED
@@ -0,0 +1,419 @@
1
+
2
+ $stderr.puts "CodeRunner (c) 2009 Edmund Highcock. Loading..." unless $has_put_startup_message_for_code_runner
3
+
4
+ if RUBY_VERSION.to_f < 1.9
5
+ raise "Ruby version 1.9 or greater required (current version is #{RUBY_VERSION})"
6
+ end
7
+
8
+ # Basic class setup
9
+
10
+ class CodeRunner
11
+
12
+ COMMAND_FOLDER = Dir.pwd
13
+ SCRIPT_FOLDER = File.dirname(File.expand_path(__FILE__)) #i.e. where this script is
14
+ if ENV['CODE_RUNNER_OPTIONS']
15
+ GLOBAL_OPTIONS = eval(ENV['CODE_RUNNER_OPTIONS']) # global options are set by the environment but some can be changed.
16
+ else
17
+ GLOBAL_OPTIONS = {}
18
+ end
19
+ SYS = (GLOBAL_OPTIONS[:system] or ENV['CODE_RUNNER_SYSTEM'] or ENV['SYSTEM'] or "generic_linux")
20
+ require SCRIPT_FOLDER + "/system_modules/#{SYS}.rb"
21
+ require SCRIPT_FOLDER + "/box_of_tricks.rb"
22
+ SYSTEM_MODULE = const_get(SYS.variable_to_class_name)
23
+ include SYSTEM_MODULE
24
+ class << self
25
+ include SYSTEM_MODULE
26
+ end
27
+ # begin
28
+ # SYSTEM_MODULE.configure_environment
29
+ # rescue NoMethodError
30
+ # end
31
+ @@sys = SYS
32
+ def gets #No reading from the command line thank you very much!
33
+ $stdin.gets
34
+ end
35
+ def self.gets
36
+ $stdin.gets
37
+ end
38
+
39
+ end
40
+
41
+
42
+
43
+ # CodeRunner::SCRIPT_FOLDER = File.dirname(File.expand_path(__FILE__)) #i.e. where this script is
44
+
45
+ $JCODE = 'U'
46
+
47
+
48
+ #########################################
49
+ # Load Libraries #
50
+ #########################################
51
+
52
+
53
+ $stderr.print 'Loading libraries...' unless $has_put_startup_message_for_code_runner
54
+
55
+ #################################
56
+ #read this if you are puzzled by
57
+ # some non-standard use of ruby
58
+ ################################
59
+ require CodeRunner::SCRIPT_FOLDER + "/box_of_tricks.rb"
60
+ ################################
61
+
62
+ require "getoptlong"
63
+ require "thread"
64
+ require "fileutils"
65
+ require "drb"
66
+ require "test/unit/assertions"
67
+ require CodeRunner::SCRIPT_FOLDER + '/parallelpipes.rb'
68
+ require 'find'
69
+
70
+ begin
71
+ require CodeRunner::SCRIPT_FOLDER + '/../../hostmanager/host_manager.rb'
72
+ rescue LoadError
73
+ eprint 'no hostmanager.'
74
+ end
75
+
76
+ begin
77
+ require "rbgsl"
78
+ require CodeRunner::SCRIPT_FOLDER + "/gsl_tools.rb"
79
+ rescue LoadError
80
+ $stderr.puts "Warning: could not load rbgsl; limited functionality"
81
+ end
82
+
83
+ #require CodeRunner::SCRIPT_FOLDER + "/gnuplot.rb"
84
+ load CodeRunner::SCRIPT_FOLDER + "/graphkit.rb"
85
+ load CodeRunner::SCRIPT_FOLDER + "/graphkit_gnuplot2.rb"
86
+ load CodeRunner::SCRIPT_FOLDER + "/graphkit_vtk_legacy.rb"
87
+ load CodeRunner::SCRIPT_FOLDER + "/graphkit_mathematica.rb"
88
+ CodeRunner::GraphKit = GraphKit # Backwards compatibility
89
+
90
+ # load 'gnuplot'
91
+ load CodeRunner::SCRIPT_FOLDER + "/feedback.rb"
92
+ eprint '.' unless $has_put_startup_message_for_code_runner
93
+ load CodeRunner::SCRIPT_FOLDER + "/test.rb"
94
+ eprint '.' unless $has_put_startup_message_for_code_runner
95
+ load CodeRunner::SCRIPT_FOLDER + "/input_file_generator.rb"
96
+ eprint '.' unless $has_put_startup_message_for_code_runner
97
+ load CodeRunner::SCRIPT_FOLDER + "/long_regexen.rb"
98
+ eprint '.' unless $has_put_startup_message_for_code_runner
99
+ load CodeRunner::SCRIPT_FOLDER + "/version.rb"
100
+ eprint '.' unless $has_put_startup_message_for_code_runner
101
+ load CodeRunner::SCRIPT_FOLDER + "/heuristic_run_methods.rb"
102
+ eprint '.' unless $has_put_startup_message_for_code_runner
103
+ load CodeRunner::SCRIPT_FOLDER + "/code_runner_version.rb"
104
+ eprint '.' unless $has_put_startup_message_for_code_runner
105
+ load CodeRunner::SCRIPT_FOLDER + "/fortran_namelist.rb"
106
+ eprint '.' unless $has_put_startup_message_for_code_runner
107
+
108
+
109
+
110
+ CodeRunner::GLOBAL_BINDING = binding
111
+
112
+
113
+ Log.log_file = nil
114
+
115
+ # $sys = 'macosx' if $sys == 'home'
116
+ # puts $sys; gets
117
+
118
+
119
+ ####################################
120
+ # Commmand line processing #
121
+ ####################################
122
+
123
+
124
+ # Here are all the methods that map the command line invocation into the correct class method call
125
+
126
+ class CodeRunner
127
+
128
+ COMMAND_LINE_FLAGS_WITH_HELP = [
129
+ ["--recalc-all", "-A", GetoptLong::NO_ARGUMENT, %[Causes each directory to be reprocessed, rather than reading the cache of data. Its exact effect depends on the code module being used. By convention it implies that ALL data analysis will be redone.]],
130
+ ["--reprocess-all", "-a", GetoptLong::NO_ARGUMENT, %[Causes each directory to be reprocessed, rather than reading the cache of data. Its exact effect depends on the code module being used. By convention it implies that VERY LITTLE data analysis will be redone.]],
131
+ ["--code", "-C", GetoptLong::REQUIRED_ARGUMENT, %[The code that is being used for simulations in this folder. This string must correspond to a code module supplied to CodeRunner. It usually only needs to be specified once as it will be stored as a default in the folder.]],
132
+ ["--comment", "-c", GetoptLong::REQUIRED_ARGUMENT, %[A comment about the submitted run.]],
133
+ ["--debug", "-d", GetoptLong::NO_ARGUMENT, %[Submit the simulation to the debug queue. This usually only has meaning on HPC systems. It does not mean debug CodeRunner!]],
134
+ ["--defaults-file", "-D", GetoptLong::REQUIRED_ARGUMENT, %[Specify a defaults file to be used when submitting runs. The name should correspond to file named something like '<name>_defaults.rb' in the correct folders within the code module. Every time a different defaults file is specified, a local copy of that defaults file is stored in the root folder. This local copy can be edited and all runs will use the local copy to get defaults. CodeRunner will never overwrite the local copy.]],
135
+ ["--film-options", "-F", GetoptLong::OPTIONAL_ARGUMENT, %[Specify a hash of options when making films. The most important one is fa (frame array). For example -F '{fa: [0, 200]}'. For all possible options see the CodeRunner method make_film_from_lists.]],
136
+ ["--conditions", "-f", GetoptLong::REQUIRED_ARGUMENT, %[A string specifying conditions used to filter runs. This filter is used in a variety of circumstances, for example when printing out the status, plotting graphs etc. Example: '@height == 10 and @width = 2.2 and @status==:Complete'.]],
137
+ ["--run-graph", "-g", GetoptLong::REQUIRED_ARGUMENT, %[Specify a run_graphkit to plot. A run_graphkit is one that is plotted for an individual run. The run graphkits available depend on the code module. The syntax is graphkit shorthand:\n -g '<graph_name>[ ; <graph_options> [ ; <conditions> [ ; <sort> ] ] ]'\n where conditions (i.e. filter) and sort will override the -f and -O flags respectively. The -g flag can be specified multiple times, which will plot multiple graphs on the same page.]],
138
+ ["--graph", "-G", GetoptLong::REQUIRED_ARGUMENT, %[Specify a graphkit to plot. A graphkit combines data for every filtered run. The syntax is graphkit shorthand:\n -G '<axis1>[ : <axis2> [ : <axis3 [ : <axis4> ] ] ] [ ; <graph_options> [ ; <conditions> [ ; <sort> ] ] ]'\n where conditions (i.e. filter) and sort will override the -f and -O flags respectively. <axis1> etc are strings which can be evaluated by the runs. The -G flag can be specified multiple times, which will plot multiple graphs on the same page. For example\n -G 'width : 2*height ; {} ; depth == 2 ; width'\n will plot twice the height against the width for every run where the depth is equal to 2, and will order the data points by width.]],
139
+ ["--heuristic-analysis", "-H", GetoptLong::NO_ARGUMENT, %[Should be specified whenever CodeRunner is being used to analyse simulations which did not originally submit (and which will therefore not have the usual CodeRunner meta data stored with them).] ],
140
+ ["--use-phantom", "-h", GetoptLong::OPTIONAL_ARGUMENT, %[Specify whether to use real or phantom runs]],
141
+ ["--just", "-j", GetoptLong::REQUIRED_ARGUMENT, %[Specify individual run ids. For example -j 45,63,128 is shorthand for -f 'id==45 or id==63 or id==128']],
142
+ ["--job_chain", "-J", GetoptLong::NO_ARGUMENT, %[Chain multiple simulations into one batch/submission job. Most useful for HPC systems.]],
143
+ ["--skip-similar-jobs-off", "-k", GetoptLong::NO_ARGUMENT, %[Normally CodeRunner will not submit a run whose input parameters identical to a previous run (to avoid wasting computer time). Specifying the flag will override that behaviour and force submission of an identical run.]],
144
+ ["--loop", "-l", GetoptLong::NO_ARGUMENT, %[Used with the status command. Keep continually printing out live status information.]],
145
+ ["--multiple-processes", "-M", GetoptLong::REQUIRED_ARGUMENT],
146
+ ["--modlet", "-m", GetoptLong::REQUIRED_ARGUMENT, %[Specify the modlet to be used in the current folder. Only needs to be specified once as it will be stored as a default.]],
147
+ ["--no-run", "-N", GetoptLong::NO_ARGUMENT, %[On some machines getting a list of currently running jobs takes a long time. Specifying this flag tells CodeRunner that you definitely know that no runs in the folder are still queueing or running. Do not specify it if there are still running jobs as it will cause their statuses to be updated incorrectly.]],
148
+ ["--nprocs", "-n", GetoptLong::REQUIRED_ARGUMENT, %[A string specifying the processor layout for the simulation. For example -n 46x4 means use 46 nodes with four processors per node. In the case of a personal computer something like -n 2 is more likely. The default is 1]],
149
+ ["--sort", "-O", GetoptLong::REQUIRED_ARGUMENT, %[Specify the sort order for the runs. Used for a variety of commands, for example status. It is a string of semicolon separated sort keys: for example -O height;width will sort the runs by height and then width.]],
150
+ ["--project", "-P", GetoptLong::REQUIRED_ARGUMENT, %[Specify the project to be used for billing purposes. Only necessary on some systems.]],
151
+ ["--parameters", "-p", GetoptLong::REQUIRED_ARGUMENT, %[A hash of parameters for the simulation. For example -p '{height: 20, width: 2.3}'. These parameters will override the defaults in the local defaults file.]],
152
+ ["--no-auto-create-runner", "-q", GetoptLong::NO_ARGUMENT, %[Used for interactive mode when you don't want CodeRunner to analyse the current directory.]],
153
+ ["--terminal-size", "-t", GetoptLong::REQUIRED_ARGUMENT, %[Specify the terminal size for situations where CodeRunner cannot work it out: -t '[rows, cols]' (square brackets are part of the syntax)]],
154
+ ["--test-submission", "-T", GetoptLong::NO_ARGUMENT, %[Don't actually submit the run, but exit after printing out the run parameters and generating any input files necessary.]],
155
+ ["--use-large-cache-but-recheck-incomplete", "-u", GetoptLong::NO_ARGUMENT, %[Use the large cache for speed, but check any runs whose status is not :Complete or :Failed.]],
156
+ ["--use-large-cache", "-U", GetoptLong::NO_ARGUMENT, %[Use the large cache for speed. No run data will be updated.]],
157
+ ["--version", "-v", GetoptLong::REQUIRED_ARGUMENT, %[Specify the version of the simulation code being used. Only has an effect for certain code modules.]],
158
+ ["--wall-mins", "-W", GetoptLong::REQUIRED_ARGUMENT, %[Specify the wall clock limit in minutes.]],
159
+ ["--write-options", "-w", GetoptLong::REQUIRED_ARGUMENT, %[Use when plotting graphs. A hash of custom options which are applied to the graphkit just before plotting it; for example: -w '{xlabel: 'X Axis Quantity, log_axis: 'y'}']],
160
+ ["--executable", "-X", GetoptLong::REQUIRED_ARGUMENT, %[Specify the location of the executable of the simulation code. It only needs to be specified once in any folder, unless it needs to be changed.]],
161
+ ["--other-folder", "-Y", GetoptLong::REQUIRED_ARGUMENT, %[Run CodeRunner in a different folder. On a local machine 'coderunner st -Y some/other/folder' is identical to 'cd some/other/folder; coderunner st -Y'. However, this flag can also be used for remote folders using RemoteCodeRunner (as long as CodeRunner is installed on the remote machine). e.g. -Y username@machine.location:path/to/folder.]],
162
+ ["--supplementary-options", "-y", GetoptLong::REQUIRED_ARGUMENT],
163
+ ["--server", "-Z", GetoptLong::REQUIRED_ARGUMENT, %[Technical use only]],
164
+ ["--log", "-z", GetoptLong::NO_ARGUMENT, %[Switch logging on (currently not working very well (05/2010)).]] # :nodoc:
165
+ ]
166
+
167
+ CLF = COMMAND_LINE_FLAGS = COMMAND_LINE_FLAGS_WITH_HELP.map{|arr| arr.slice(0..2)}
168
+
169
+ CODE_COMMAND_OPTIONS = (Dir.entries(SCRIPT_FOLDER + "/code_modules/") - [".", "..", ".svn"]).map do |d|
170
+ ["--#{d}-options", "", GetoptLong::REQUIRED_ARGUMENT, %[A hash of options for the #{d} code module]]
171
+ end
172
+
173
+ LONG_COMMAND_LINE_OPTIONS = [
174
+ ["--replace-existing", "", GetoptLong::NO_ARGUMENT, %[Use with resubmit: causes each resubmitted run to replace the run being resubmitted.]],
175
+ ["--smart-resubmit-name", "", GetoptLong::NO_ARGUMENT, %[Use with resubmit: causes each resubmitted run to only contain its original id and changed parameters in its run name.]],
176
+ ] + CODE_COMMAND_OPTIONS
177
+ LONG_COMMAND_LINE_FLAGS = LONG_COMMAND_LINE_OPTIONS.map{|arr| [arr[0], arr[2]]}
178
+
179
+ rihelp = <<EOF
180
+ Documents classes, methods, constants and modules in the usual Ruby form: e.g.
181
+
182
+ * CodeRunner -- a class
183
+ * CodeRunner.status -- a class method
184
+ * CodeRunner#filter -- an instance method
185
+ * CodeRunner::Run -- a sub class
186
+ * CodeRunner::CODE_RUNNER_VERSION --a constant
187
+ EOF
188
+
189
+
190
+ COMMANDS_WITH_HELP = [
191
+ ["available_modlets", "av", 0, 'List the available modlets for the code module.', [], [:C]],
192
+ ["available_defaults_files", "avd", 0, 'List the defaults files for the code module.', [], [:C]],
193
+ ["cancel", "can", 1, 'Cancel the specified job.', ['id'], [:U]],
194
+ ["code_command", "cc", 1, 'Call a class method of the run class. Effectively this will call run_class.class_eval(command). See documentation for whichever code module is in use.', ['command'], []],
195
+ ["continue_in_new_folder", "cnf", 1, 'Make a new folder in the parent directory and copy all coderunner configuration files to that folder. If options j or f are specified, copy all matching runs to that new folder.', ['folder'], [:j, :f, :U, :N]],
196
+ ["code_runner_execute", "crex", 1, 'Run (within the CodeRunner class) the fragment of Ruby code given.', ['Ruby fragment'], []],
197
+ ["delete", "del", 0, 'Permanently erase all filtered runs.', [], [:j, :F, :U, :N]],
198
+ ["directory", "dir", 1, 'Print out the directory for the given run.', ['id'], []],
199
+ ["execute", "ex", 1, 'Run (at the top level) the fragment of Ruby code given.', ['Ruby fragment'], []],
200
+ ['film', "fm", 0, 'Create a film of the specified graphkits.', [], [:F, :G, :g, :U, :N, :j, :f]],
201
+ ["generate_modlet_from_input_file", "gm", 1, 'Deprecated', [], []],
202
+ ["generate_documentation", "rdoc", 1, 'Create automatic documentation using the rdoc tool', [], []],
203
+ ["interactive_mode", "im", 0, 'Launch an interactive terminal. Any command line flags specified set the defaults for the session.', [], [:U, :N, :j, :q]],
204
+ ["load_file", "ld", 1, 'Load a Ruby script file using the CodeRunner framework.', ['script file'], []],
205
+ ['manual', 'man', 0, 'Print out command line manual', [], []],
206
+ ['netcdf_plot', 'ncplot', 3, 'Plot a comma separated list of variables, at a comma separated list of indices (nil for all) from the specified netcdf file against each other using gnuplot.', ['netcdf_file', 'vars', 'indices'], [:w]],
207
+ ["plot_graph", "plot", 0, 'Plot the specified graphkits using Gnuplot', [], [:G, :g, :w, :O, :U, :N, :j, :f]],
208
+ ["parameter_scan", "ps", 1, 'Read a parameter scan from file. For full details of how to write a parameter scan, see online documentation (coderunner.sourceforge.net).', ['scan file'], [:n, :W, :k, :v, :p, :T, :d]],
209
+ ['print_queue_status', 'qstat', 0, 'Show the current status of the queue', [], [:U, :u]],
210
+ ["readout", "ro", 0, 'Print a simple text readout of all data from the runs.', [], []],
211
+ ["reference", "ri", 1, "Print out documentation for the given class or method. #{rihelp}", ['ruby_class_or_method'], []],
212
+ ["resubmit", "resub", 0, 'Resubmit the filtered runs to be simulated. All parameters will be the same bar those altered by the p option.', [], [:p, :n, :W, :k, :v, :T, :d, :J, :f, :j]],
213
+ ["run_command", "rc", 1, 'Cause all filtered runs to evaluate the given string.', ['command string'], [:U, :f, :j, :N]],
214
+ ["runner_eval", "ev", 1, 'Cause the runner (the CodeRunner instance) to evaluate the given string.', ['command string'], [:U, :N, :j, :f]],
215
+ ["scan", "scan", 1, 'Submit a simple scan. For full details of how to write a simple scan, see online documentation (coderunner.sourceforge.net).', ['scan string'], [:p, :n, :W, :k, :v, :T, :d]],
216
+ ["show_values_of", "shvl", 1, 'Evaluate the expression for each run and print a unique sorted list of them.', ['expression'], [:U, :N, :j, :f]],
217
+ ['start_launcher', 'launch', 2, 'Start a simple job launcher for non batch systems.', ['refresh_interval', 'max_queue_size'], []],
218
+ ["status", "st", 0, 'Print out a summary of the status of the filtered runs.', [], [:U, :N, :j, :f, :O]],
219
+ ["status_with_comments", "sc", 0, 'Print a list of ids with their status and any comments.', [], [:U, :N, :j, :f, :O]],
220
+ ["status_loop", "sl", 0, 'Loop, updating the filtered runs, then printing out a summary of the status of the filtered runs. ', [], [:U, :N, :j, :f, :O]],
221
+ ["submit", "sub", 0, 'Submit a run to be simulated.', [], [:p, :n, :W, :k, :v, :T, :d, :J]],
222
+ ["submit_command", "subcom", 2, 'Submit an arbitrary shell command to the batch queue.', ['job name', 'command'], [:n, :W, :v, :T, :d]],
223
+ ["write_graph", "wg", 1, 'Write a graph to disk.', ['filename'], [:G, :g, :w, :O, :U, :N, :j, :f]]
224
+ ]
225
+
226
+ # This lists all the commands available on the command line. The first two items in each array indicate the long and short form of the command, and the third indicates the number of arguments the command takes. They are all implemented as Code Runner class methods (the method is named after the long form). The short form of the command is available as a global method in Code Runner interactive mode.
227
+
228
+ COMMANDS = COMMANDS_WITH_HELP.map{|arr| arr.slice(0..2)}
229
+
230
+ # A lookup hash which gives the appropriate short command option (copt) key for a given long command flag
231
+
232
+ CLF_TO_SHORT_COPTS = COMMAND_LINE_FLAGS.inject({}){ |hash, (long, short, req)|
233
+ letter = short[1,1]
234
+ hash[long] = letter.to_sym
235
+ hash
236
+ }
237
+
238
+ # specifying flag sets a bool to be true
239
+
240
+ CLF_BOOLS = [:H, :U, :u, :A, :a, :T, :N, :q, :z, :d, :J, :replace_existing]
241
+ # CLF_BOOLS = [:s, :r, :D, :H, :U, :u, :L, :l, :A, :a, :T, :N,:V, :q, :z, :d] #
242
+
243
+ CLF_INVERSE_BOOLS = [:k] # specifying flag sets a bool to be false
244
+
245
+ # a look up hash that converts the long form of the command options to the short form (NB command options e.g. use_large_cache have a different form from command line flags e.g. --use-large-cache)
246
+
247
+ LONG_TO_SHORT = COMMAND_LINE_FLAGS.inject({}){ |hash, (long, short, req)|
248
+ letter = short[1,1]
249
+ hash[long[2, long.size].gsub(/\-/, '_').to_sym] = letter.to_sym
250
+ hash
251
+ }
252
+
253
+ # A look up table that converts long only command line options (in LONG_COMMAND_LINE_OPTIONS) to the equivalent CodeRunner command option
254
+
255
+ CLF_TO_LONG = LONG_COMMAND_LINE_OPTIONS.inject({}) do |hash, (long, short, req, help)|
256
+ option = long[2, long.size].gsub(/\-/, '_').to_sym
257
+ hash[long] = option
258
+ hash
259
+ end
260
+
261
+ #Converts a command line flag opt with value arg to a command option which is stored in copts
262
+
263
+ def self.process_command_line_option(opt, arg, copts)
264
+ case opt
265
+ when "--change-directory"
266
+ copts[:c] = arg.to_i
267
+ when "--delete"
268
+ copts[:x] = arg.to_i
269
+ when "--graph"
270
+ copts[:G].push arg
271
+ when "--run-graph"
272
+ copts[:g].push arg
273
+ # when "--cancel"
274
+ # copts[:K] = arg.to_i
275
+ when "--multiple-processes"
276
+ copts[:M] = arg.to_i
277
+ when "--film"
278
+ copts[:F] = (arg or true)
279
+ when "--recheck"
280
+ copts[:R] = arg.to_i
281
+ when "--use-large-cache-but-recheck-incomplete"
282
+ copts[:U] = true
283
+ copts[:u]=true
284
+ when "--wall-mins"
285
+ copts[:W] = arg.to_i
286
+ when "--use-phantom"
287
+ copts[:h] = (arg and arg =~ /\S/) ? arg.to_sym : :phantom
288
+ when "--terminal-size"
289
+ array = eval arg
290
+ ENV['ROWS'], ENV['COLS'] = array[0].to_s, array[1].to_s
291
+ when "--interactive-mode"
292
+ @@interactive_mode = true
293
+ when "--parameters"
294
+ copts[:p].push arg
295
+ else
296
+ if CLF_BOOLS.include? CLF_TO_SHORT_COPTS[opt]
297
+ copts[CLF_TO_SHORT_COPTS[opt]] = true
298
+ elsif CLF_INVERSE_BOOLS.include? CLF_TO_SHORT_COPTS[opt]
299
+ copts[CLF_TO_SHORT_COPTS[opt]] = false
300
+ elsif CLF_TO_SHORT_COPTS[opt] # Applies to most options
301
+ copts[CLF_TO_SHORT_COPTS[opt]] = arg
302
+ elsif CLF_BOOLS.include? CLF_TO_LONG[opt]
303
+ copts[CLF_TO_LONG[opt]] = true
304
+ elsif CLF_INVERSE_BOOLS.include? CLF_TO_LONG[opt]
305
+ copts[CLF_TO_LONG[opt]] = false
306
+ elsif CODE_COMMAND_OPTIONS.map{|o| o[0]}.include? opt
307
+ begin
308
+ #copts[:code_copts] ||= {}
309
+ copts[
310
+ #CLF_TO_LONG[opt].to_s.sub('_options','').to_sym
311
+ CLF_TO_LONG[opt]
312
+ ] = eval(arg)
313
+ rescue SyntaxError => err
314
+ eputs "\nOption #{opt} must be a hash\n\n"
315
+ raise err
316
+ end
317
+
318
+ elsif CLF_TO_LONG[opt]
319
+ copts[CLF_TO_LONG[opt]] = arg
320
+ else
321
+ raise "Unknown command line argument: #{opt}"
322
+ end
323
+ end
324
+ copts
325
+ end
326
+
327
+ # Default command options; they are usually determined by the command line flags, but can be set independently
328
+
329
+ DEFAULT_COMMAND_OPTIONS = {}
330
+
331
+ def self.set_default_command_options_from_command_line
332
+
333
+ #some defaults
334
+ # DEFAULT_COMMAND_OPTIONS[:p] ||= {}
335
+ DEFAULT_COMMAND_OPTIONS[:v] ||= ""
336
+ #DEFAULT_COMMAND_OPTIONS[:n] ||= "1"
337
+ DEFAULT_COMMAND_OPTIONS[:G] = []
338
+ DEFAULT_COMMAND_OPTIONS[:g] = []
339
+ DEFAULT_COMMAND_OPTIONS[:k] = true
340
+ DEFAULT_COMMAND_OPTIONS[:h] ||= :real
341
+ DEFAULT_COMMAND_OPTIONS[:p] = []
342
+
343
+ # ep COMMAND_LINE_FLAGS
344
+ opts = GetoptLong.new(*(COMMAND_LINE_FLAGS + LONG_COMMAND_LINE_FLAGS))
345
+ opts.each do |opt, arg|
346
+ process_command_line_option(opt, arg, DEFAULT_COMMAND_OPTIONS)
347
+ end
348
+ #raise "\n\nCannot use large cache ('-U' or '-u' ) if submitting runs" if DEFAULT_COMMAND_OPTIONS[:U] and (DEFAULT_COMMAND_OPTIONS[:s] or DEFAULT_COMMAND_OPTIONS[:P])
349
+
350
+
351
+ if DEFAULT_COMMAND_OPTIONS[:z]
352
+ Log.log_file = Dir.pwd + '/.cr_logfile.txt'
353
+ Log.clean_up
354
+ else
355
+ Log.log_file = nil
356
+ # puts Log.log_file
357
+ end
358
+ end
359
+
360
+ def self.run_script
361
+ if DEFAULT_COMMAND_OPTIONS[:Z]
362
+ DEFAULT_COMMAND_OPTIONS.absorb(eval(DEFAULT_COMMAND_OPTIONS[:Z]))
363
+ puts "Begin Output"
364
+ end
365
+ command = COMMANDS.find{|com| com.slice(0..1).include? ARGV[0]}
366
+ raise "\n-------------------\nCommand #{ARGV[0].inspect} not found: try 'coderunner man' for help\n-------------------\n" unless command
367
+ send(command[0].to_sym, *ARGV.values_at(*(1...(1+command[2])).to_a))
368
+ end
369
+
370
+
371
+ end
372
+
373
+
374
+ load CodeRunner::SCRIPT_FOLDER + "/class_methods.rb"
375
+ load CodeRunner::SCRIPT_FOLDER + "/instance_methods.rb"
376
+ load CodeRunner::SCRIPT_FOLDER + "/interactive_methods.rb"
377
+ $stderr.puts unless $has_put_startup_message_for_code_runner
378
+ $has_put_startup_message_for_code_runner = true
379
+
380
+
381
+ CodeRunner.set_default_command_options_from_command_line
382
+
383
+ do_profile = (ENV['CODE_RUNNER_PROFILE'] and ENV['CODE_RUNNER_PROFILE'].size > 0) ? ENV['CODE_RUNNER_PROFILE'] : false
384
+
385
+
386
+
387
+
388
+ if do_profile
389
+ begin
390
+ require 'ruby-prof'
391
+ rescue LoadError
392
+ eputs "Please install ruby-prof using ' $ gem install ruby-prof'"
393
+ exit
394
+ end
395
+
396
+ # Profile the code
397
+ RubyProf.start
398
+ end
399
+ ####################
400
+ CodeRunner.run_script if $0 == __FILE__
401
+ ###################
402
+
403
+ if do_profile
404
+ result = RubyProf.stop
405
+
406
+ # Print a flat profile to text
407
+ case ENV['CODE_RUNNER_PROFILE']
408
+ when /html/i
409
+ printer = RubyProf::GraphHtmlPrinter.new(result)
410
+ when /graph/i
411
+ printer = RubyProf::GraphPrinter.new(result)
412
+ when /txt/i
413
+ printer = RubyProf::FlatPrinter.new(result)
414
+ else
415
+ raise "CODE_RUNNER_PROFILE should be 'html', 'graph' or 'txt'"
416
+ end
417
+
418
+ printer.print($stdout, {})
419
+ end