Skip to content

Commit 1dac981

Browse files
authored
Allow users to specify only two types of resource for WQEX when autolabel=True (#1881)
* WQ resource spec checking logic * refactor the if check for resource spec * fix test
1 parent 8f7c2db commit 1dac981

File tree

2 files changed

+17
-25
lines changed

2 files changed

+17
-25
lines changed

parsl/executors/workqueue/executor.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -336,28 +336,30 @@ def submit(self, func, resource_specification, *args, **kwargs):
336336
if resource_specification and isinstance(resource_specification, dict):
337337
logger.debug("Got resource specification: {}".format(resource_specification))
338338

339-
acceptable_resource_types = ['cores', 'memory', 'disk']
340-
keys = list(resource_specification.keys())
341-
if len(keys) != 3:
342-
logger.error("Task resource specification requires "
339+
acceptable_resource_types = set(['cores', 'memory', 'disk'])
340+
keys = set(resource_specification.keys())
341+
if self.autolabel:
342+
if not keys.issubset(acceptable_resource_types):
343+
logger.error("Task resource specification only accepts "
344+
"three types of resources: cores, memory, and disk")
345+
raise ExecutorError(self, "Task resource specification only accepts "
346+
"three types of resources: cores, memory, and disk")
347+
348+
elif keys != acceptable_resource_types:
349+
logger.error("Running with `autolabel=False`. In this mode, "
350+
"task resource specification requires "
343351
"three resources to be specified simultaneously: cores, memory, and disk")
344352
raise ExecutorError(self, "Task resource specification requires "
345353
"three resources to be specified simultaneously: cores, memory, and disk, "
346-
"and only takes these three resource types.")
347-
348-
if not all(k.lower() in acceptable_resource_types for k in keys):
349-
logger.error("Task resource specification only accepts "
350-
"three types of resources: cores, memory, and disk")
351-
raise ExecutorError(self, "Task resource specification requires "
352-
"three resources to be specified simultaneously: cores, memory, and disk, "
353-
"and only takes these three resource types.")
354+
"and only takes these three resource types, when running with `autolabel=False`. "
355+
"Try setting autolabel=True if you are unsure of the resource usage")
354356

355357
for k in keys:
356-
if k.lower() == 'cores':
358+
if k == 'cores':
357359
cores = resource_specification[k]
358-
elif k.lower() == 'memory':
360+
elif k == 'memory':
359361
memory = resource_specification[k]
360-
elif k.lower() == 'disk':
362+
elif k == 'disk':
361363
disk = resource_specification[k]
362364

363365
self.task_counter += 1

parsl/tests/test_error_handling/test_resource_spec.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,6 @@ def test_resource(n=2):
4141
except Exception as e:
4242
assert isinstance(e, ExecutorError)
4343

44-
# Correct specification, case insensitive
45-
spec = {'COREs': 2, 'MEMory': 1000, 'Disk': 1000}
46-
fut = double(n, parsl_resource_specification=spec)
47-
try:
48-
fut.result()
49-
except UnsupportedFeatureError:
50-
assert not isinstance(executor, WorkQueueExecutor)
51-
else:
52-
assert isinstance(executor, WorkQueueExecutor)
53-
5444

5545
if __name__ == '__main__':
5646
local_config = config

0 commit comments

Comments
 (0)