Skip to content

Commit c800d27

Browse files
authored
Merge pull request #51 from tilde-lab/aiida
Generalize AiiDA integration w.r.t. supported engines
2 parents c3ede98 + 3580ecb commit c800d27

File tree

2 files changed

+33
-16
lines changed

2 files changed

+33
-16
lines changed

yascheduler/aiida_plugin.py

+12-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
"""
2-
Aiida plugin for yascheduler
2+
Aiida plugin for yascheduler,
3+
with respect to the supported yascheduler engines
34
"""
45

56
import aiida.schedulers
67
from aiida.schedulers.datastructures import JobState, JobInfo, NodeNumberJobResource
8+
from aiida.orm import load_node
9+
710

811
_MAP_STATUS_YASCHEDULER = {
912
"QUEUED": JobState.QUEUED,
@@ -67,12 +70,15 @@ def _get_submit_script_header(self, job_tmpl):
6770
Return the submit script header, using the parameters from the
6871
job_tmpl.
6972
"""
70-
lines = []
73+
aiida_code = load_node(job_tmpl.codes_info[0]['code_uuid'])
74+
75+
# We map the lowercase code labels onto yascheduler engines,
76+
# so that the required input file(s) can be deduced
77+
lines = ["ENGINE={}".format(aiida_code.label.lower())]
78+
7179
if job_tmpl.job_name:
7280
lines.append("LABEL={}".format(job_tmpl.job_name))
7381

74-
# TODO too specific for engine.pcrystal
75-
lines += ["INPUT=INPUT", "STRUCT=fort.34"]
7682
return "\n".join(lines)
7783

7884
def _get_submit_command(self, submit_script):
@@ -88,7 +94,8 @@ def _parse_submit_output(self, retval, stdout, stderr):
8894
"""
8995
if stderr.strip():
9096
self.logger.warning("Stderr when submitting: {}".format(stderr.strip()))
91-
return stdout.split(":")[1].strip()
97+
98+
return stdout.strip()
9299

93100
def _parse_joblist_output(self, retval, stdout, stderr):
94101
"""

yascheduler/utils.py

+21-11
Original file line numberDiff line numberDiff line change
@@ -17,33 +17,43 @@
1717

1818

1919
def submit():
20-
parser = argparse.ArgumentParser(description="Submit task to yascheduler daemon")
20+
parser = argparse.ArgumentParser(description="Submit task to yascheduler via AiiDA script")
2121
parser.add_argument("script")
2222

2323
args = parser.parse_args()
2424
if not os.path.isfile(args.script):
2525
raise ValueError("Script parameter is not a file name")
2626

27-
inputs = {}
27+
script_params = {}
2828
with open(args.script) as f:
2929
for l in f.readlines():
3030
try:
3131
k, v = l.split("=")
32-
inputs[k.strip()] = v.strip()
32+
script_params[k.strip()] = v.strip()
3333
except ValueError:
3434
pass
35+
36+
label = script_params.get('LABEL', 'AiiDA job')
37+
options = {
38+
"local_folder": os.getcwd()
39+
}
40+
if not script_params.get('ENGINE'):
41+
raise ValueError("Script has not defined an engine")
42+
3543
config = ConfigParser()
3644
config.read(CONFIG_FILE)
3745
yac = Yascheduler(config)
38-
task_id = yac.queue_submit_task(
39-
inputs["LABEL"],
40-
{
41-
"structure": open(inputs["STRUCT"]).read(),
42-
"input": open(inputs["INPUT"]).read(),
43-
"local_folder": os.getcwd(),
44-
},
45-
) # TODO
4646

47+
if script_params['ENGINE'] not in yac.engines:
48+
raise ValueError("Script refers to unknown engine")
49+
50+
for input_file in yac.engines[script_params['ENGINE']].input_files:
51+
if not os.path.exists(os.path.join(options["local_folder"], input_file)):
52+
raise ValueError("Script was not supplied with the required input")
53+
54+
options[input_file] = open(input_file).read()
55+
56+
task_id = yac.queue_submit_task(label, options, script_params['ENGINE'])
4757
print("Successfully submitted task: {}".format(task_id))
4858
yac.connection.close()
4959

0 commit comments

Comments
 (0)