Skip to content

Commit 8f1066a

Browse files
committed
👌 PwBaseWorkChain: Improve handling of SCF convergence issues
The current error handler for the `PwBaseWorkChain` that deals with SCF convergence issues only tries to reduce the `mixing-beta` by 20% each time the calculation fails, and doesn't consider the rate of convergence. Here we improve the error handling for this case by calculating the slope on the logarithm of the "scf accuracy". Based on some statistics presented in #961 We noted two points: 1. Most of the calculations that converge do so within 50 SCF steps. 2. For those that don't, there is a very low chance of convergence in case the scf accuracy slope is higher than -0.1. Hence, we: * Limit the default number of maximum steps (`electron_maxstep`) to 50. * In case of SCF convergence failure, check the scf accuracy slope. If < -0.1, do a full restart. * Else, check the `mixing_beta`. If above 0.1, half it and restart the calculation.
1 parent fc1a940 commit 8f1066a

File tree

8 files changed

+41
-20
lines changed

8 files changed

+41
-20
lines changed

‎src/aiida_quantumespresso/workflows/protocols/pw/base.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ default_inputs:
2525
smearing: cold
2626
degauss: 0.01
2727
ELECTRONS:
28-
electron_maxstep: 80
28+
electron_maxstep: 50
2929
mixing_beta: 0.4
3030
default_protocol: moderate
3131
protocols:

‎src/aiida_quantumespresso/workflows/pw/base.py‎

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,11 @@ class PwBaseWorkChain(ProtocolMixin, BaseRestartWorkChain):
2929
'qe': qe_defaults,
3030
'delta_threshold_degauss': 30,
3131
'delta_factor_degauss': 0.1,
32-
'delta_factor_mixing_beta': 0.8,
32+
'delta_factor_mixing_beta': 0.5,
3333
'delta_factor_max_seconds': 0.95,
3434
'delta_factor_nbnd': 0.05,
3535
'delta_minimum_nbnd': 4,
36+
'conv_slope_threshold': -0.1,
3637
})
3738

