Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not exit if exit_code is 0 #11

Merged
merged 2 commits into from
Dec 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading