Parse a dictionary of resources into a string of SGE options.
Parameters: |
-
resources
(dict )
–
A dictionary of resources to request for the job.
|
TODO: implement dependency handling
Source code in ribbon/batch/queue_utils.py
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167 | def parse_sge_resources(resources, dependency_type=None):
"""
Parse a dictionary of resources into a string of SGE options.
Args:
resources (dict): A dictionary of resources to request for the job.
Returns:
str: A string of SGE options
TODO: implement dependency handling
"""
resource_mappings = {
'time': '-l h_rt',
'mem': '-l mem_free',
'dependency': '-hold_jid',
'gpus': '-l gpu',
'job-name': '-N',
'output': '-o',
'queue': '-q',
'node-name': '-l hostname',
# Add other resource mappings as needed
}
# Parse dependencies:
if 'dependency' in resources:
dependencies = resources['dependency']
if isinstance(dependencies, list):
dependencies = ','.join([str(job_id) for job_id in dependencies])
resources['dependency'] = dependencies
resources_list = []
for key, value in resources.items():
if key == 'dependency':
# Handle dependencies specifically
resources_list.append(f"-hold_jid {value}")
else:
if key not in resource_mappings:
print(f"Warning: Unrecognized resource key: {key}. Skipping.")
continue
sge_option = resource_mappings.get(key)
if sge_option:
if sge_option.startswith('-l'):
resources_list.append(f"{sge_option}={value}")
else:
resources_list.append(f"{sge_option} {value}")
else:
# For unrecognized keys, assume they are '-l key=value'
resources_list.append(f"-l {key}={value}")
resources_string = ' '.join(resources_list)
return resources_string
|