3839
@classmethod
@@ -563,16 +564,36 @@ def handle_electronic_convergence_not_reached(self, calculation):
563564
564565
Decrease the mixing beta and fully restart from the previous calculation.
565566
"""
566-
factor = self.defaults.delta_factor_mixing_beta
567+
import numpy
568+
569+
scf_accuracy = calculation.tools.get_scf_accuracy(0)
570+
scf_accuracy_slope = numpy.polyfit(numpy.arange(0, len(scf_accuracy)), numpy.log(scf_accuracy), 1)[0]
571+
572+
if scf_accuracy_slope < self.defaults.conv_slope_threshold:
573+
574+
action = (
575+
'electronic convergence not reached but the scf accuracy is decreasing: restart from the last '
576+
'calculation.'
577+
)
578+
self.set_restart_type(RestartType.FULL, calculation.outputs.remote_folder)
579+
self.report_error_handled(calculation, action)
580+
return ProcessHandlerReport(True)
581+
567582
mixing_beta = self.ctx.inputs.parameters.get('ELECTRONS', {}).get('mixing_beta', self.defaults.qe.mixing_beta)
568-
mixing_beta_new = mixing_beta * factor
569583

570-
self.ctx.inputs.parameters['ELECTRONS']['mixing_beta'] = mixing_beta_new
571-
action = f'reduced beta mixing from {mixing_beta} to {mixing_beta_new} and restarting from the last calculation'
584+
if mixing_beta > 0.1:
572585

573-
self.set_restart_type(RestartType.FULL, calculation.outputs.remote_folder)
574-
self.report_error_handled(calculation, action)
575-
return ProcessHandlerReport(True)
586+
mixing_beta_new = mixing_beta * self.defaults.delta_factor_mixing_beta
587+
588+
self.ctx.inputs.parameters['ELECTRONS']['mixing_beta'] = mixing_beta_new
589+
action = (
590+
f'reduced beta mixing from {mixing_beta} to {mixing_beta_new} and restarting from the last '
591+
'calculation'
592+
)
593+
594+
self.set_restart_type(RestartType.FULL, calculation.outputs.remote_folder)
595+
self.report_error_handled(calculation, action)
596+
return ProcessHandlerReport(True)
576597

577598
@process_handler(priority=420, exit_codes=[
578599
PwCalculation.exit_codes.WARNING_ELECTRONIC_CONVERGENCE_NOT_REACHED,

‎tests/workflows/protocols/pw/test_bands/test_default.yml‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ bands:
2020
conv_thr: 4.0e-10
2121
diago_full_acc: true
2222
diagonalization: paro
23-
electron_maxstep: 80
23+
electron_maxstep: 50
2424
mixing_beta: 0.4
2525
startingpot: file
2626
SYSTEM:
@@ -60,7 +60,7 @@ relax:
6060
tstress: true
6161
ELECTRONS:
6262
conv_thr: 4.0e-10
63-
electron_maxstep: 80
63+
electron_maxstep: 50
6464
mixing_beta: 0.4
6565
SYSTEM:
6666
degauss: 0.01
@@ -95,7 +95,7 @@ scf:
9595
tstress: true
9696
ELECTRONS:
9797
conv_thr: 4.0e-10
98-
electron_maxstep: 80
98+
electron_maxstep: 50
9999
mixing_beta: 0.4
100100
SYSTEM:
101101
degauss: 0.01

‎tests/workflows/protocols/pw/test_base/test_default.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pw:
1818
tstress: true
1919
ELECTRONS:
2020
conv_thr: 4.0e-10
21-
electron_maxstep: 80
21+
electron_maxstep: 50
2222
mixing_beta: 0.4
2323
SYSTEM:
2424
degauss: 0.01

‎tests/workflows/protocols/pw/test_relax/test_default.yml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ base:
2222
tstress: true
2323
ELECTRONS:
2424
conv_thr: 4.0e-10
25-
electron_maxstep: 80
25+
electron_maxstep: 50
2626
mixing_beta: 0.4
2727
SYSTEM:
2828
degauss: 0.01
@@ -54,7 +54,7 @@ base_final_scf:
5454
tstress: true
5555
ELECTRONS:
5656
conv_thr: 4.0e-10
57-
electron_maxstep: 80
57+
electron_maxstep: 50
5858
mixing_beta: 0.4
5959
SYSTEM:
6060
degauss: 0.01

‎tests/workflows/protocols/test_pdos/test_default.yml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ nscf:
3232
tstress: true
3333
ELECTRONS:
3434
conv_thr: 4.0e-10
35-
electron_maxstep: 80
35+
electron_maxstep: 50
3636
mixing_beta: 0.4
3737
SYSTEM:
3838
ecutrho: 240.0
@@ -74,7 +74,7 @@ scf:
7474
tstress: true
7575
ELECTRONS:
7676
conv_thr: 4.0e-10
77-
electron_maxstep: 80
77+
electron_maxstep: 50
7878
mixing_beta: 0.4
7979
SYSTEM:
8080
degauss: 0.01

‎tests/workflows/protocols/xspectra/test_core/test_default.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ scf:
3737
tstress: true
3838
ELECTRONS:
3939
conv_thr: 4.0e-10
40-
electron_maxstep: 80
40+
electron_maxstep: 50
4141
mixing_beta: 0.4
4242
SYSTEM:
4343
degauss: 0.01

‎tests/workflows/protocols/xspectra/test_crystal/test_default.yml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ core:
2525
tstress: true
2626
ELECTRONS:
2727
conv_thr: 4.0e-10
28-
electron_maxstep: 80
28+
electron_maxstep: 50
2929
mixing_beta: 0.4
3030
SYSTEM:
3131
degauss: 0.01
@@ -100,7 +100,7 @@ relax:
100100
tstress: true
101101
ELECTRONS:
102102
conv_thr: 4.0e-10
103-
electron_maxstep: 80
103+
electron_maxstep: 50
104104
mixing_beta: 0.4
105105
SYSTEM:
106106
degauss: 0.01

0 commit comments

Comments
 (0)