diff --git a/aiida_quantumespresso/workflows/pw/base.py b/aiida_quantumespresso/workflows/pw/base.py index d660111dd..80b2f111f 100644 --- a/aiida_quantumespresso/workflows/pw/base.py +++ b/aiida_quantumespresso/workflows/pw/base.py @@ -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) @@ -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)) diff --git a/tests/workflows/pw/test_base.py b/tests/workflows/pw/test_base.py index 4b7ab0153..e7dc83b8c 100644 --- a/tests/workflows/pw/test_base.py +++ b/tests/workflows/pw/test_base.py @@ -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 @@ -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) @@ -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