Skip to content

Commit

Permalink
Fix exit status when convergence is not met (#56)
Browse files Browse the repository at this point in the history
Fixes #55

Exit status 0 was given when at the last iteration
no self-consistency (of Hubbard parameters) was
reached. This is misleading, and a new exit code is
added to highlitght better this condition.
  • Loading branch information
bastonero authored Dec 7, 2023
1 parent de596eb commit 8ef3b5b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/aiida_quantumespresso_hp/workflows/hubbard.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@ def define(cls, spec):
spec.exit_code(405, 'ERROR_NON_INTEGER_TOT_MAGNETIZATION',
message='The scf PwBaseWorkChain sub process in iteration {iteration}'\
'returned a non integer total magnetization (threshold exceeded).')

spec.exit_code(601, 'ERROR_CONVERGENCE_NOT_REACHED',
message='The Hubbard parameters did not converge at the last iteration #{iteration}')
# yapf: enable

@classmethod
Expand Down Expand Up @@ -646,9 +649,14 @@ def check_convergence(self):

def run_results(self):
"""Attach the final converged Hubbard U parameters and the corresponding structure."""
self.report(f'Hubbard parameters self-consistently converged in {self.ctx.iteration} iterations')
self.out('hubbard_structure', self.ctx.current_hubbard_structure)

if self.ctx.is_converged:
self.report(f'Hubbard parameters self-consistently converged in {self.ctx.iteration} iterations')
else:
self.report(f'Hubbard parameters did not converge at the last iteration #{self.ctx.iteration}.')
return self.exit_codes.ERROR_CONVERGENCE_NOT_REACHED.format(iteration=self.ctx.iteration)

def should_clean_workdir(self):
"""Whether to clean the work directories at each iteration."""
return self.inputs.clean_workdir.value
Expand Down
7 changes: 7 additions & 0 deletions tests/workflows/test_hubbard.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,8 @@ def test_not_converged_check_convergence(
generate_workchain_hubbard, generate_hp_workchain_node, generate_inputs_hubbard, generate_hubbard_structure
):
"""Test when `SelfConsistentHubbardWorkChain.check_convergence` is not at convergence."""
from aiida_quantumespresso_hp.workflows.hubbard import SelfConsistentHubbardWorkChain as WorkChain

inputs = generate_inputs_hubbard()
process = generate_workchain_hubbard(inputs=inputs)

Expand All @@ -391,6 +393,11 @@ def test_not_converged_check_convergence(
process.check_convergence()
assert not process.ctx.is_converged

result = process.run_results()
assert 'hubbard_structure' in process.outputs
assert process.outputs['hubbard_structure'] == process.ctx.workchains_hp[-1].outputs['hubbard_structure']
assert result == WorkChain.exit_codes.ERROR_CONVERGENCE_NOT_REACHED.format(iteration=process.ctx.iteration)


@pytest.mark.usefixtures('aiida_profile')
def test_relabel_check_convergence(
Expand Down

0 comments on commit 8ef3b5b

Please sign in to comment.