rbbt-util 5.32.7 → 5.32.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/bin/rbbt +1 -0
  3. data/lib/rbbt/hpc/batch.rb +23 -7
  4. data/lib/rbbt/hpc/slurm.rb +29 -10
  5. data/lib/rbbt/persist/tsv/adapter.rb +1 -5
  6. data/lib/rbbt/resource.rb +22 -9
  7. data/lib/rbbt/tsv/csv.rb +2 -2
  8. data/lib/rbbt/tsv/manipulate.rb +2 -0
  9. data/lib/rbbt/util/R.rb +2 -2
  10. data/lib/rbbt/util/cmd.rb +39 -18
  11. data/lib/rbbt/util/log/progress/report.rb +20 -17
  12. data/lib/rbbt/util/python.rb +24 -3
  13. data/lib/rbbt/util/simpleDSL.rb +4 -4
  14. data/lib/rbbt/workflow.rb +20 -2
  15. data/lib/rbbt/workflow/step.rb +37 -6
  16. data/lib/rbbt/workflow/step/accessor.rb +2 -2
  17. data/lib/rbbt/workflow/util/data.rb +31 -0
  18. data/lib/rbbt/workflow/util/trace.rb +2 -1
  19. data/python/rbbt.py +3 -0
  20. data/share/install/software/lib/install_helpers +1 -1
  21. data/share/rbbt_commands/hpc/list +11 -7
  22. data/share/rbbt_commands/hpc/orchestrate +6 -1
  23. data/share/rbbt_commands/hpc/task +6 -1
  24. data/share/rbbt_commands/lsf/clean +212 -0
  25. data/share/rbbt_commands/lsf/list +315 -0
  26. data/share/rbbt_commands/lsf/orchestrate +61 -0
  27. data/share/rbbt_commands/lsf/tail +55 -0
  28. data/share/rbbt_commands/lsf/task +60 -0
  29. data/share/rbbt_commands/slurm/clean +212 -0
  30. data/share/rbbt_commands/slurm/list +315 -0
  31. data/share/rbbt_commands/slurm/orchestrate +61 -0
  32. data/share/rbbt_commands/slurm/tail +55 -0
  33. data/share/rbbt_commands/slurm/task +60 -0
  34. data/share/rbbt_commands/workflow/forget_deps +5 -4
  35. data/test/rbbt/util/test_python.rb +3 -2
  36. data/test/rbbt/util/test_simpleDSL.rb +3 -3
  37. data/test/rbbt/workflow/util/test_data.rb +35 -0
  38. metadata +97 -84
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b989d145b1a34baab93f351ea9944e73dde157e9973a9443717b84a43e7b41d5
4
- data.tar.gz: d6e8f5a7e8cb2d2f0e9a99f36a7594e4fc3655dd1d4f9b571f73f0f947b19fd3
3
+ metadata.gz: 4c61ee9aa98e617b2cd43ea3c57b71439cbb5c2c65282ed7695fafd5c46ccbf3
4
+ data.tar.gz: e30e12b162f86ee74b4a4c33e44c7e976612a11e8219b2afd9c6cc0ea520fe24
5
5
  SHA512:
6
- metadata.gz: da60531d5e35efd54b0c4de7e9ad6b034ef05e8d58d6a6b0a1b15422b324dd6eb5a4cb01b21ba60c091616d512106c278ef794088f87f844bd96e86d8f61d7da
7
- data.tar.gz: 2327575017d9dbb301b8c0ba36ee691bc8be00175712e2121da019251c3735d0348cae6d18e8112b00c952e233eb806a19f2275563310360ed745a9b868a6021
6
+ metadata.gz: abee1a9322982a9da1cca62f7c36e47a7517a6c8066177f5155f8bfc17e6bc19054bfc1b8068c67e58fb0bf4a1c7585c3d493c2ca70d600391348e03f61ebab6
7
+ data.tar.gz: 80e3f811802c5e33cefd1c7c9561a9bdfcc2cfbfa97f300babd3c095de1d5bfb14a88e2e52918c4be9e869f9bf2722df68a493895077101e42b2f4ee57e9427c
data/bin/rbbt CHANGED
@@ -102,6 +102,7 @@ end
102
102
 
103
103
  if options[:config_keys]
104
104
  options[:config_keys].split(",").each do |config|
105
+ config = config.strip
105
106
  Rbbt::Config.process_config config
