MCPcopy Create free account
hub / github.com/LBANN/lbann / BatchScript

Class BatchScript

python/lbann/launcher/batch_script.py:6–193  ·  view source on GitHub ↗

Utility class to write batch job scripts. This class manages a non-interactive script file that can be submitted as a batch job to an HPC job scheduler. A script is made up of two parts: the header configures the job and the body contains the actual commands to be executed. Thi

Source from the content-addressed store, hash-verified

4from lbann.util import make_iterable
5
6class BatchScript:
7 """Utility class to write batch job scripts.
8
9 This class manages a non-interactive script file that can be
10 submitted as a batch job to an HPC job scheduler. A script is made
11 up of two parts: the header configures the job and the body
12 contains the actual commands to be executed.
13
14 This particular class is not fully implemented. Derived classes
15 for specific job schedulers should implement
16 `add_parallel_command` and `submit`, maintaining the same API.
17
18 """
19
20 def __init__(self,
21 script_file=None,
22 work_dir=os.getcwd(),
23 interpreter='/bin/bash'):
24 """Construct batch script manager.
25
26 Args:
27 script_file (str): Script file.
28 work_dir (str, optional): Working directory
29 (default: current working directory).
30 interpreter (str, optional): Script interpreter
31 (default: /bin/bash).
32
33 """
34
35 # Lines in script are stored as lists of strings
36 self.header = []
37 self.body = []
38
39 # Construct file paths
40 self.work_dir = os.path.realpath(work_dir)
41 self.script_file = script_file
42 if not self.script_file:
43 self.script_file = os.path.join(self.work_dir, 'batch.sh')
44 self.script_file = os.path.realpath(self.script_file)
45 self.out_log_file = os.path.join(self.work_dir, 'out.log')
46 self.err_log_file = os.path.join(self.work_dir, 'err.log')
47
48 # Shebang line
49 if interpreter:
50 self.add_header_line('#!{}'.format(interpreter))
51
52 def add_header_line(self, line):
53 """Add line to script header.
54
55 The header should specify configuration options for the job
56 scheduler, without containing executable commands.
57
58 """
59 self.header.append(line)
60
61 def add_body_line(self, line):
62 """Add line to script body.
63

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected