rbbt-util 5.30.10 → 5.31.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rbbt/hpc.rb +3 -0
- data/lib/rbbt/hpc/batch.rb +621 -0
- data/lib/rbbt/hpc/lsf.rb +119 -0
- data/lib/rbbt/hpc/orchestrate.rb +13 -12
- data/lib/rbbt/hpc/slurm.rb +62 -559
- data/lib/rbbt/resource/path.rb +3 -1
- data/lib/rbbt/tsv/accessor.rb +5 -2
- data/lib/rbbt/tsv/dumper.rb +1 -0
- data/lib/rbbt/tsv/parallel/traverse.rb +1 -1
- data/lib/rbbt/tsv/stream.rb +5 -6
- data/lib/rbbt/util/cmd.rb +15 -1
- data/lib/rbbt/util/log.rb +22 -1
- data/lib/rbbt/util/log/progress.rb +17 -2
- data/lib/rbbt/util/log/progress/report.rb +36 -3
- data/lib/rbbt/util/misc/development.rb +2 -2
- data/lib/rbbt/util/misc/inspect.rb +17 -1
- data/lib/rbbt/util/misc/omics.rb +60 -1
- data/lib/rbbt/util/misc/options.rb +5 -0
- data/lib/rbbt/workflow/accessor.rb +7 -2
- data/lib/rbbt/workflow/definition.rb +2 -2
- data/lib/rbbt/workflow/step/accessor.rb +10 -6
- data/lib/rbbt/workflow/step/run.rb +9 -0
- data/lib/rbbt/workflow/usage.rb +13 -13
- data/lib/rbbt/workflow/util/provenance.rb +26 -21
- data/share/config.ru +3 -3
- data/share/rbbt_commands/{slurm → hpc}/clean +91 -18
- data/share/rbbt_commands/{slurm → hpc}/list +119 -31
- data/share/rbbt_commands/hpc/orchestrate +81 -0
- data/share/rbbt_commands/hpc/tail +81 -0
- data/share/rbbt_commands/hpc/task +80 -0
- data/test/rbbt/hpc/test_batch.rb +65 -0
- data/test/rbbt/hpc/test_slurm.rb +30 -0
- data/test/rbbt/util/misc/test_development.rb +11 -0
- data/test/test_helper.rb +3 -1
- metadata +16 -7
- data/share/rbbt_commands/slurm/orchestrate +0 -48
- data/share/rbbt_commands/slurm/task +0 -46
@@ -79,9 +79,9 @@ module Workflow
|
|
79
79
|
dep = dependencies.last.join
|
80
80
|
raise dep.get_exception if dep.error?
|
81
81
|
set_info :result_type, dep.info[:result_type]
|
82
|
-
forget = config :forget_dep_tasks, "key:forget_dep_tasks", :default => FORGET_DEP_TASKS
|
82
|
+
forget = config :forget_dep_tasks, "forget_dep_tasks", "key:forget_dep_tasks", :default => FORGET_DEP_TASKS
|
83
83
|
if forget
|
84
|
-
remove = config :remove_dep_tasks, "key:remove_dep_tasks", :default => REMOVE_DEP_TASKS
|
84
|
+
remove = config :remove_dep_tasks, "remove_dep_tasks", "key:remove_dep_tasks", :default => REMOVE_DEP_TASKS
|
85
85
|
|
86
86
|
self.archive_deps
|
87
87
|
self.copy_files_dir
|
@@ -99,6 +99,7 @@ class Step
|
|
99
99
|
if String === value && File.exists?(value)
|
100
100
|
Open.ln_s(value, path)
|
101
101
|
else
|
102
|
+
value = "#{value}" if Path === value
|
102
103
|
Open.write(path + '.yaml', value.to_yaml)
|
103
104
|
end
|
104
105
|
when Array === value
|
@@ -122,15 +123,18 @@ class Step
|
|
122
123
|
workflow = job.workflow
|
123
124
|
workflow = Kernel.const_get workflow if String === workflow
|
124
125
|
if workflow
|
125
|
-
task_info = workflow.task_info(task_name)
|
126
|
-
input_types = task_info[:input_types]
|
127
|
-
task_inputs = task_info[:inputs]
|
128
|
-
input_defaults = task_info[:input_defaults]
|
126
|
+
task_info = IndiferentHash.setup(workflow.task_info(task_name))
|
127
|
+
input_types = IndiferentHash.setup(task_info[:input_types])
|
128
|
+
task_inputs = IndiferentHash.setup(task_info[:inputs])
|
129
|
+
input_defaults = IndiferentHash.setup(task_info[:input_defaults])
|
129
130
|
else
|
130
|
-
task_info =
|
131
|
+
task_info = IndiferentHash.setup({})
|
132
|
+
input_types = IndiferentHash.setup({})
|
133
|
+
task_inputs = IndiferentHash.setup({})
|
134
|
+
input_defaults = IndiferentHash.setup({})
|
131
135
|
end
|
132
136
|
|
133
|
-
inputs = {}
|
137
|
+
inputs = IndiferentHash.setup({})
|
134
138
|
real_inputs = job.real_inputs || job.info[:real_inputs]
|
135
139
|
job.recursive_inputs.zip(job.recursive_inputs.fields).each do |value,name|
|
136
140
|
next unless task_inputs.include? name.to_sym
|
@@ -623,6 +623,15 @@ class Step
|
|
623
623
|
Log.warn "Exception removing result of aborted job: #{$!.message}"
|
624
624
|
end
|
625
625
|
end
|
626
|
+
|
627
|
+
if Open.exists?(tmp_path) && status != :done
|
628
|
+
Log.warn "Aborted job had finished. Removing tmp result -- #{ tmp_path }"
|
629
|
+
begin
|
630
|
+
Open.rm tmp_path
|
631
|
+
rescue Exception
|
632
|
+
Log.warn "Exception removing tmp result of aborted job: #{$!.message}"
|
633
|
+
end
|
634
|
+
end
|
626
635
|
end
|
627
636
|
|
628
637
|
def _abort
|
data/lib/rbbt/workflow/usage.rb
CHANGED
@@ -6,19 +6,6 @@ module Task
|
|
6
6
|
puts "\n" << Misc.format_paragraph(description.strip) << "\n" if description and not description.empty?
|
7
7
|
puts
|
8
8
|
|
9
|
-
case
|
10
|
-
when (input_types.values & [:array]).any?
|
11
|
-
puts Log.color(:green, Misc.format_paragraph("Lists are specified as arguments using ',' or '|'. When specified as files the '\\n'
|
12
|
-
also works in addition to the others. You may use the '--array_separator' option
|
13
|
-
the change this default. Whenever a file is specified it may also accept STDIN using
|
14
|
-
the '-' character."))
|
15
|
-
puts
|
16
|
-
|
17
|
-
when (input_types.values & [:text, :tsv]).any?
|
18
|
-
puts Log.color(:green, Misc.format_paragraph("Whenever a file is specified it may also accept STDIN using the '-' character."))
|
19
|
-
puts
|
20
|
-
end
|
21
|
-
|
22
9
|
selects = []
|
23
10
|
if inputs.any?
|
24
11
|
inputs.zip(input_types.values_at(*inputs)).select{|i,t| t.to_sym == :select && input_options[i] && input_options[i][:select_options] }.each{|i,t| selects << [i, input_options[i][:select_options]] }
|
@@ -50,6 +37,19 @@ module Task
|
|
50
37
|
puts
|
51
38
|
end
|
52
39
|
|
40
|
+
case
|
41
|
+
when (input_types.values & [:array]).any?
|
42
|
+
puts Log.color(:green, Misc.format_paragraph("Lists are specified as arguments using ',' or '|'. When specified as files the '\\n'
|
43
|
+
also works in addition to the others. You may use the '--array_separator' option
|
44
|
+
the change this default. Whenever a file is specified it may also accept STDIN using
|
45
|
+
the '-' character."))
|
46
|
+
puts
|
47
|
+
|
48
|
+
when (input_types.values & [:text, :tsv]).any?
|
49
|
+
puts Log.color(:green, Misc.format_paragraph("Whenever a file is specified it may also accept STDIN using the '-' character."))
|
50
|
+
puts
|
51
|
+
end
|
52
|
+
|
53
53
|
puts Log.color(:magenta, "Returns: ") << Log.color(:blue, result_type.to_s) << "\n"
|
54
54
|
puts
|
55
55
|
|
@@ -1,23 +1,28 @@
|
|
1
1
|
class Step
|
2
|
+
|
3
|
+
def self.status_color(status)
|
4
|
+
case status.to_sym
|
5
|
+
when :error, :aborted, :missing, :dead, :unsync
|
6
|
+
:red
|
7
|
+
when :streaming, :started
|
8
|
+
:cyan
|
9
|
+
when :done, :noinfo
|
10
|
+
:green
|
11
|
+
when :dependencies, :waiting, :setup
|
12
|
+
:yellow
|
13
|
+
when :notfound, :cleaned
|
14
|
+
:blue
|
15
|
+
else
|
16
|
+
if status.to_s.index ">"
|
17
|
+
:cyan
|
18
|
+
else
|
19
|
+
:cyan
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
2
24
|
def self.prov_status_msg(status)
|
3
|
-
color =
|
4
|
-
when :error, :aborted, :missing, :dead, :unsync
|
5
|
-
:red
|
6
|
-
when :streaming, :started
|
7
|
-
:cyan
|
8
|
-
when :done, :noinfo
|
9
|
-
:green
|
10
|
-
when :dependencies, :waiting, :setup
|
11
|
-
:yellow
|
12
|
-
when :notfound, :cleaned
|
13
|
-
:blue
|
14
|
-
else
|
15
|
-
if status.to_s.index ">"
|
16
|
-
:cyan
|
17
|
-
else
|
18
|
-
:cyan
|
19
|
-
end
|
20
|
-
end
|
25
|
+
color = status_color(status)
|
21
26
|
Log.color(color, status.to_s)
|
22
27
|
end
|
23
28
|
|
@@ -25,7 +30,7 @@ class Step
|
|
25
30
|
parts = path.sub(/\{.*/,'').split "/"
|
26
31
|
|
27
32
|
parts.pop
|
28
|
-
|
33
|
+
|
29
34
|
task = Log.color(:yellow, parts.pop)
|
30
35
|
workflow = Log.color(:magenta, parts.pop)
|
31
36
|
#if status.to_s == 'noinfo' && parts.last != 'jobs'
|
@@ -89,7 +94,7 @@ class Step
|
|
89
94
|
str << prov_report(dep, offset + 1, task, seen, expand_repeats)
|
90
95
|
else
|
91
96
|
if expand_repeats
|
92
|
-
str << Log.color(
|
97
|
+
str << Log.color(Step.status_color(dep.status), Log.uncolor(prov_report(dep, offset+1, task)))
|
93
98
|
else
|
94
99
|
info = dep.info || {}
|
95
100
|
status = info[:status] || :missing
|
@@ -98,7 +103,7 @@ class Step
|
|
98
103
|
status = :unsync if status == :done and not Open.exist?(path)
|
99
104
|
status = :notfound if status == :noinfo and not Open.exist?(path)
|
100
105
|
|
101
|
-
str << Log.color(status
|
106
|
+
str << Log.color(Step.status_color(status), " " * (offset + 1) + Log.uncolor(prov_report_msg(status, name, path, info)))
|
102
107
|
end
|
103
108
|
end
|
104
109
|
end if step.dependencies
|
data/share/config.ru
CHANGED
@@ -43,6 +43,9 @@ app_eval app, Rbbt.etc['app.d/remote_workflow_tasks.rb'].find_all
|
|
43
43
|
#{{{ BASE
|
44
44
|
app_eval app, Rbbt.etc['app.d/base.rb'].find
|
45
45
|
|
46
|
+
#{{{ SINATRA
|
47
|
+
load_file Rbbt.lib['sinatra.rb'].find_all
|
48
|
+
|
46
49
|
#{{{ RESOURCES
|
47
50
|
load_file Rbbt.etc['app.d/resources.rb'].find
|
48
51
|
|
@@ -70,9 +73,6 @@ load_file Rbbt.etc['app.d/preload.rb'].find_all
|
|
70
73
|
#{{{ PRELOAD
|
71
74
|
load_file Rbbt.etc['app.d/semaphores.rb'].find_all
|
72
75
|
|
73
|
-
#{{{ SINATRA
|
74
|
-
load_file Rbbt.lib['sinatra.rb'].find_all
|
75
|
-
|
76
76
|
Entity.entity_list_cache = Rbbt.var.sinatra.app[app_name].find.entity_lists
|
77
77
|
Entity.entity_map_cache = Rbbt.var.sinatra.app[app_name].find.entity_maps
|
78
78
|
Entity.entity_property_cache = Rbbt.var.sinatra.app[app_name].find.entity_properties
|
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'rbbt-util'
|
4
4
|
require 'rbbt/util/simpleopt'
|
5
|
+
require 'rbbt/hpc'
|
5
6
|
|
6
7
|
#$0 = "rbbt #{$previous_commands*""} #{ File.basename(__FILE__) }" if $previous_commands
|
7
8
|
|
@@ -9,16 +10,17 @@ options = SOPT.setup <<EOF
|
|
9
10
|
|
10
11
|
Clean error or aborted jobs
|
11
12
|
|
12
|
-
$ rbbt
|
13
|
+
$ rbbt slurm clean [options]
|
13
14
|
|
14
15
|
-h--help Print this help
|
15
16
|
-d--done Done jobs only
|
16
17
|
-e--error Error jobs only
|
17
18
|
-a--aborted SLURM aboted jobs
|
19
|
+
-q--queued Queued jobs only
|
18
20
|
-j--job* Job ids
|
19
21
|
-s--search* Regular expression
|
20
22
|
-t--tail* Show the last lines of the STDERR
|
21
|
-
-
|
23
|
+
-BP--batch_parameters show batch parameters
|
22
24
|
-dr--dry_run Do not erase anything
|
23
25
|
EOF
|
24
26
|
|
@@ -31,14 +33,47 @@ if options[:help]
|
|
31
33
|
exit 0
|
32
34
|
end
|
33
35
|
|
36
|
+
batch_system = options.delete :batch_system
|
37
|
+
batch_system ||= 'auto'
|
38
|
+
|
39
|
+
HPC::BATCH_MODULE = case batch_system.to_s.downcase
|
40
|
+
when 'slurm'
|
41
|
+
HPC::SLURM
|
42
|
+
when 'lsf'
|
43
|
+
HPC::LSF
|
44
|
+
when 'auto'
|
45
|
+
case $previous_commands.last
|
46
|
+
when 'slurm'
|
47
|
+
HPC::SLURM
|
48
|
+
when 'lsf'
|
49
|
+
HPC::LSF
|
50
|
+
else
|
51
|
+
case Rbbt::Config.get(:batch_system, :batch, :batch_system, :hpc, :HPC, :BATCH).to_s.downcase
|
52
|
+
when 'slurm'
|
53
|
+
HPC::SLURM
|
54
|
+
when 'lsf'
|
55
|
+
HPC::LSF
|
56
|
+
else
|
57
|
+
case ENV["BATCH_SYSTEM"].to_s.downcase
|
58
|
+
when 'slurm'
|
59
|
+
HPC::SLURM
|
60
|
+
when 'lsf'
|
61
|
+
HPC::LSF
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
raise ParameterException.new("Could not detect batch_system: #{Misc.fingerprint batch_system}") if HPC::BATCH_MODULE.nil?
|
68
|
+
|
34
69
|
Log.severity = 4
|
35
|
-
done, error, aborted, jobid, search, tail,
|
70
|
+
done, error, aborted, queued, jobid, search, tail, batch_parameters, dry_run = options.values_at :done, :error, :aborted, :queued, :job, :search, :tail, :batch_parameters, :dry_run
|
36
71
|
|
37
|
-
workdir = File.expand_path('~/rbbt-
|
72
|
+
workdir = File.expand_path('~/rbbt-batch')
|
38
73
|
Path.setup(workdir)
|
39
74
|
|
40
75
|
running_jobs = begin
|
41
|
-
squeue_txt =
|
76
|
+
squeue_txt = HPC::BATCH_MODULE.job_status
|
42
77
|
squeue_txt.split("\n").collect{|l| l.to_i.to_s}
|
43
78
|
rescue
|
44
79
|
Log.warn "Cannot determine if jobs are running, they will seem to be all alive (Job ID in green)"
|
@@ -58,27 +93,35 @@ else
|
|
58
93
|
end
|
59
94
|
|
60
95
|
count = 0
|
61
|
-
workdir.glob("**/command.
|
96
|
+
workdir.glob("**/command.batch").sort_by{|f| File.mtime(f)}.each do |fcmd|
|
62
97
|
dir = File.dirname(fcmd)
|
98
|
+
command_txt = Open.read(fcmd)
|
63
99
|
|
64
|
-
if m =
|
100
|
+
if m = command_txt.match(/#CMD: (.*)/)
|
65
101
|
cmd = m[1]
|
66
102
|
else
|
67
103
|
cmd = nil
|
68
104
|
end
|
69
105
|
|
70
|
-
if m =
|
106
|
+
if m = command_txt.match(/# Run command\n(.*?)\n/im)
|
71
107
|
exe = m[1]
|
72
108
|
else
|
73
109
|
exe = nil
|
74
110
|
end
|
75
111
|
|
76
|
-
if m =
|
112
|
+
if m = command_txt.match(/^CONTAINER_DIR=(.*)/)
|
77
113
|
container_home = m[1]
|
78
114
|
else
|
79
115
|
container_home = nil
|
80
116
|
end
|
81
117
|
|
118
|
+
if m = command_txt.match(/^BATCH_SYSTEM=(.*)/)
|
119
|
+
job_batch_system = m[1].downcase
|
120
|
+
else
|
121
|
+
job_batch_system = nil
|
122
|
+
end
|
123
|
+
|
124
|
+
different_system = job_batch_system != batch_system
|
82
125
|
|
83
126
|
if File.exists?(fid = File.join(dir, 'job.id'))
|
84
127
|
id = Open.read(fid).chomp
|
@@ -93,7 +136,16 @@ workdir.glob("**/command.slurm").sort_by{|f| File.mtime(f)}.each do |fcmd|
|
|
93
136
|
end
|
94
137
|
|
95
138
|
if File.exists?(fstatus = File.join(dir, 'job.status'))
|
96
|
-
|
139
|
+
fstatus_txt = Open.read(fstatus)
|
140
|
+
begin
|
141
|
+
if job_batch_system == "lsf"
|
142
|
+
nodes = Open.read(fstatus).split("\n").last.split(/\s+/)[5].split(",")
|
143
|
+
else
|
144
|
+
nodes = Open.read(fstatus).split("\n").last.split(/\s+/).last.split(",")
|
145
|
+
end
|
146
|
+
rescue
|
147
|
+
nodes = []
|
148
|
+
end
|
97
149
|
elsif job_nodes[id]
|
98
150
|
nodes = job_nodes[id]
|
99
151
|
else
|
@@ -113,20 +165,36 @@ workdir.glob("**/command.slurm").sort_by{|f| File.mtime(f)}.each do |fcmd|
|
|
113
165
|
cadeps = Open.read(fcadep).split("\n") if File.exists?(fcadep)
|
114
166
|
|
115
167
|
aborted = error = true if aborted.nil? && error.nil?
|
116
|
-
if done || error || aborted || running || queued || jobid || search
|
168
|
+
#if done || error || aborted || running || queued || jobid || search
|
169
|
+
# select = false
|
170
|
+
# select = true if done && exit_status && exit_status.to_i == 0
|
171
|
+
# select = true if error && exit_status && exit_status.to_i != 0
|
172
|
+
# select = true if aborted && (exit_status.nil? && ! running_jobs.include?(id))
|
173
|
+
# select = select && jobid.split(",").include?(id) if jobid
|
174
|
+
# select = select && cmd.match(/#{search}/) if search
|
175
|
+
# next unless select
|
176
|
+
#end
|
177
|
+
|
178
|
+
if done || error || aborted || queued || jobid
|
117
179
|
select = false
|
118
|
-
select = true if done && exit_status
|
119
|
-
select = true if error && exit_status && exit_status
|
180
|
+
select = true if done && exit_status == 0
|
181
|
+
select = true if error && exit_status && exit_status != 0
|
120
182
|
select = true if aborted && (exit_status.nil? && ! running_jobs.include?(id))
|
121
|
-
|
183
|
+
is_running = exit_status.nil? && ( (running_jobs.include?(id) && (!deps || (running_jobs & deps).empty?)) || different_system )
|
184
|
+
select = true if queued && deps && (running_jobs & deps).any? || queued && is_running && nodes.empty?
|
185
|
+
select = true if jobid && jobid.split(",").include?(id)
|
122
186
|
select = select && cmd.match(/#{search}/) if search
|
123
187
|
next unless select
|
188
|
+
elsif search
|
189
|
+
select = false
|
190
|
+
select = true if search && cmd.match(/#{search}/)
|
191
|
+
next unless select
|
124
192
|
end
|
125
193
|
|
126
194
|
|
127
195
|
puts Log.color(:yellow, "**ERASING**")
|
128
196
|
puts Log.color :blue, dir
|
129
|
-
puts Log.color(:magenta, "Creation: ") << File.mtime(File.join(dir, 'command.
|
197
|
+
puts Log.color(:magenta, "Creation: ") << File.mtime(File.join(dir, 'command.batch')).to_s
|
130
198
|
puts Log.color(:magenta, "Done: ") << File.mtime(File.join(dir, 'exit.status')).to_s if File.exist?(File.join(dir, 'exit.status'))
|
131
199
|
puts Log.color(:magenta, "Exec: ") << (exe || "Missing")
|
132
200
|
puts Log.color(:magenta, "CMD: ") << (Log.color(:yellow, cmd) || "Missing")
|
@@ -137,9 +205,14 @@ workdir.glob("**/command.slurm").sort_by{|f| File.mtime(f)}.each do |fcmd|
|
|
137
205
|
puts Log.color(:magenta, "Nodes: ") << nodes * ", "
|
138
206
|
puts Log.color(:magenta, "Output: ") << File.exists?(File.join(dir, 'std.out')).to_s << (id.nil? ? "" : " (last update " + Misc.format_seconds(time_diff) + " ago)")
|
139
207
|
|
140
|
-
if options[:
|
141
|
-
puts Log.color(:magenta, "
|
142
|
-
|
208
|
+
if options[:batch_parameters]
|
209
|
+
puts Log.color(:magenta, "BATCH parameters: ")
|
210
|
+
case job_batch_system
|
211
|
+
when 'slurm'
|
212
|
+
puts Log.color :blue, CMD.cmd('grep "^#SBATCH" |tail -n +6', :in => Open.read(fcmd)).read.strip
|
213
|
+
when 'lsf'
|
214
|
+
puts Log.color :blue, CMD.cmd('grep "^#BSUB" |tail -n +6', :in => Open.read(fcmd)).read.strip
|
215
|
+
end
|
143
216
|
end
|
144
217
|
|
145
218
|
if tail && File.exists?(File.join(dir, 'std.err'))
|
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'rbbt-util'
|
4
4
|
require 'rbbt/util/simpleopt'
|
5
|
+
require 'rbbt/hpc'
|
5
6
|
|
6
7
|
#$0 = "rbbt #{$previous_commands*""} #{ File.basename(__FILE__) }" if $previous_commands
|
7
8
|
|
@@ -9,7 +10,7 @@ options = SOPT.setup <<EOF
|
|
9
10
|
|
10
11
|
Queue a job in Marenostrum
|
11
12
|
|
12
|
-
$ rbbt
|
13
|
+
$ rbbt slurm list [options]
|
13
14
|
|
14
15
|
-h--help Print this help
|
15
16
|
-d--done Done jobs only
|
@@ -20,9 +21,11 @@ $ rbbt mnl [options]
|
|
20
21
|
-j--job* Job ids
|
21
22
|
-s--search* Regular expression
|
22
23
|
-t--tail* Show the last lines of the STDERR
|
23
|
-
-
|
24
|
-
-
|
24
|
+
-p--progress Report progress of job and the dependencies
|
25
|
+
-BP--batch_parameters show batch parameters
|
26
|
+
-BPP--batch_procpath show Procpath performance summary
|
25
27
|
-sacct--sacct_peformance show sacct performance summary
|
28
|
+
-bs--batch_system* Batch system to use: auto, lsf, slurm (default is auto-detect)
|
26
29
|
EOF
|
27
30
|
|
28
31
|
if options[:help]
|
@@ -34,14 +37,48 @@ if options[:help]
|
|
34
37
|
exit 0
|
35
38
|
end
|
36
39
|
|
37
|
-
|
38
|
-
|
40
|
+
batch_system = options.delete :batch_system
|
41
|
+
batch_system ||= 'auto'
|
42
|
+
|
43
|
+
HPC::BATCH_MODULE = case batch_system.to_s.downcase
|
44
|
+
when 'slurm'
|
45
|
+
HPC::SLURM
|
46
|
+
when 'lsf'
|
47
|
+
HPC::LSF
|
48
|
+
when 'auto'
|
49
|
+
case $previous_commands.last
|
50
|
+
when 'slurm'
|
51
|
+
HPC::SLURM
|
52
|
+
when 'lsf'
|
53
|
+
HPC::LSF
|
54
|
+
else
|
55
|
+
case Rbbt::Config.get(:batch_system, :batch, :batch_system, :hpc, :HPC, :BATCH).to_s.downcase
|
56
|
+
when 'slurm'
|
57
|
+
HPC::SLURM
|
58
|
+
when 'lsf'
|
59
|
+
HPC::LSF
|
60
|
+
else
|
61
|
+
case ENV["BATCH_SYSTEM"].to_s.downcase
|
62
|
+
when 'slurm'
|
63
|
+
HPC::SLURM
|
64
|
+
when 'lsf'
|
65
|
+
HPC::LSF
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
raise ParameterException.new("Could not detect batch_system: #{Misc.fingerprint batch_system}") if HPC::BATCH_MODULE.nil?
|
72
|
+
|
73
|
+
batch_system = HPC::BATCH_MODULE.to_s.split("::").last.downcase
|
39
74
|
|
40
|
-
|
75
|
+
done, error, running, queued, aborted, jobid, search, tail, progress = options.values_at :done, :error, :running, :queued, :aborted, :job, :search, :tail, :progress
|
76
|
+
|
77
|
+
workdir = File.expand_path('~/rbbt-batch')
|
41
78
|
Path.setup(workdir)
|
42
79
|
|
43
80
|
running_jobs = begin
|
44
|
-
squeue_txt =
|
81
|
+
squeue_txt = HPC::BATCH_MODULE.job_status
|
45
82
|
squeue_txt.split("\n").collect{|l| l.to_i.to_s}
|
46
83
|
rescue
|
47
84
|
Log.warn "Cannot determine if jobs are running, they will seem to be all alive (Job ID in green)"
|
@@ -61,35 +98,48 @@ else
|
|
61
98
|
end
|
62
99
|
|
63
100
|
count = 0
|
64
|
-
workdir.glob("**/command.
|
101
|
+
workdir.glob("**/command.batch").sort_by{|f| File.mtime(f)}.each do |fcmd|
|
65
102
|
dir = File.dirname(fcmd)
|
103
|
+
command_txt = Open.read(fcmd)
|
66
104
|
|
67
|
-
if m =
|
105
|
+
if m = command_txt.match(/#CMD: (.*)/)
|
68
106
|
cmd = m[1]
|
69
107
|
else
|
70
108
|
cmd = nil
|
71
109
|
end
|
72
110
|
|
73
|
-
if m =
|
111
|
+
if m = command_txt.match(/^BATCH_SYSTEM=(.*)/)
|
112
|
+
job_batch_system = m[1].downcase
|
113
|
+
else
|
114
|
+
job_batch_system = nil
|
115
|
+
end
|
116
|
+
|
117
|
+
different_system = job_batch_system != batch_system
|
118
|
+
|
119
|
+
if m = command_txt.match(/#MANIFEST: (.*)/)
|
74
120
|
manifest = m[1]
|
75
121
|
else
|
76
122
|
manifest = nil
|
77
123
|
end
|
78
124
|
|
125
|
+
if m = command_txt.match(/#STEP_PATH: (.*)/)
|
126
|
+
step_path = m[1]
|
127
|
+
else
|
128
|
+
step_path = nil
|
129
|
+
end
|
79
130
|
|
80
|
-
if m =
|
81
|
-
exe = m[1]
|
131
|
+
if m = command_txt.match(/#EXEC_CMD: (.*)/)
|
132
|
+
exe = m[1]
|
82
133
|
else
|
83
134
|
exe = nil
|
84
135
|
end
|
85
136
|
|
86
|
-
if m =
|
137
|
+
if m = command_txt.match(/^CONTAINER_DIR=(.*)/)
|
87
138
|
container_home = m[1]
|
88
139
|
else
|
89
140
|
container_home = nil
|
90
141
|
end
|
91
142
|
|
92
|
-
|
93
143
|
if File.exists?(fid = File.join(dir, 'job.id'))
|
94
144
|
id = Open.read(fid).chomp
|
95
145
|
else
|
@@ -103,11 +153,20 @@ workdir.glob("**/command.slurm").sort_by{|f| File.mtime(f)}.each do |fcmd|
|
|
103
153
|
end
|
104
154
|
|
105
155
|
if File.exists?(fstatus = File.join(dir, 'job.status'))
|
106
|
-
|
156
|
+
fstatus_txt = Open.read(fstatus)
|
157
|
+
begin
|
158
|
+
if job_batch_system == "lsf"
|
159
|
+
nodes = Open.read(fstatus).split("\n").last.split(/\s+/)[5].split(",")
|
160
|
+
else
|
161
|
+
nodes = Open.read(fstatus).split("\n").last.split(/\s+/).last.split(",")
|
162
|
+
end
|
163
|
+
rescue
|
164
|
+
nodes = []
|
165
|
+
end
|
107
166
|
elsif job_nodes[id]
|
108
|
-
|
167
|
+
nodes = job_nodes[id].reject{|n| n.include? "("}
|
109
168
|
else
|
110
|
-
|
169
|
+
nodes = []
|
111
170
|
end
|
112
171
|
|
113
172
|
if File.exists?(File.join(dir, 'exit.status'))
|
@@ -136,7 +195,7 @@ workdir.glob("**/command.slurm").sort_by{|f| File.mtime(f)}.each do |fcmd|
|
|
136
195
|
select = true if done && exit_status == 0
|
137
196
|
select = true if error && exit_status && exit_status != 0
|
138
197
|
select = true if aborted && (exit_status.nil? && ! running_jobs.include?(id))
|
139
|
-
is_running = exit_status.nil? && running_jobs.include?(id) && (!deps || (running_jobs & deps).empty?)
|
198
|
+
is_running = exit_status.nil? && ( (running_jobs.include?(id) && (!deps || (running_jobs & deps).empty?)) || different_system )
|
140
199
|
select = true if queued && deps && (running_jobs & deps).any? || queued && is_running && nodes.empty?
|
141
200
|
select = true if running && nodes.any? && (exit_status.nil? && running_jobs.include?(id)) && (!deps || (running_jobs & deps).empty?)
|
142
201
|
select = true if jobid && jobid.split(",").include?(id)
|
@@ -150,29 +209,39 @@ workdir.glob("**/command.slurm").sort_by{|f| File.mtime(f)}.each do |fcmd|
|
|
150
209
|
|
151
210
|
|
152
211
|
puts Log.color :blue, dir
|
153
|
-
puts Log.color(:magenta, "Creation: ") << File.mtime(File.join(dir, 'command.
|
212
|
+
puts Log.color(:magenta, "Creation: ") << File.mtime(File.join(dir, 'command.batch')).to_s
|
154
213
|
puts Log.color(:magenta, "Started: ") << File.ctime(File.join(dir, 'std.err')).to_s if File.exist?(File.join(dir, 'std.err'))
|
155
214
|
puts Log.color(:magenta, "Manifest: ") << Log.color(:yellow, manifest)
|
215
|
+
puts Log.color(:magenta, "Step path: ") << Log.color(:yellow, step_path)
|
156
216
|
puts Log.color(:magenta, "Done: ") << File.mtime(File.join(dir, 'exit.status')).to_s if File.exist?(File.join(dir, 'exit.status'))
|
157
217
|
puts Log.color(:magenta, "Exec: ") << (exe || "Missing")
|
158
218
|
puts Log.color(:magenta, "CMD: ") << (Log.color(:yellow, cmd) || "Missing")
|
159
219
|
puts Log.color(:magenta, "HOME: ") << Log.color(:yellow, container_home) if container_home
|
160
|
-
|
220
|
+
if different_system
|
221
|
+
puts Log.color(:magenta, "Job ID (#{Log.color(:red, job_batch_system)}): ") << (exit_status ? (exit_status == 0 ? Log.color(:green, "Done") : Log.color(:red, "Error")) + " (#{ id })" : Log.color(:green, id) )
|
222
|
+
else
|
223
|
+
puts Log.color(:magenta, "Job ID: ") << (exit_status ? (exit_status == 0 ? Log.color(:green, "Done") : Log.color(:red, "Error")) + " (#{ id })" : (running_jobs.include?(id) || $norunningjobs ? Log.color(:green, id) : Log.color(:red, id) ))
|
224
|
+
end
|
161
225
|
puts Log.color(:magenta, "Dependencies: ") << deps * ", " if deps
|
162
226
|
puts Log.color(:magenta, "Dependencies (can fail): ") << cadeps * ", " if cadeps
|
163
227
|
puts Log.color(:magenta, "Nodes: ") << nodes * ", "
|
164
228
|
puts Log.color(:magenta, "Time elapsed: ") << Misc.format_seconds(time_elapsed) if time_elapsed
|
165
229
|
puts Log.color(:magenta, "Output: ") << File.exists?(File.join(dir, 'std.out')).to_s << (id.nil? || File.exists?(File.join(dir, 'exit.status')) ? "" : " (last update " + Misc.format_seconds(time_diff) + " ago)")
|
166
230
|
|
167
|
-
if options[:
|
168
|
-
puts Log.color(:magenta, "
|
169
|
-
|
231
|
+
if options[:batch_parameters]
|
232
|
+
puts Log.color(:magenta, "BATCH parameters: ")
|
233
|
+
case job_batch_system
|
234
|
+
when 'slurm'
|
235
|
+
text = CMD.cmd('grep "^#SBATCH" |tail -n +5', :in => Open.read(fcmd)).read.strip
|
236
|
+
when 'lsf'
|
237
|
+
text = CMD.cmd('grep "^#BSUB" |tail -n +5', :in => Open.read(fcmd)).read.strip
|
238
|
+
end
|
170
239
|
lines = text.split("\n").collect{|line| header, _sep, value = line.partition(/\s+/); Log.color(:yellow, header + ": ") + value}
|
171
240
|
puts Log.color :yellow, lines * "\n"
|
172
241
|
end
|
173
242
|
|
174
243
|
fprocpath = File.join(dir, 'procpath.sqlite3')
|
175
|
-
if options[:
|
244
|
+
if options[:batch_procpath] && Open.exists?(fprocpath)
|
176
245
|
puts Log.color(:magenta, "Procpath summary: ")
|
177
246
|
require 'rbbt/tsv/csv'
|
178
247
|
meta = TSV.csv(CMD.cmd("sqlite3 -header -csv #{fprocpath} 'select * from meta;' "))
|
@@ -214,13 +283,15 @@ workdir.glob("**/command.slurm").sort_by{|f| File.mtime(f)}.each do |fcmd|
|
|
214
283
|
|
215
284
|
if options[:sacct_peformance]
|
216
285
|
begin
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
286
|
+
raise "sacct not supported for LSF" unless batch_system == 'slurm'
|
287
|
+
tsv = TSV.open(CMD.cmd("sacct -j #{id} -o 'jobid,AveRSS,MaxRSS,MaxDiskRead,MaxDiskWrite' -P|grep 'JobID\\|\.batch'"), :header_hash => '', :sep => "|", :type => :list)
|
288
|
+
values = tsv[tsv.keys.first]
|
289
|
+
if values.compact.any?
|
290
|
+
puts Log.color(:magenta, "SACCT performance: ")
|
291
|
+
puts values.zip(values.fields).collect{|v,t| Log.color(:yellow, t + ": ") + v.to_s } * "\n"
|
292
|
+
end
|
223
293
|
rescue
|
294
|
+
Log.warn $!.message
|
224
295
|
end
|
225
296
|
end
|
226
297
|
|
@@ -234,7 +305,24 @@ workdir.glob("**/command.slurm").sort_by{|f| File.mtime(f)}.each do |fcmd|
|
|
234
305
|
puts CMD.cmd("grep -i -w 'Completed step' #{File.join(dir, 'std.err')} | grep -v 'Retrying dep.' | tail -n #{tail.to_i}", :no_fail => true).read
|
235
306
|
else
|
236
307
|
puts Log.color(:magenta, "Log tail: ")
|
237
|
-
puts CMD.cmd("
|
308
|
+
puts CMD.cmd(" cat #{File.join(dir, 'std.err')} | grep -v '^[^\\s:]*\\[3.m' | tail -n #{tail.to_i} ").read
|
309
|
+
end
|
310
|
+
end
|
311
|
+
|
312
|
+
if options[:progress]
|
313
|
+
step_line = Open.read(fcmd).split("\n").select{|line| line =~ /^#STEP_PATH:/}.first
|
314
|
+
if step_line
|
315
|
+
require 'rbbt/workflow'
|
316
|
+
step_path = step_line.split(": ").last.strip
|
317
|
+
step = Step.new step_path
|
318
|
+
step.load_dependencies_from_info
|
319
|
+
(step.rec_dependencies + [step]).reverse.each do |j|
|
320
|
+
next if j.done?
|
321
|
+
next unless j.file(:progress).exists?
|
322
|
+
bar = Log::ProgressBar.new
|
323
|
+
bar.load(j.file(:progress).yaml)
|
324
|
+
puts Log.color(:magenta, "Progress: ") + bar.report_msg + " " + Log.color(:yellow, j.task_signature)
|
325
|
+
end
|
238
326
|
end
|
239
327
|
end
|
240
328
|
|