Skip to content

Commit

Permalink
PwBaseWorkChain: do no assume output_band exists in band sanity c…
Browse files Browse the repository at this point in the history
…heck (#544)

The `output_band` output of the `PwCalculation` is optional and, for
example, when the setting `no_bands=True`, the band files will not be
retrieved and consequentially not parsed. The process handler checking
the bands `sanity_check_insufficient_bands`, however, assumed the output
node is always there. This is changed to simply skip the check if the
node is not there.

Note that we do not check in the workchain whether the output should
have been there, because the sanity check is only triggered for
successful calculations, and if the output should have been there, the
calculation should have been failed. If this is not the case, that is a
bug in the parser and should be addressed there.
  • Loading branch information
sphuber authored Aug 6, 2020
1 parent cdd212f commit 61fe3b4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
10 changes: 8 additions & 2 deletions aiida_quantumespresso/workflows/pw/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ def run_init(self):
inputs = prepare_process_inputs(PwCalculation, inputs)
running = self.submit(PwCalculation, **inputs)

self.report('launching initialization {}<{}>'.format(running.pk, self._process_class.__name__))
self.report('launching initialization {}<{}>'.format(running.pk, self.ctx.process_name))

return ToContext(calculation_init=running)

Expand Down Expand Up @@ -336,9 +336,15 @@ def sanity_check_insufficient_bands(self, calculation):

try:
bands = calculation.outputs.output_band
except AttributeError:
args = [self.ctx.process_name, calculation.pk]
self.report('{}<{}> does not have `output_band` output, skipping sanity check.'.format(*args))
return

try:
get_highest_occupied_band(bands)
except ValueError as exception:
args = [self._process_class.__name__, calculation.pk]
args = [self.ctx.process_name, calculation.pk]
self.report('{}<{}> run with smearing and highest band is occupied'.format(*args))
self.report('BandsData<{}> has invalid occupations: {}'.format(bands.pk, exception))
self.report('{}<{}> had insufficient bands'.format(calculation.process_label, calculation.pk))
Expand Down
14 changes: 12 additions & 2 deletions tests/workflows/pw/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
from plumpy import ProcessState

from aiida.common import AttributeDict
from aiida.engine import ProcessHandlerReport
from aiida.engine import ExitCode, ProcessHandlerReport
from aiida.orm import Dict

from aiida_quantumespresso.calculations.pw import PwCalculation
from aiida_quantumespresso.workflows.pw.base import PwBaseWorkChain
Expand All @@ -23,7 +24,7 @@ def _generate_workchain_pw(exit_code=None):
process = generate_workchain(entry_point, {'pw': inputs, 'kpoints': kpoints})

if exit_code is not None:
node = generate_calc_job_node()
node = generate_calc_job_node(inputs={'parameters': Dict()})
node.set_process_state(ProcessState.FINISHED)
node.set_exit_status(exit_code.status)

Expand Down Expand Up @@ -133,3 +134,12 @@ def test_handle_relax_recoverable_ionic_convergence_error(

result = process.inspect_process()
assert result.status == 0


def test_sanity_check_no_bands(aiida_profile, generate_workchain_pw):
"""Test that `sanity_check_insufficient_bands` does not except if there is no `output_band`, which is optional."""
process = generate_workchain_pw(exit_code=ExitCode(0))
process.setup()

calculation = process.ctx.children[-1]
assert process.sanity_check_insufficient_bands(calculation) is None

0 comments on commit 61fe3b4

Please sign in to comment.