Skip to content

Commit

Permalink
apply reviewer suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
mbercx committed May 6, 2023
1 parent 75b5cb5 commit 0c8c48a
Show file tree
Hide file tree
Showing 21 changed files with 41 additions and 33 deletions.
2 changes: 2 additions & 0 deletions src/aiida_quantumespresso/calculations/namelists.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ def define(cls, spec):
message='The retrieved folder did not contain the required stdout output file.')
spec.exit_code(310, 'ERROR_OUTPUT_STDOUT_READ',
message='The stdout output file could not be read.')
spec.exit_code(311, 'ERROR_OUTPUT_STDOUT_PARSE',
message='The stdout output file could not be parsed.')
spec.exit_code(312, 'ERROR_OUTPUT_STDOUT_INCOMPLETE',
message='The stdout output file was incomplete probably because the calculation got interrupted.')
# yapf: enable
Expand Down
2 changes: 0 additions & 2 deletions src/aiida_quantumespresso/calculations/pw2gw.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ def define(cls, spec):

spec.exit_code(305, 'ERROR_OUTPUT_FILES',
message='The eps*.dat output files could not be read or parsed.')
spec.exit_code(311, 'ERROR_OUTPUT_STDOUT_PARSE',
message='The stdout output file could not be parsed.')
spec.exit_code(330, 'ERROR_OUTPUT_FILES_INVALID_FORMAT',
message='The eps*.dat output files do not have the expected shape (N, 2).')
spec.exit_code(331, 'ERROR_OUTPUT_FILES_ENERGY_MISMATCH',
Expand Down
20 changes: 13 additions & 7 deletions src/aiida_quantumespresso/parsers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
All `Parser` implementations in `aiida-quantumespresso` must use this base class, not `aiida.parsers.Parser`.
"""
import abc
import re
import typing

Expand All @@ -15,7 +16,7 @@
__all__ = ('BaseParser',)


class BaseParser(Parser): # pylint: disable=abstract-method
class BaseParser(Parser, metaclass=abc.ABCMeta):
"""Custom ``Parser`` class for ``aiida-quantumespresso`` parser implementations."""

class_error_map = {}
Expand All @@ -38,12 +39,12 @@ def get_error_map(cls):

@classmethod
def get_warning_map(cls):
"""The full error map of the parser class."""
"""The full warning map of the parser class."""
warning_map = cls.base_warning_map.copy()
warning_map.update(cls.class_warning_map)
return warning_map

def _retrieve_parse_stdout(self, **kwargs) -> typing.Tuple[str, dict, AttributeDict]:
def _parse_stdout_from_retrieved(self, **kwargs) -> typing.Tuple[str, dict, AttributeDict]:
"""Retrieve and parse the ``stdout`` content of a Quantum ESPRESSO calculation.
:returns: size 3 tuple with the stdout content, parsed data and log messages
Expand All @@ -63,10 +64,15 @@ def _retrieve_parse_stdout(self, **kwargs) -> typing.Tuple[str, dict, AttributeD
logs.error.append('ERROR_OUTPUT_STDOUT_READ')
return {}, logs

parsed_data, stdout_logs = self.parse_stdout(stdout, **kwargs)
try:
parsed_data, stdout_logs = self.parse_stdout(stdout, **kwargs)
except Exception as exception:
logs.error.append('ERROR_OUTPUT_STDOUT_PARSE')
logs.error.append(exception)
return {}, logs

for log_type, log_items in stdout_logs.items():
logs[log_type].extend(log_items)
for log_level, log_items in stdout_logs.items():
logs[log_level].extend(log_items)

return parsed_data, logs

Expand All @@ -85,7 +91,7 @@ def parse_stdout(cls, stdout: str) -> typing.Tuple[dict, AttributeDict]:
if not re.search(r'JOB DONE', stdout):
logs.error.append('ERROR_OUTPUT_STDOUT_INCOMPLETE')

code_match = re.search(r'Program\s(?P<code_name>[A-Z|\_|\d]+)\sv\.(?P<code_version>[\d\.|a-z|A-Z]+)\s', stdout)
code_match = re.search(r'Program\s(?P<code_name>[A-Z|\_|\d]+)\s(?P<code_version>v\.[\d\.|a-z|A-Z]+)\s', stdout)

if code_match:

Expand Down
2 changes: 1 addition & 1 deletion src/aiida_quantumespresso/parsers/dos.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class DosParser(BaseParser):

def parse(self, **kwargs):
"""Parse the retrieved files of a ``DosCalculation`` into output nodes."""
parsed_stdout, logs_stdout = self._retrieve_parse_stdout()
parsed_stdout, logs_stdout = self._parse_stdout_from_retrieved()
self._emit_logs(logs_stdout)

self.out('output_parameters', Dict(dict=parsed_stdout))
Expand Down
2 changes: 1 addition & 1 deletion src/aiida_quantumespresso/parsers/matdyn.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class MatdynParser(BaseParser):

def parse(self, **kwargs):
"""Parse the retrieved files from a ``MatdynCalculation`` into output nodes."""
parsed_stdout, logs_stdout = self._retrieve_parse_stdout()
parsed_stdout, logs_stdout = self._parse_stdout_from_retrieved()
self._emit_logs(logs_stdout)

self.out('output_parameters', orm.Dict(parsed_stdout))
Expand Down
8 changes: 4 additions & 4 deletions src/aiida_quantumespresso/parsers/neb.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def parse(self, **kwargs):
pw_input_dict = self.node.inputs.pw.parameters.get_dict()

# First parse the Neb output
parsed_stdout, logs_stdout = self._retrieve_parse_stdout()
parsed_stdout, logs_stdout = self._parse_stdout_from_retrieved()
self._emit_logs(logs_stdout)
iteration_data = parsed_stdout.pop('iteration_data')

Expand Down Expand Up @@ -147,9 +147,9 @@ def parse(self, **kwargs):
cells.append(structure_data.cell)

# Add also PW warnings and errors to the neb output data, avoiding repetitions.
for log_type in ['warning', 'error']:
for message in logs_stdout[log_type]:
formatted_message = f'{log_type}: {message}'
for log_level in ['warning', 'error']:
for message in logs_stdout[log_level]:
formatted_message = f'{log_level}: {message}'
if formatted_message not in parsed_stdout['warnings']:
parsed_stdout['warnings'].append(formatted_message)

Expand Down
8 changes: 5 additions & 3 deletions src/aiida_quantumespresso/parsers/ph.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ def parse(self, **kwargs):

dynmat_files.append(self.retrieved.base.repository.get_object_content(os.path.join(dynmat_folder, filename)))

parsed_stdout, logs_stdout = self._retrieve_parse_stdout(tensor_file=tensor_file, dynmat_files=dynmat_files)
parsed_stdout, logs_stdout = self._parse_stdout_from_retrieved(
tensor_file=tensor_file, dynmat_files=dynmat_files
)
self._emit_logs(logs_stdout)
self.out('output_parameters', orm.Dict(dict=parsed_stdout))

Expand Down Expand Up @@ -71,7 +73,7 @@ def parse_stdout(cls, stdout: str, tensor_file: str, dynmat_files: list) -> tupl
parsed_data, logs = parse_stdout(stdout, tensor_file, dynmat_files)

parsed_data.update(parsed_base)
for log_type, log_items in logs_base.items():
logs[log_type].extend(log_items)
for log_level, log_items in logs_base.items():
logs[log_level].extend(log_items)

return parsed_data, logs
2 changes: 1 addition & 1 deletion src/aiida_quantumespresso/parsers/pp.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class PpParser(BaseParser):

def parse(self, **kwargs):
"""Parse the retrieved files of a ``PpCalculation`` into output nodes."""
parsed_stdout, logs_stdout = self._retrieve_parse_stdout()
parsed_stdout, logs_stdout = self._parse_stdout_from_retrieved()
self._emit_logs(logs_stdout)

self.out('output_parameters', orm.Dict(dict=parsed_stdout))
Expand Down
2 changes: 1 addition & 1 deletion src/aiida_quantumespresso/parsers/projwfc.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ def parse(self, **kwargs):
# we create a dictionary the progressively accumulates more info
out_info_dict = {}

parsed_stdout, logs_stdout = self._retrieve_parse_stdout(out_info_dict=out_info_dict)
parsed_stdout, logs_stdout = self._parse_stdout_from_retrieved(out_info_dict=out_info_dict)
self._emit_logs(logs_stdout)
self.out('output_parameters', Dict(dict=parsed_stdout))

Expand Down
2 changes: 1 addition & 1 deletion src/aiida_quantumespresso/parsers/pw2gw.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def parse(self, **kwargs):
permanently in the repository. The second required node is a filepath under the key
``retrieved_temporary_files`` which should contain the temporary retrieved files.
"""
parsed_stdout, logs_stdout = self._retrieve_parse_stdout()
parsed_stdout, logs_stdout = self._parse_stdout_from_retrieved()
self._emit_logs(logs_stdout)

self.out('output_parameters', Dict(dict=parsed_stdout))
Expand Down
2 changes: 1 addition & 1 deletion src/aiida_quantumespresso/parsers/pw2wannier90.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def parse(self, **kwargs):
Two nodes that are expected are the default 'retrieved' ``FolderData`` node which will store the retrieved files
permanently in the repository.
"""
parsed_stdout, logs_stdout = self._retrieve_parse_stdout()
parsed_stdout, logs_stdout = self._parse_stdout_from_retrieved()
self._emit_logs(logs_stdout)

self.out('output_parameters', Dict(parsed_stdout))
Expand Down
2 changes: 1 addition & 1 deletion src/aiida_quantumespresso/parsers/q2r.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Q2rParser(BaseParser):

def parse(self, **kwargs):
"""Parse the retrieved files of a ``Q2rCalculation`` into output nodes."""
parsed_stdout, logs_stdout = self._retrieve_parse_stdout()
parsed_stdout, logs_stdout = self._parse_stdout_from_retrieved()
self._emit_logs(logs_stdout)

self.out('output_parameters', Dict(parsed_stdout))
Expand Down
2 changes: 1 addition & 1 deletion tests/parsers/test_dos/test_dos_default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ dos:
- states/eV
- states/eV
parameters:
code_version: 6.4.1
code_version: v.6.4.1
wall_time: 0.41s
wall_time_seconds: 0.41
2 changes: 1 addition & 1 deletion tests/parsers/test_matdyn/test_matdyn_default.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
output_parameters:
code_version: '6.1'
code_version: v.6.1
wall_time: 0.00s
wall_time_seconds: 0.0
output_phonon_bands:
Expand Down
4 changes: 2 additions & 2 deletions tests/parsers/test_neb.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def test_neb_default(fixture_localhost, generate_calc_job_node, generate_parser,

assert calcfunction.is_finished, calcfunction.exception
assert calcfunction.is_finished_ok, calcfunction.exit_message
assert not orm.Log.collection.get_logs_for(node)
assert not [log for log in orm.Log.objects.get_logs_for(node) if log.levelname == 'ERROR']
assert 'output_parameters' in results
assert 'output_mep' in results
assert 'output_trajectory' in results
Expand Down Expand Up @@ -89,7 +89,7 @@ def test_neb_all_iterations(

assert calcfunction.is_finished, calcfunction.exception
assert calcfunction.is_finished_ok, calcfunction.exit_message
assert not orm.Log.collection.get_logs_for(node)
assert not [log for log in orm.Log.objects.get_logs_for(node) if log.levelname == 'ERROR']
assert 'output_parameters' in results
assert 'output_mep' in results
assert 'output_trajectory' in results
Expand Down
2 changes: 1 addition & 1 deletion tests/parsers/test_neb/test_neb_default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ parameters:
ci_scheme: auto
climbing_image_auto:
- 1
code_version: 6.4.1
code_version: v.6.4.1
converged:
- true
- 13
Expand Down
2 changes: 1 addition & 1 deletion tests/parsers/test_ph/test_ph_default_default_.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
code_version: '6.1'
code_version: v.6.1
dielectric_constant:
- - 57.36256076907993
- -2.842170943040401e-14
Expand Down
2 changes: 1 addition & 1 deletion tests/parsers/test_ph/test_ph_not_converged.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
code_version: '6.1'
code_version: v.6.1
number_of_atoms: 2
number_of_irr_representations_for_each_q:
- 2
Expand Down
2 changes: 1 addition & 1 deletion tests/parsers/test_ph/test_ph_out_of_walltime.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
code_version: 6.3MaX
code_version: v.6.3MaX
number_of_atoms: 2
number_of_irr_representations_for_each_q:
- 2
Expand Down
2 changes: 1 addition & 1 deletion tests/parsers/test_pw2gw/test_pw2gw_default_data.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
output_parameters:
code_version: '6.2'
code_version: v.6.2
wall_time: 1m26.21s
wall_time_seconds: 86.21000000000001
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
parameters:
code_version: 6.4.1
code_version: v.6.4.1
wall_time: 2.18s
wall_time_seconds: 2.18

0 comments on commit 0c8c48a

Please sign in to comment.