Skip to content

Commit

Permalink
Do not exit if exit_code is 0 (#11)
Browse files Browse the repository at this point in the history
* Do not exit if exit_code is 0
* remove the calculator as it may not be JSON serializable
  • Loading branch information
superstar54 authored Dec 14, 2024
1 parent 88d7117 commit 1cfe56f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/aiida_pythonjob/data/atoms.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ def __init__(self, value=None, **kwargs):

@classmethod
def atoms2dict(cls, atoms):
"""Convert ASE Atoms to a dictionary."""
# we remove the calculator as it may not be JSON serializable
atoms.calc = None
data = atoms2dict(atoms)
data.pop("unique_id")
keys = list(data.keys())
Expand Down
5 changes: 3 additions & 2 deletions src/aiida_pythonjob/parsers/pythonjob.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,14 @@ def parse(self, **kwargs):
top_level_output_list[i]["value"] = self.serialize_output(results[i], top_level_output_list[i])
elif isinstance(results, dict):
# pop the exit code if it exists
exit_code = results.pop("exit_code", 0)
exit_code = results.pop("exit_code", None)
if exit_code:
if isinstance(exit_code, dict):
exit_code = ExitCode(exit_code["status"], exit_code["message"])
elif isinstance(exit_code, int):
exit_code = ExitCode(exit_code)
return exit_code
if exit_code.status != 0:
return exit_code
if len(top_level_output_list) == 1:
# if output name in results, use it
if top_level_output_list[0]["name"] in results:
Expand Down
7 changes: 7 additions & 0 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ def test_dict_result_only_show_one_output(fixture_localhost):


def test_exit_code(fixture_localhost):
result = {"a": 1, "exit_code": {"status": 0, "message": ""}}
function_data = {"outputs": [{"name": "a"}]}
parser = create_parser(result, function_data)
exit_code = parser.parse()
assert exit_code is None
assert parser.outputs["a"] == 1
#
result = {"exit_code": {"status": 1, "message": "error"}}
function_data = {"outputs": [{"name": "a"}, {"name": "b"}, {"name": "c"}]}
parser = create_parser(result, function_data)
Expand Down

0 comments on commit 1cfe56f

Please sign in to comment.