batch_experiment 2.0.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -3
- data/examples/ukp_experiment.rb +2 -2
- data/lib/batch_experiment.rb +18 -8
- metadata +2 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e2281f50d62e17b6584f76c6ee3a06b15ad3f95e
|
4
|
+
data.tar.gz: 6e75c67a2776de460de325dff16620cf5e1297b4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 697c5f3cb314baed7e726e03c9627d76c3cb5f47709d666d48169b9f9bb6f79bd4c3f713e10ab738bb35bd312fa5ab9be2cce290da0fc701ccbb2157fb09826a
|
7
|
+
data.tar.gz: de6fa0170a1d52371e9b5799432e9915f9e9256eb76c425a520a27e217e90fa6c0e3d3709212acf3b4b52fc6244a1c6ec9b06eac321e617f42caecf184452e23
|
data/README.md
CHANGED
@@ -15,11 +15,11 @@ What conditions you need to use this tool:
|
|
15
15
|
|
16
16
|
What is not needed:
|
17
17
|
|
18
|
-
* To know how to program in ruby. Only taking less than 5 minutes to learn some basic syntax will suffice to run commands on multiple cores and save the results to files (using BatchExperiment::batch). However, if you want not only to execute the commands but want to extract and group some information from their output to a
|
18
|
+
* To know how to program in ruby. Only taking less than 5 minutes to learn some basic syntax will suffice to run commands on multiple cores and save the results to files (using BatchExperiment::batch). However, if you want not only to execute the commands but want to extract and group some information from their output to a CSV (using BatchExperiment::experiment), you will need to tell ruby how to do the extracting part.
|
19
19
|
|
20
20
|
## How to use it
|
21
21
|
|
22
|
-
You will need to create a ruby script (copy, past and adapt one of the provided examples), give it execution permissions ("chmod +x script.rb"), and execute it ("./script.rb"). It's good to remember that
|
22
|
+
You will need to create a ruby script (copy, past and adapt one of the provided examples), give it execution permissions ("chmod +x script.rb"), and execute it ("./script.rb"). It's good to remember that, if you didn't created a folder for the output files and set the :output_dir configuration to it, the script will probably flood your current folder with the output files. Also, good to remember that, if you didn't set the :cwd configuration, the commands will be called from the folder where you called the script, so they probably will expect that any relative paths/filenames given to them to be relative to the current folder.
|
23
23
|
|
24
24
|
## Examples
|
25
25
|
|
@@ -33,7 +33,7 @@ require 'batch_experiment'
|
|
33
33
|
commands = [
|
34
34
|
'sleep 2 && echo orange',
|
35
35
|
'sleep 4 && echo banana',
|
36
|
-
'sleep 100 && echo "never gonna happen"',
|
36
|
+
'sleep 100 && echo "never gonna happen"', # killed by timeout
|
37
37
|
]
|
38
38
|
|
39
39
|
conf = {
|
data/examples/ukp_experiment.rb
CHANGED
@@ -25,6 +25,8 @@ execution_info = {
|
|
25
25
|
cpus_available: [1, 2, 3],
|
26
26
|
timeout: 10,
|
27
27
|
post_timeout: 2,
|
28
|
+
cwd: '/home/henrique/AreaDeTrabalho/masters/data/ukp/',
|
29
|
+
output_dir: '/home/henrique/AreaDeTrabalho/tmp/',
|
28
30
|
}
|
29
31
|
|
30
32
|
conf = {
|
@@ -36,8 +38,6 @@ conf = {
|
|
36
38
|
files = ['corepb.ukp', 'exnsd18.ukp', 'exnsd26.ukp', 'exnsdbis18.ukp', 'exnsd16.ukp', 'exnsd20.ukp', 'exnsdbis10.ukp', 'exnsds12.ukp']
|
37
39
|
# If you don't execute the script from the ukp files folder you need to put the
|
38
40
|
# folder relative or absolute path here (with trailing slash).
|
39
|
-
path = '~/Aulas/mestrado/masters/data/ukp/'
|
40
|
-
files.map! { | f | path + f }
|
41
41
|
|
42
42
|
BatchExperiment::experiment(comms_info, execution_info, conf, files)
|
43
43
|
|
data/lib/batch_experiment.rb
CHANGED
@@ -136,6 +136,12 @@ module BatchExperiment
|
|
136
136
|
# Default: '.out'.
|
137
137
|
# -- err_ext [String] Extension to be used in place of '.err'.
|
138
138
|
# Default: '.err'.
|
139
|
+
# -- cwd [String] Command Working Directory. The path from where the
|
140
|
+
# commands will be executed. Default: './' (i.e. the same directory from
|
141
|
+
# where the ruby script was run).
|
142
|
+
# -- output_dir [String] The folder used to save the
|
143
|
+
# '.out'/'.err'/'.unfinished' files. Default: './' (i.e. the same directory
|
144
|
+
# from where the ruby script was run).
|
139
145
|
#
|
140
146
|
# @return [String] Which commands were executed. Can be different from
|
141
147
|
# the 'commands' argument if commands are skipped (see :skip_done_comms).
|
@@ -174,6 +180,8 @@ module BatchExperiment
|
|
174
180
|
conf[:post_timeout] ||= 5
|
175
181
|
conf[:converter] ||= BatchExperiment::Comm2FnameConverter.new
|
176
182
|
conf[:skip_done_comms] = true if conf[:skip_done_comms].nil?
|
183
|
+
conf[:cwd] ||= './'
|
184
|
+
conf[:output_dir] ||= './'
|
177
185
|
|
178
186
|
# Initialize main variables
|
179
187
|
free_cpus = conf[:cpus_available].clone
|
@@ -183,9 +191,9 @@ module BatchExperiment
|
|
183
191
|
|
184
192
|
commands.each do | command |
|
185
193
|
commfname = conf[:converter].call(command)
|
186
|
-
out_fname = commfname + conf[:out_ext]
|
187
|
-
err_fname = commfname + conf[:err_ext]
|
188
|
-
lockfname = commfname + conf[:unfinished_ext]
|
194
|
+
out_fname = conf[:output_dir] + commfname + conf[:out_ext]
|
195
|
+
err_fname = conf[:output_dir] + commfname + conf[:err_ext]
|
196
|
+
lockfname = conf[:output_dir] + commfname + conf[:unfinished_ext]
|
189
197
|
|
190
198
|
if conf[:skip_done_comms] && File.exists?(out_fname)
|
191
199
|
if File.exists?(lockfname)
|
@@ -216,10 +224,11 @@ module BatchExperiment
|
|
216
224
|
'sh', '-c', command
|
217
225
|
)
|
218
226
|
|
227
|
+
cproc.cwd = conf[:cwd]
|
228
|
+
|
219
229
|
File.open(lockfname, 'w') {} # empty on purpose
|
220
230
|
out = File.open(out_fname, 'w')
|
221
231
|
err = File.open(err_fname, 'w')
|
222
|
-
|
223
232
|
cproc.io.stdout = out
|
224
233
|
cproc.io.stderr = err
|
225
234
|
|
@@ -398,8 +407,9 @@ module BatchExperiment
|
|
398
407
|
#conf[:skip_commands] defaults to false/nil
|
399
408
|
|
400
409
|
# Get some of the batch config that we use inside here too.
|
401
|
-
out_ext = batch_conf[:out_ext]
|
410
|
+
out_ext = batch_conf[:out_ext] || '.out'
|
402
411
|
unfinished_ext = batch_conf[:unfinished_ext] || '.unfinished'
|
412
|
+
output_dir = batch_conf[:output_dir] || './'
|
403
413
|
converter = batch_conf[:converter].clone unless batch_conf[:converter].nil?
|
404
414
|
converter ||= BatchExperiment::Comm2FnameConverter.new
|
405
415
|
|
@@ -480,14 +490,14 @@ module BatchExperiment
|
|
480
490
|
curr_line = [algorithm, filename, run_number]
|
481
491
|
|
482
492
|
partial_fname = converter.call(exp_comm)
|
483
|
-
out_fname = partial_fname + out_ext
|
484
|
-
lockfname = partial_fname + unfinished_ext
|
493
|
+
out_fname = output_dir + partial_fname + out_ext
|
494
|
+
lockfname = output_dir + partial_fname + unfinished_ext
|
485
495
|
extractor = run_info[:comm_info][:extractor]
|
486
496
|
|
487
497
|
if File.exists?(out_fname)
|
488
498
|
if File.exists?(lockfname)
|
489
499
|
puts "Ignored file '#{out_fname}' because there was a"
|
490
|
-
+ " '#{lockfname}' file
|
500
|
+
+ " '#{lockfname}' file too."
|
491
501
|
else
|
492
502
|
f_content = File.open(out_fname, 'r') { | f | f.read }
|
493
503
|
curr_line << extractor.extract(f_content)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: batch_experiment
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Henrique Becker
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-06-
|
11
|
+
date: 2016-06-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: childprocess
|
@@ -66,4 +66,3 @@ specification_version: 4
|
|
66
66
|
summary: A ruby script that distributes system commands between cpu cores, and save
|
67
67
|
their output.
|
68
68
|
test_files: []
|
69
|
-
has_rdoc:
|