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

PwBaseWorkChain: do no assume output_band exists in band sanity check #544

Merged
merged 1 commit into from
Aug 6, 2020
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
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