106
107
  end
107
108
  end
@@ -95,14 +95,15 @@ module HPC
95
95
 
96
96
  task = Symbol === job.overriden ? job.overriden : job.task_name
97
97
 
98
- if job.overriden
99
- override_deps = job.rec_dependencies.
100
- select{|dep| Symbol === dep.overriden }.
98
+ if job.overriden?
99
+ #override_deps = job.rec_dependencies.
100
+ # select{|dep| Symbol === dep.overriden }.
101
+
102
+ override_deps = job.overriden_deps.
101
103
  collect do |dep|
102
-
103
104
  name = [dep.workflow.to_s, dep.task_name] * "#"
104
105
  [name, dep.path] * "="
105
- end * ","
106
+ end.uniq * ","
106
107
 
107
108
  options[:override_deps] = override_deps unless override_deps.empty?
108
109
  end
@@ -156,10 +157,15 @@ EOF
156
157
  :singularity_ruby_inline,
157
158
  :sync,
158
159
  :task_cpus,
160
+ :mem,
161
+ :mem_per_cpu,
162
+ :licenses,
163
+ :contraints,
159
164
  :time,
160
165
  :user_group,
161
166
  :wipe_container,
162
167
  :workdir,
168
+ :purge_deps
163
169
  ]
164
170
 
165
171
  keys.each do |key|
@@ -378,9 +384,9 @@ echo "user_scratch: #{scratch_group_dir}/#{user}/{PKGDIR}/{TOPLEVEL}/{SUBPATH}"
378
384
  end
379
385
 
380
386
  def execute(options)
381
- exec_cmd, job_cmd = options.values_at :exec_cmd, :rbbt_cmd
387
+ exec_cmd, job_cmd, task_cpus = options.values_at :exec_cmd, :rbbt_cmd, :task_cpus
382
388
 
383
- <<-EOF
389
+ script=<<-EOF
384
390
  step_path=$(
385
391
  #{exec_cmd} #{job_cmd} --printpath
386
392
  )
@@ -388,7 +394,10 @@ exit_status=$?
388
394
 
389
395
  [[ -z $BATCH_JOB_ID ]] || #{exec_cmd} workflow write_info --recursive --force=false --check_pid "$step_path" batch_job $BATCH_JOB_ID
390
396
  [[ -z $BATCH_SYSTEM ]] || #{exec_cmd} workflow write_info --recursive --force=false --check_pid "$step_path" batch_system $BATCH_SYSTEM
397
+ #{exec_cmd} workflow write_info --recursive --force=false --check_pid "$step_path" batch_cpus #{task_cpus}
391
398
  EOF
399
+
400
+ script
392
401
  end
393
402
 
394
403
  def sync_environment(options = {})
@@ -409,6 +418,13 @@ fi
409
418
 
410
419
  def cleanup_environment(options = {})
411
420
  cleanup_environment = ""
421
+
422
+ cleanup_environment +=<<-EOF if options[:purge_deps]
423
+ if [ $exit_status == '0' ]; then
424
+ #{options[:exec_cmd]} workflow forget_deps --purge --recursive_purge "$step_path" 2>1 >> '#{options[:fsync]}'
425
+ fi
426
+ EOF
427
+
412
428
  if options[:sync]
413
429
  if options[:wipe_container] == 'force'
414
430
  cleanup_environment +=<<-EOF
@@ -28,6 +28,11 @@ export BATCH_SYSTEM=SLURM
28
28
  workdir = Misc.process_options options, :workdir
29
29
  exclusive = Misc.process_options options, :exclusive
30
30
  highmem = Misc.process_options options, :highmem
31
+ licenses = Misc.process_options options, :licenses
32
+ constraint = Misc.process_options options, :constraint
33
+
34
+ mem = Misc.process_options options, :mem
35
+ mem_per_cpu = Misc.process_options options, :mem_per_cpu
31
36
 
32
37
  batch_dir = Misc.process_options options, :batch_dir
33
38
  batch_name = Misc.process_options options, :batch_name
@@ -37,20 +42,34 @@ export BATCH_SYSTEM=SLURM
37
42
 
38
43
  time = Misc.format_seconds Misc.timespan(time) unless time.include? ":"
39
44
 
