Skip to content

Commit

Permalink
Place the --output-mode in front of job scritp (#28)
Browse files Browse the repository at this point in the history
Fixes #27

`--output-mode` option was wrongly put in the end of the submit command
which cause the problem that stdout of submit command is not json
parsable. The test was not able to catch it because the command was
defined in the test but not directly get from the scheduler. Test is
update to using the commond generated from scheduler and therefore being
tested directly.
  • Loading branch information
unkcpz authored Jul 19, 2024
1 parent 422b61d commit b8b48dd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
6 changes: 3 additions & 3 deletions aiida_hyperqueue/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def _get_submit_command(self, submit_script: str) -> str:
submit_script: the path of the submit script relative to the working
directory.
"""
submit_command = f"hq submit {submit_script} --output-mode=json"
submit_command = f"hq submit --output-mode=json {submit_script}"

self.logger.info(f"Submitting with: {submit_command}")

Expand Down Expand Up @@ -178,10 +178,10 @@ def _parse_submit_output(self, retval: int, stdout: str, stderr: str) -> str:
f"in _parse_submit_output{transport_string}: there was some text in stderr: {stderr}"
)

hq_job_dict = json.loads(stdout)
try:
hq_job_dict = json.loads(stdout)
return str(hq_job_dict["id"])
except KeyError:
except Exception:
# If no valid line is found, log and raise an error
self.logger.error(
f"in _parse_submit_output{transport_string}: unable to find the job id: {stdout}"
Expand Down
9 changes: 7 additions & 2 deletions tests/test_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ def test_submit_command():
"""Test submit command"""
scheduler = HyperQueueScheduler()

assert "hq submit job.sh" in scheduler._get_submit_command("job.sh")
assert "hq submit --output-mode=json job.sh" == scheduler._get_submit_command(
"job.sh"
)


def test_parse_submit_command_output(hq_env: HqEnv, valid_submit_script):
Expand All @@ -78,8 +80,11 @@ def test_parse_submit_command_output(hq_env: HqEnv, valid_submit_script):
hq_env.start_worker(cpus="1")
Path("_aiidasubmit.sh").write_text(valid_submit_script)

scheduler = HyperQueueScheduler()
args = scheduler._get_submit_command("_aiidasubmit.sh")
args = args.split(" ")[1:]
process = hq_env.command(
["submit", "--output-mode=json", "_aiidasubmit.sh"],
args,
wait=False,
ignore_stderr=True,
)
Expand Down

0 comments on commit b8b48dd

Please sign in to comment.