From fd6e7927ed56c9cc479749f1981266f06e2f5c25 Mon Sep 17 00:00:00 2001 From: t-reents Date: Fri, 7 Jun 2024 14:32:59 +0200 Subject: [PATCH] Fix maximum number of iterations reached In the current implementation of the `PwRelaxWorkChain`, an error is raised if the maximum number of iterations is reached. This check is located in the `should_run_relax` method. In case this error is raised, it is ignored as the method is called in a `while_` loop which expects a boolean argument (https://github.com/aiidateam/plumpy/blob/master/src/plumpy/workchains.py#L395-L399). Therefore, the statement is moved to the `inspect_relax` method. --- src/aiida_quantumespresso/workflows/pw/relax.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/aiida_quantumespresso/workflows/pw/relax.py b/src/aiida_quantumespresso/workflows/pw/relax.py index b6198a703..cddd4b6bb 100644 --- a/src/aiida_quantumespresso/workflows/pw/relax.py +++ b/src/aiida_quantumespresso/workflows/pw/relax.py @@ -254,11 +254,6 @@ def should_run_relax(self): self.report('Meta-convergence disabled: workchain completed after a single iteration.') return False - # Stop if the maximum number of meta iterations has been reached - if self.ctx.iteration == self.inputs.max_meta_convergence_iterations.value: - self.report('Maximum number of meta convergence iterations reached.') - return self.exit_codes.ERROR_MAX_ITERATIONS_EXCEEDED - base_relax_workchain = self.ctx.base_relax_workchains[-1] # If the last work chain still found Pulay stresses in the final SCF, continue @@ -343,6 +338,12 @@ def inspect_relax(self): # Set relaxed structure as input structure for next iteration self.ctx.current_structure = structure self.ctx.current_number_of_bands = workchain.outputs.output_parameters.get_dict()['number_of_bands'] + + # Stop if the maximum number of meta iterations has been reached + if self.ctx.meta_convergence and self.ctx.iteration == self.inputs.max_meta_convergence_iterations.value: + self.report('Maximum number of meta convergence iterations reached.') + return self.exit_codes.ERROR_MAX_ITERATIONS_EXCEEDED + def results(self): """Attach the output parameters and structure of the last workchain to the outputs."""