45
+ sbatch_params = {"job-name" => batch_name,
46
+ "output" => fout,
47
+ "error" => ferr,
48
+ "cpus-per-task" => task_cpus,
49
+ "nodes" => nodes,
50
+ "time" => time,
51
+ "exclusive" => exclusive,
52
+ "licenses" => licenses,
53
+ "mem" => mem,
54
+ "mem-per-cpu" => mem_per_cpu,
55
+ }
56
+
40
57
  header =<<-EOF
41
58
  #!/bin/bash
42
- #SBATCH --job-name="#{batch_name}"
43
- #SBATCH --workdir="#{workdir}"
44
- #SBATCH --output="#{fout}"
45
- #SBATCH --error="#{ferr}"
46
- #SBATCH --qos="#{queue}"
47
- #SBATCH --cpus-per-task="#{task_cpus}"
48
- #SBATCH --time="#{time}"
49
- #SBATCH --nodes="#{nodes}"
50
59
  EOF
51
60
 
52
- header << "#SBATCH --exclusive" << "\n" if exclusive
53
- header << "#SBATCH --constraint=highmem" << "\n" if highmem
61
+ sbatch_params.each do |name,value|
62
+ next if value.nil? || value == ""
63
+ if TrueClass === value
64
+ header << "#SBATCH --#{name}" << "\n"
65
+ elsif Array === value
66
+ value.each do |v|
67
+ header << "#SBATCH --#{name}=\"#{v}\"" << "\n"
68
+ end
69
+ else
70
+ header << "#SBATCH --#{name}=\"#{value}\"" << "\n"
71
+ end
72
+ end
54
73
 
55
74
  header
56
75
  end
@@ -148,11 +148,7 @@ module Persist
148
148
  def write_lock
149
149
  write if closed?
150
150
  if write?
151
- begin
152
- return yield
153
- ensure
154
- close
155
- end
151
+ return yield
156
152
  end
157
153
 
158
154
  lock do
data/lib/rbbt/resource.rb CHANGED
@@ -4,10 +4,10 @@ require 'rbbt/resource/path'
4
4
  require 'net/http'
5
5
  require 'set'
6
6
 
7
-
8
7
  module Resource
9
8
  class ResourceNotFound < RbbtException; end
10
9
 
10
+
11
11
  class << self
12
12
  attr_accessor :lock_dir
13
13
 
@@ -87,12 +87,21 @@ module Resource
87
87
  lock_filename = nil # it seems like this was locked already.
88
88
 
89
89
  Misc.lock lock_filename do
90
- uri = URI(url)
90
+ begin
91
+ uri = URI(url)
92
+
93
+ http = Net::HTTP.new(uri.host, uri.port)
91
94
 
92
- http = Net::HTTP.new(uri.host, uri.port)
93
- request = Net::HTTP::Get.new(uri.request_uri)
94
- timeout = 60 * 10
95
- Net::HTTP.start(uri.host, uri.port, :timeout => timeout, :read_timeout => timeout, :open_timeout => timeout) do |http|
95
+ if uri.scheme == "https"
96
+ http.use_ssl = true
97
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
98
+ http.instance_variable_set("@ssl_options", OpenSSL::SSL::OP_NO_SSLv2 + OpenSSL::SSL::OP_NO_SSLv3 + OpenSSL::SSL::OP_NO_COMPRESSION)
99
+ end
100
+
101
+ timeout = 60 * 10
102
+ http.read_timeout = timeout
103
+ http.open_timeout = timeout
104
+ request = Net::HTTP::Get.new(uri.request_uri)
96
105
  http.request request do |response|
97
106
  filename = if response["Content-Disposition"]
98
107
  response["Content-Disposition"].split(";").select{|f| f.include? "filename"}.collect{|f| f.split("=").last.gsub('"','')}.first
@@ -123,9 +132,11 @@ module Resource
123
132
  FileUtils.mv tmp_dir, final_path
124
133
  end
125
134
  else
126
- Open.open(location, :nocache => true) do |s|
127
- Misc.sensiblewrite(final_path, s)
128
- end
135
+ url = location
136
+ raise TryAgain
137
+ #Open.open(location, :nocache => true) do |s|
138
+ # Misc.sensiblewrite(final_path, s)
139
+ #end
129
140
  end
130
141
  when Net::HTTPInternalServerError
131
142
  @server_missing_resource_cache << url
@@ -134,6 +145,8 @@ module Resource
134
145
  raise "Response not understood: #{response.inspect}"
135
146
  end
136
147
  end
