Skip to content

Commit

Permalink
Fix error handler to prevent exceeding niter_max (#54)
Browse files Browse the repository at this point in the history
Fixes #48 

The binary `hp.x` has an hard coded maximum for `niter_max` of 500, and
the error handler wasn't taking this into account, resulting in calculation failures.
The `convergence_not_reached` handler is now adapted to only change `alpha_mix`. 
`niter_max`, `nmix` and `alpha_mix` are also now sensibly defined in the protocol.

Co-authored-by: Timo Reents <[email protected]>
Co-authored-by: Lorenzo <[email protected]>
  • Loading branch information
3 people authored Dec 8, 2023
1 parent 8ef3b5b commit 296ba48
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 14 deletions.
11 changes: 2 additions & 9 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,13 +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:
parameters['niter_max'] *= self.defaults.delta_factor_niter_max
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
3 changes: 3 additions & 0 deletions tests/workflows/protocols/hp/test_base/test_default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ hp:
withmpi: true
parameters:
INPUTHP:
alpha_mix(1): 0.4
conv_thr_chi: 5.0e-06
niter_max: 200
nmix: 8
qpoints:
- - 2
- 2
Expand Down
3 changes: 3 additions & 0 deletions tests/workflows/protocols/hp/test_main/test_default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ hp:
withmpi: true
parameters:
INPUTHP:
alpha_mix(1): 0.4
conv_thr_chi: 5.0e-06
niter_max: 200
nmix: 8
settings:
parent_folder_symlink: true
parallelize_atoms: true
Expand Down
3 changes: 3 additions & 0 deletions tests/workflows/protocols/test_hubbard/test_default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ hubbard:
withmpi: true
parameters:
INPUTHP:
alpha_mix(1): 0.4
conv_thr_chi: 5.0e-06
niter_max: 200
nmix: 8
settings:
parent_folder_symlink: true
parallelize_atoms: true
Expand Down

0 comments on commit 296ba48

Please sign in to comment.