From 273ac12ad8ddcd57b67ace1afea5535257690e10 Mon Sep 17 00:00:00 2001 From: superstar54 Date: Sat, 14 Dec 2024 07:29:00 +0100 Subject: [PATCH 1/2] Do not exit if exit_code is 0 --- src/aiida_pythonjob/parsers/pythonjob.py | 5 +++-- tests/test_parser.py | 7 +++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/aiida_pythonjob/parsers/pythonjob.py b/src/aiida_pythonjob/parsers/pythonjob.py index 644cab5..26b686a 100644 --- a/src/aiida_pythonjob/parsers/pythonjob.py +++ b/src/aiida_pythonjob/parsers/pythonjob.py @@ -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: diff --git a/tests/test_parser.py b/tests/test_parser.py index ca2916c..512e002 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -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) From 16a3751c384311d5a1c7483ef0a8fd898975cf7a Mon Sep 17 00:00:00 2001 From: superstar54 Date: Sat, 14 Dec 2024 07:29:13 +0100 Subject: [PATCH 2/2] remove the calculator as it may not be JSON serializable --- src/aiida_pythonjob/data/atoms.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/aiida_pythonjob/data/atoms.py b/src/aiida_pythonjob/data/atoms.py index 262794d..946cde2 100644 --- a/src/aiida_pythonjob/data/atoms.py +++ b/src/aiida_pythonjob/data/atoms.py @@ -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())