blib/lib/HPC/Runner/Command/submit_jobs/Utils/Scheduler/Directives.pm

filter: Statementstmt 73.3% 33 / 45 Branchbran n/a Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 54.5% 6 / 11 Podpod n/a totaltotal 60.0% 39 / 65 CC 3 SCAR 13.5
CC
3
Cov
65%
__ANON__
12.0
__ANON__
2.0
__ANON__
2.0
CRAP 3.8
« blib/lib/HPC/Runner/Command/submit_jobs/Plugin/Dummy.pm ↑ Summary blib/lib/HPC/Runner/Command/submit_jobs/Utils/Scheduler/JobStats.pm »
1 package HPC::Runner::Command::submit_jobs::Utils::Scheduler::Directives;
2  
3 1 ▶use MooseX::App::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use BioSAILs::Utils::Traits qw(ArrayRefOfStrs);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use File::Temp qw/ tempfile /;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use File::Slurp;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 =head1 HPC::Runner::Command::submit_jobs::Utils::Scheduler::Directives
13  
14 =cut
15  
16 =head2 Command Line Options
17  
18 #TODO Move this over to docs
19  
20 =cut
21  
22 =head3 module
23  
24 modules to load with slurm
25 Should use the same names used in 'module load'
26  
27 Example. R2 becomes 'module load R2'
28  
29 =cut
30  
31 option 'module' => (
32 traits => ['Array'],
33 is => 'rw',
34 isa => ArrayRefOfStrs,
35 coerce => 1,
36 required => 0,
37 documentation => q{List of modules to load ex. R2, samtools, etc},
38 0 ▶ default => sub { [] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
39 1 cmd_split => qr/,/,
40 handles => {
41 has_modules => 'count',
42 all_modules => 'elements',
43 join_modules => 'join',
44 },
45 );
46  
47 =head3 conda_env
48  
49 Anaconda envs to load
50  
51 Load anaconda envs with
52  
53 source activate /path/to/my/env
54  
55 =cut
56  
57 1 option 'conda_env' => (
58 is => 'rw',
59 isa => 'Str',
60 required => 0,
61 documentation => q{Conda env to activate.},
62 predicate => 'has_conda_env',
63 );
64  
65 =head3 cpus_per_task
66  
67 slurm item --cpus_per_task defaults to 1
68  
69 =cut
70  
71 1 option 'cpus_per_task' => (
72 is => 'rw',
73 isa => 'Int',
74 required => 0,
75 default => 4,
76 predicate => 'has_cpus_per_task',
77 clearer => 'clear_cpus_per_task',
78 documentation => '--cpus-per-task switch in slurm'
79 );
80  
81 =head3 ntasks
82  
83 slurm item --ntasks defaults to 1
84  
85 =cut
86  
87 1 option 'ntasks' => (
88 is => 'rw',
89 isa => 'Int',
90 required => 0,
91 default => 1,
92 predicate => 'has_ntasks',
93 clearer => 'clear_ntasks',
94 documentation =>
95 '--ntasks switch in slurm. This is equal to the number of concurrent tasks on each node * the number of nodes, not the total number of tasks'
96 );
97  
98 =head3 account
99  
100 slurm item --account defaults to 1
101  
102 =cut
103  
104 1 option 'account' => (
105 is => 'rw',
106 isa => 'Str',
107 required => 0,
108 predicate => 'has_account',
109 clearer => 'clear_account',
110 documentation => '--account switch in slurm. '
111 );
112  
113 =head3 account-per-node
114  
115 slurm item --ntasks-per-node defaults to 28
116  
117 =cut
118  
119 option 'ntasks_per_node' => (
120 is => 'rw',
121 isa => 'Int',
122 required => 0,
123 default => 1,
124 trigger => sub {
125 0 ▶ my $self = shift;
Subroutine __ANON__: not called CC=1 SCAR=6.9
126 0 my $ntasks = $self->ntasks_per_node * $self->nodes_count;
127 0 $self->ntasks($ntasks);
128 },
129 1 predicate => 'has_ntasks_per_node',
130 clearer => 'clear_ntasks_per_node',
131 documentation =>
132 '--ntasks-per-node switch in slurm. total concurrent tasks on a node.'
133 );
134  
135 =head3 commands_per_node
136  
137 commands to run per node
138  
139 =cut
140  
141 #TODO Update this for job arrays
142  
143 1 option 'commands_per_node' => (
144 is => 'rw',
145 isa => 'Int',
146 required => 0,
147 default => 1,
148 documentation =>
149 q{Commands to run on each node. If you have a low number of jobs you can submit at a time you want this number much higher. },
150 predicate => 'has_commands_per_node',
151 clearer => 'clear_commands_per_node'
152 );
153  
154 =head3 nodes_count
155  
156 Number of nodes to use on a job. This is only useful for mpi jobs.
157  
158 PBS:
159 #PBS -l nodes=nodes_count:ppn=16 this
160  
161 Slurm:
162 #SBATCH --nodes=nodes_count
163  
164 =cut
165  
166 1 option 'nodes_count' => (
167 is => 'rw',
168 isa => 'Int',
169 required => 0,
170 default => 1,
171 documentation =>
172 q{Number of nodes requested. You should only use this if submitting parallel jobs.},
173 predicate => 'has_nodes_count',
174 clearer => 'clear_nodes_count'
175 );
176  
177 =head3 partition
178  
179 Specify the partition.
180  
181 In PBS this is called 'queue'
182  
183 =cut
184  
185 1 option 'partition' => (
186 is => 'rw',
187 isa => 'Str',
188 required => 0,
189 documentation => q{Slurm partition to submit jobs to.},
190 predicate => 'has_partition',
191 clearer => 'clear_partition'
192 );
193  
194 =head3 walltime
195  
196 Define scheduler walltime
197  
198 =cut
199  
200 1 option 'walltime' => (
201 is => 'rw',
202 isa => 'Str',
203 required => 0,
204 default => '00:20:00',
205 predicate => 'has_walltime',
206 clearer => 'clear_walltime,'
207 );
208  
209 =head2 mem
210  
211 =cut
212  
213 1 option 'mem' => (
214 is => 'rw',
215 isa => 'Str|Undef',
216 predicate => 'has_mem',
217 clearer => 'clear_mem',
218 required => 0,
219 default => '10GB',
220 documentation => q{Supply a memory limit},
221 );
222  
223 =head3 user
224  
225 user running the script. Passed to slurm for mail information
226  
227 =cut
228  
229 option 'user' => (
230 is => 'rw',
231 isa => 'Str',
232 0 ▶ default => sub { return $ENV{USER} || $ENV{LOGNAME} || getpwuid($<); },
Subroutine __ANON__: not called CC=3 SCAR=24.8
Condition0%0/6
$ENV{'USER'} || $ENV{'LOGNAME'} || getpwuid $<
l!l&&r!l&&!r
000
$ENV{"USER"} or $ENV{"LOGNAME"}
l!l&&r!l&&!r
000
MC/DC0%0/3
$ENV{'USER'} || $ENV{'LOGNAME'} || getpwuid $<
$ENV{"USER"} $ENV{"LOGNAME"} getpwuid $<
Truth table0%0/4
A or B || C
A= $ENV{"USER"}B= $ENV{"LOGNAME"}C= getpwuid $<
ABCresult
1XX1
01X1
0011
0000
233 1 required => 1,
234 documentation =>
235 q{This defaults to your current user ID. This can only be changed if running as an admin user}
236 );
237  
238 =head3 procs
239  
240 Total number of concurrent running tasks.
241  
242 Analagous to parallel --jobs i
243  
244 =cut
245  
246 option 'procs' => (
247 is => 'rw',
248 isa => 'Int',
249 default => 1,
250 required => 0,
251 documentation =>
252 q{Total number of concurrently running jobs allowed at any time.},
253 trigger => sub {
254 0 ▶ my $self = shift;
Subroutine __ANON__: not called CC=1 SCAR=6.9
255 0 $self->ntasks_per_node( $self->procs );
256 }
257 1 );
258  
259 =head3 template_file
260  
261 actual template file
262  
263 One is generated here for you, but you can always supply your own with
264 --template_file /path/to/template
265  
266 Default is for SLURM
267  
268 =cut
269  
270 has 'template_file' => (
271 is => 'rw',
272 isa => 'Str',
273 default => sub {
274 0 ▶ my $self = shift;
Subroutine __ANON__: not called CC=1 SCAR=6.9
275  
276 0 my ( $fh, $filename ) = tempfile();
277  
278 0 my $tt = <<EOF;
279 #!/usr/bin/env bash
280 #
281 #SBATCH --share
282 #SBATCH --job-name=[% JOBNAME %]
283 #SBATCH --output=[% OUT %]
284 [% IF job.has_account %]
285 #SBATCH --account=[% job.account %]
286 [% END %]
287 [% IF job.has_partition %]
288 #SBATCH --partition=[% job.partition %]
289 [% END %]
290 [% IF job.has_nodes_count %]
291 #SBATCH --nodes=[% job.nodes_count %]
292 [% END %]
293 [% IF job.has_ntasks %]
294 #SBATCH --ntasks=[% job.ntasks %]
295 [% END %]
296 [% IF job.has_cpus_per_task %]
297 #SBATCH --cpus-per-task=[% job.cpus_per_task %]
298 [% END %]
299 [% IF job.has_ntasks_per_node %]
300 #SBATCH --ntasks-per-node=[% job.ntasks_per_node %]
301 [% END %]
302 [% IF job.has_mem %]
303 #SBATCH --mem=[% job.mem %]
304 [% END %]
305 [% IF job.has_walltime %]
306 #SBATCH --time=[% job.walltime %]
307 [% END %]
308 [% IF ARRAY_STR %]
309 #SBATCH --array=[% ARRAY_STR %]
310 [% END %]
311 [% IF AFTEROK %]
312 #SBATCH --dependency=afterok:[% AFTEROK %]
313 [% END %]
314  
315 [% IF MODULES %]
316 module load [% MODULES %]
317 [% END %]
318  
319 [% IF job.has_conda_env %]
320 source activate [% job.conda_env %]
321 [% END %]
322  
323 [% COMMAND %]
324  
325 EOF
326  
327 0 print $fh $tt;
328 0 return $filename;
329 },
330 1 predicate => 'has_template_file',
331 clearer => 'clear_template_file',
332 documentation =>
333 q{Path to Scheduler template file if you do not wish to use the default.}
334 );
335  
336  
337  
338 1 1;
« blib/lib/HPC/Runner/Command/submit_jobs/Plugin/Dummy.pm ↑ Summary blib/lib/HPC/Runner/Command/submit_jobs/Utils/Scheduler/JobStats.pm »