148
+ rescue TryAgain
149
+ retry
137
150
  end
138
151
  end
139
152
  rescue
data/lib/rbbt/tsv/csv.rb CHANGED
@@ -28,10 +28,10 @@ module TSV
28
28
  if Misc.is_filename?(obj)
29
29
  CSV.read obj, options
30
30
  else
31
- CSV.new obj, options
31
+ CSV.new obj, **options
32
32
  end
33
33
  else
34
- CSV.new obj, options
34
+ CSV.new obj, **options
35
35
  end
36
36
 
37
37
  tsv = if noheaders
@@ -174,6 +174,8 @@ module TSV
174
174
  if Hash === @monitor
175
175
  desc = @monitor[:desc] if @monitor.include? :desc
176
176
  step = @monitor[:step] if @monitor.include? :step
177
+ elsif String === @monitor
178
+ desc = @monitor
177
179
  end
178
180
  progress_monitor = Log::ProgressBar.new_bar(size, :desc => desc)
179
181
  end
data/lib/rbbt/util/R.rb CHANGED
@@ -41,7 +41,7 @@ source('#{UTIL}');
41
41
 
42
42
  if monitor
43
43
  #io = CMD.cmd('R --no-save --quiet', options.merge(:in => cmd, :pipe => true, :log => true))
44
- io = CMD.cmd('R --no-save --quiet', options.merge(:in => cmd, :pipe => true, :log => true, :xvfb => true))
44
+ io = CMD.cmd('R --no-save --quiet', options.merge(:in => cmd, :pipe => true, :log => true, :xvfb => options[:xvfb]))
45
45
  while line = io.gets
46
46
  case monitor
47
47
  when Proc
@@ -52,7 +52,7 @@ source('#{UTIL}');
52
52
  end
53
53
  nil
54
54
  else
55
- CMD.cmd('R --no-save --slave --quiet', options.merge(:in => cmd, :xvfb => true))
55
+ CMD.cmd('R --no-save --slave --quiet', options.merge(:in => cmd, :xvfb => options[:xvfb]))
56
56
  end
57
57
  end
58
58
 
data/lib/rbbt/util/cmd.rb CHANGED
@@ -192,25 +192,47 @@ module CMD
192
192
 
193
193
  ConcurrentStream.setup sout, :pids => pids, :autojoin => no_wait, :no_fail => no_fail
194
194
 
195
- err_thread = Thread.new do
196
- while line = serr.gets
197
- bar.process(line) if bar
198
- sout.log = line
199
- Log.log "STDERR [#{pid}]: " + line, stderr
200
- end if Integer === stderr and log
201
- serr.close
195
+ if (Integer === stderr and log) || bar
196
+ err_thread = Thread.new do
197
+ while line = serr.gets
198
+ bar.process(line) if bar
199
+ sout.log = line
200
+ Log.log "STDERR [#{pid}]: " + line, stderr if log
201
+ end
202
+ serr.close
203
+ end
204
+ else
205
+ err_thread = Misc.consume_stream(serr, true)
202
206
  end
203
207
 
204
208
  sout.threads = [in_thread, err_thread, wait_thr].compact
205
209
 
206
210
  sout
207
211
  else
208
- err = ""
209
- err_thread = Thread.new do
210
- while not serr.eof?
211
- err << serr.gets if Integer === stderr
212
+
213
+ if bar
214
+ err = ""
215
+ err_thread = Thread.new do
216
+ while not serr.eof?
217
+ line = serr.gets
218
+ bar.process(line)
219
+ err << line if Integer === stderr and log
220
+ end
221
+ serr.close
212
222
  end
213
- serr.close
223
+ elsif log and Integer === stderr
224
+ err = ""
225
+ err_thread = Thread.new do
226
+ while not serr.eof?
227
+ err << serr.gets
228
+ end
229
+ serr.close
230
+ end
231
+ else
232
+ Misc.consume_stream(serr, true)
233
+ #serr.close
234
+ err_thread = nil
235
+ err = ""
214
236
  end
215
237
 
216
238
  ConcurrentStream.setup sout, :pids => pids, :threads => [in_thread, err_thread].compact, :autojoin => no_wait, :no_fail => no_fail
@@ -220,7 +242,11 @@ module CMD
220
242
 
221
243
  status = wait_thr.value
222
244
  if not status.success? and not no_fail
