From 1f554939c373378ee4d1edf0fc8dc05a480e4ae1 Mon Sep 17 00:00:00 2001 From: bastonero Date: Wed, 26 Jun 2024 22:06:27 +0000 Subject: [PATCH] Address review 2 --- .../parsers/parse_raw/ph.py | 25 +++++++++---------- src/aiida_quantumespresso/parsers/ph.py | 7 +++--- .../test_ph/test_ph_initialization.yml | 25 ------------------- 3 files changed, 16 insertions(+), 41 deletions(-) diff --git a/src/aiida_quantumespresso/parsers/parse_raw/ph.py b/src/aiida_quantumespresso/parsers/parse_raw/ph.py index 636e17d6d..2dc2d5ddb 100644 --- a/src/aiida_quantumespresso/parsers/parse_raw/ph.py +++ b/src/aiida_quantumespresso/parsers/parse_raw/ph.py @@ -442,16 +442,16 @@ def parse_ph_dynmat(data, logs, lattice_parameter=None, also_eigenvectors=False, return parsed_data -def parse_initialization_qpoints(stdout: str) -> tuple[dict, bool]: +def parse_initialization_qpoints(stdout: str) -> dict: """Return the number of q-points from an initialization run. Here, the initialization run refers to the one performed by specifying `start_irr` and `last_irr` to 0 in the inputs. - :return: (parsed dictionary, error found), the last is a boolean - regarding whether an expected quantity has not been properly - parse; it also checks that the number of q-points parsed within - parenthesis and the amount of q-points parsed from coordinaes coincide. + :return: parsed dictionary + + :raise: `RuntimeError` if the number of q-points cannot be parsed or it + differs from the number of q-points in the stdout list. """ import re @@ -462,6 +462,8 @@ def parse_initialization_qpoints(stdout: str) -> tuple[dict, bool]: match = re.search(pattern, stdout) if match: parameters.update({'number_of_qpoints': int(match.group(1))}) + else: + raise RuntimeError('the number of q-points cannot be parsed') # Regular expression pattern to match the q-points section pattern = r'\(\s*\d+\s*q-points\):\s*\n\s*N\s*xq\(1\)\s*xq\(2\)\s*xq\(3\)\s*\n((?:\s*\d+\s*[\d\.\-\s]+\n?)*)' @@ -475,13 +477,10 @@ def parse_initialization_qpoints(stdout: str) -> tuple[dict, bool]: coords = re.findall(coord_pattern, q_points_block) # Find all coordinates in the block q_points = [list(map(float, coord)) for coord in coords] + else: + raise RuntimeError('the list of q-points cannot be parsed') - parameters.update({'q_points': q_points}) - - if 'number_of_qpoints' not in parameters and 'q_points' not in parameters: - return parameters, False - - if parameters['number_of_qpoints'] != len(parameters['q_points']): - return parameters, False + if parameters['number_of_qpoints'] != len(q_points): + raise RuntimeError('the number of q-points do not coincde with the number of listed q-points') - return parameters, True + return parameters diff --git a/src/aiida_quantumespresso/parsers/ph.py b/src/aiida_quantumespresso/parsers/ph.py index abe6d6b3e..5b8fc3d25 100644 --- a/src/aiida_quantumespresso/parsers/ph.py +++ b/src/aiida_quantumespresso/parsers/ph.py @@ -44,11 +44,12 @@ def parse(self, **kwargs): # When `start_irr` and `last_irr` are set to 0, `JOB DONE` is not in stdout (expected behaviour). # Though, we at least expect that `stdout` is not empty, otherwise something went wrong. if stdout and _is_initialization(self.node.inputs.parameters.get_dict()): - parameters, parsed_ok = parse_initialization_qpoints(stdout) - if parsed_ok: + try: + parameters = parse_initialization_qpoints(stdout) self.out('output_parameters', orm.Dict(parameters)) return - # we let it go, as it should exit with STDOUT_INCOMPLETE or similar + except RuntimeError as exc: + logs.error.append('ERROR_OUTPUT_STDOUT_INCOMPLETE') # If the scheduler detected OOW, simply keep that exit code by not returning anything more specific. if self.node.exit_status == PhCalculation.exit_codes.ERROR_SCHEDULER_OUT_OF_WALLTIME: diff --git a/tests/parsers/test_ph/test_ph_initialization.yml b/tests/parsers/test_ph/test_ph_initialization.yml index 5a62dd333..1945c22a3 100644 --- a/tests/parsers/test_ph/test_ph_initialization.yml +++ b/tests/parsers/test_ph/test_ph_initialization.yml @@ -1,26 +1 @@ number_of_qpoints: 8 -q_points: -- - 0.0 - - 0.0 - - 0.0 -- - 0.0 - - 0.0 - - -0.061660223 -- - 0.0 - - -0.577350269 - - 0.0 -- - 0.0 - - -0.577350269 - - -0.061660223 -- - -0.5 - - -0.288675135 - - 0.0 -- - -0.5 - - -0.288675135 - - -0.061660223 -- - -0.5 - - -0.866025404 - - 0.0 -- - -0.5 - - -0.866025404 - - -0.061660223