Skip to content

Commit

Permalink
Simplify convergence_not_reached handler
Browse files Browse the repository at this point in the history
Adapt the `convergence_not_reached` handler so that it only adjusts `alpha_mix`. `niter_max` is moved to the protocol.
  • Loading branch information
Timo Reents committed Dec 7, 2023
1 parent 5aa1ebf commit 6263392
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 15 deletions.
12 changes: 2 additions & 10 deletions src/aiida_quantumespresso_hp/workflows/hp/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,10 @@ def handle_computing_cholesky(self, _):

@process_handler(priority=410, exit_codes=HpCalculation.exit_codes.ERROR_CONVERGENCE_NOT_REACHED)
def handle_convergence_not_reached(self, _):
"""Handle `ERROR_CONVERGENCE_NOT_REACHED`: decrease `alpha_mix`, increase `niter_max`, and restart.
"""Handle `ERROR_CONVERGENCE_NOT_REACHED`: decrease `alpha_mix` and restart.
Since `hp.x` does not support restarting from incomplete calculations, the entire calculation will have to be
restarted from scratch. By increasing the `niter_max` and decreasing `alpha_mix` there is a chance that the next
restarted from scratch. By decreasing `alpha_mix` there is a chance that the next
run will converge. If these keys are present in the input parameters, they will be scaled by a default factor,
otherwise, a hardcoded default value will be set that is lower/higher than that of the code's default.
"""
Expand All @@ -232,14 +232,6 @@ def handle_convergence_not_reached(self, _):
parameters[parameter] = 0.20
changes.append(f'set `{parameter}` to {parameters[parameter]}')

if 'niter_max' in parameters:
# QE has a hard-coded limit of 500
parameters['niter_max'] = min(parameters['niter_max'] * self.defaults.delta_factor_niter_max, 500)
else:
parameters['niter_max'] = 200

changes.append(f"changed `niter_max` to {parameters['niter_max']}")

if changes:
self.report(f"convergence not reached: {', '.join(changes)}")
else:
Expand Down
3 changes: 3 additions & 0 deletions src/aiida_quantumespresso_hp/workflows/protocols/hp/base.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ default_inputs:
parameters:
INPUTHP:
conv_thr_chi: 5.e-6
niter_max: 200
nmix: 8
alpha_mix(1): 0.4
qpoints:
- 2
- 2
Expand Down
8 changes: 3 additions & 5 deletions tests/workflows/hp/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,9 @@ def test_handle_unrecoverable_failure(generate_workchain_hp):
@pytest.mark.parametrize(
('inputs', 'expected'),
(
({}, {'alpha_mix(1)': 0.2, 'niter_max': 200}),
({'niter_max': 5}, {'alpha_mix(1)': 0.2, 'niter_max': 10}),
({'alpha_mix(5)': 0.5}, {'alpha_mix(5)': 0.25, 'niter_max': 200}),
({'alpha_mix(5)': 0.5, 'alpha_mix(10)': 0.4}, {'alpha_mix(5)': 0.25, 'alpha_mix(10)': 0.2, 'niter_max': 200}),
({'niter_max': 1, 'alpha_mix(2)': 0.3}, {'niter_max': 2, 'alpha_mix(2)': 0.15}),
({}, {'alpha_mix(1)': 0.2}),
({'alpha_mix(5)': 0.5}, {'alpha_mix(5)': 0.25}),
({'alpha_mix(5)': 0.5, 'alpha_mix(10)': 0.4}, {'alpha_mix(5)': 0.25, 'alpha_mix(10)': 0.2}),
),
) # yapf: disable
def test_handle_convergence_not_reached(generate_workchain_hp, generate_inputs_hp, inputs, expected):
Expand Down

0 comments on commit 6263392

Please sign in to comment.