223
- raise ProcessFailed.new "Command [#{pid}] #{cmd} failed with error status #{status.exitstatus}.\n#{err}"
245
+ if !err.empty?
246
+ raise ProcessFailed.new "Command [#{pid}] #{cmd} failed with error status #{status.exitstatus}.\n#{err}"
247
+ else
248
+ raise ProcessFailed.new "Command [#{pid}] #{cmd} failed with error status #{status.exitstatus}"
249
+ end
224
250
  else
225
251
  Log.log err, stderr if Integer === stderr and log
226
252
  end
@@ -263,11 +289,6 @@ module CMD
263
289
  if c == "\n"
264
290
  bar.process(line) if bar
265
291
  starting = true
266
- #if pid
267
- # Log.logn "STDOUT [#{pid}]: ", level
268
- #else
269
- # Log.logn "STDOUT: ", level
270
- #end
271
292
  line = "" if bar
272
293
  end
273
294
  end
@@ -12,32 +12,35 @@ module Log
12
12
  attr_accessor :history, :mean_max, :max_history
13
13
  def thr_msg
14
14
  if @history.nil?
15
- @history ||= [[@ticks, Time.now] ]
15
+ @history ||= [[0, @start], [@ticks, Time.now] ]
16
16
  elsif @last_ticks != @ticks
17
17
  @history << [@ticks, Time.now]
18
- max_history ||= case
19
- when @ticks > 20
20
- count = @ticks - @last_count
21
- count = 1 if count == 0
22
- if @max
23
- times = @max / count
24
- num = times / 20
25
- num = 2 if num < 2
26
- else
27
- num = 10
18
+ max_history ||= begin
19
+ max_history = case
20
+ when @ticks > 20
21
+ count = @ticks - @last_count
22
+ count = 1 if count == 0
23
+ if @max
24
+ times = @max / count
25
+ num = times / 20
26
+ num = 2 if num < 2
27
+ else
28
+ num = 10
29
+ end
30
+ count * num
31
+ else
32
+ 20
33
+ end
34
+ max_history = 30 if max_history > 30
35
+ max_history
28
36
  end
29
- count * num
30
- else
31
- 20
32
- end
33
- max_history = 30 if max_history > 30
34
37
  @history.shift if @history.length > max_history
35
38
  end
36
39
 
37
40
  @last_ticks = @ticks
38
41
 
39
42
  @mean_max ||= 0
40
- if @history.length > 2
43
+ if @history.length > 3
41
44
 
42
45
  sticks, stime = @history.first
43
46
  ssticks, sstime = @history[-3]
@@ -3,10 +3,17 @@ require 'pycall/import'
3
3
 
4
4
  module RbbtPython
5
5
  extend PyCall::Import
6
+
7
+ def self.exec(script)
8
+ PyCall.exec(script)
9
+ end
10
+
6
11
  def self.run(mod = nil, imports = nil, &block)
7
12
  if mod
8
- if imports
13
+ if Array === imports
9
14
  pyfrom mod, :import => imports
15
+ elsif Hash === imports
16
+ pyimport mod, imports
10
17
  else
11
18
  pyimport mod
12
19
  end
@@ -17,8 +24,10 @@ module RbbtPython
17
24
 
18
25
  def self.run_log(mod = nil, imports = nil, severity = 0, severity_err = nil, &block)
19
26
  if mod
20
- if imports
27
+ if Array === imports
21
28
  pyfrom mod, :import => imports
29
+ elsif Hash === imports
30
+ pyimport mod, imports
22
31
  else
23
32
  pyimport mod
24
33
  end
@@ -31,8 +40,10 @@ module RbbtPython
31
40
 
32
41
  def self.run_log_stderr(mod = nil, imports = nil, severity = 0, &block)
33
42
  if mod
34
- if imports
43
+ if Array === imports
35
44
  pyfrom mod, :import => imports
45
+ elsif Hash === imports
46
+ pyimport mod, imports
36
47
  else
37
48
  pyimport mod
38
49
  end
@@ -49,4 +60,14 @@ module RbbtPython
49
60
  end
50
61
  end
51
62
 
63
+ def self.add_paths(paths)
64
+ self.run 'sys' do
65
+ paths.each do |path|
66
+ sys.path.append path
67
+ end
68
+ end
69
+ end
70
+
71
+ RbbtPython.add_paths Rbbt.python.find_all
72
+ RbbtPython.pyimport "rbbt"
52
73
  end