Skip to content

Commit

Permalink
🤔 A bunch of questionable changes
Browse files Browse the repository at this point in the history
* Stick to 50 `electron_maxstep`
* Refuse to increase number of SCF step if slope good
* Switch to `local-TF` mixing if lowsym or lowdim
* Finally, reduce mixing beta and increase ndim
  • Loading branch information
mbercx committed Nov 28, 2023
1 parent a3da4cd commit 33a7259
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 19 deletions.
6 changes: 5 additions & 1 deletion src/aiida_quantumespresso/workflows/protocols/pw/base.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ default_inputs:
nosym: False
occupations: smearing
smearing: cold
degauss: 0.01
degauss: 0.02
ELECTRONS:
electron_maxstep: 50
mixing_beta: 0.4
Expand All @@ -43,6 +43,8 @@ protocols:
parameters:
CONTROL:
forc_conv_thr: 0.5e-4
SYSTEM:
degauss: 0.0125
fast:
description: 'Protocol to perform the computation at low precision at minimal computational cost for testing purposes.'
kpoints_distance: 0.50
Expand All @@ -53,3 +55,5 @@ protocols:
parameters:
CONTROL:
forc_conv_thr: 1.e-3
SYSTEM:
degauss: 0.0275
44 changes: 36 additions & 8 deletions src/aiida_quantumespresso/workflows/pw/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,13 @@ class PwBaseWorkChain(ProtocolMixin, BaseRestartWorkChain):
'delta_threshold_degauss': 30,
'delta_factor_degauss': 0.1,
'delta_factor_mixing_beta': 0.5,
'delta_addition_mixing_ndim': 4,
'delta_factor_max_seconds': 0.95,
'delta_factor_nbnd': 0.05,
'delta_minimum_nbnd': 4,
'conv_slope_threshold': -0.1,
'conv_slope_range': 30,
'low_symmetry_threshold': 6
})

@classmethod
Expand Down Expand Up @@ -571,31 +574,56 @@ def handle_electronic_convergence_not_reached(self, calculation):
"""
import numpy

scf_accuracy = calculation.tools.get_scf_accuracy(0)
scf_accuracy = calculation.tools.get_scf_accuracy(-1)[-self.defaults.conv_slope_range:]
scf_accuracy_slope = numpy.polyfit(numpy.arange(0, len(scf_accuracy)), numpy.log(scf_accuracy), 1)[0]

if scf_accuracy_slope < self.defaults.conv_slope_threshold:
mixing_beta = self.ctx.inputs.parameters['ELECTRONS'].get('mixing_beta', self.defaults.qe.mixing_beta)
mixing_ndim = self.ctx.inputs.parameters['ELECTRONS'].get('mixing_ndim', self.defaults.qe.mixing_ndim)
mixing_mode = self.ctx.inputs.parameters['ELECTRONS'].get('mixing_mode', self.defaults.qe.mixing_mode)
low_symmetry_structure = (
len(calculation.outputs.output_parameters.get_dict()['symmetries']) < self.defaults.low_symmetry_threshold
)
low_dim_structure = calculation.inputs.structure.pbc != (True, True, True)

self.report(f'scf accuracy slope: {scf_accuracy_slope:.2f}')
self.report(f'mixing beta: {mixing_beta:.2f}')
self.report(f'mixing ndim: {mixing_ndim}')
self.report(f'mixing mode: {mixing_mode}')
self.report(f"structure symmetries: {len(calculation.outputs.output_parameters.get_dict()['symmetries'])}")
self.report(f'low symmetry structure: {low_symmetry_structure}')
self.report(f'low dimension structure: {low_dim_structure}')

if scf_accuracy_slope < self.defaults.conv_slope_threshold:
action = (
'electronic convergence not reached but the scf accuracy is decreasing: restart from the last '
'calculation.'
f'electronic convergence not reached but the scf accuracy slope ({scf_accuracy_slope:.2f}) is smaller '
f'than the threshold ({self.defaults.conv_slope_threshold:.2f}): restart from the last calculation.'
)
self.set_restart_type(RestartType.FULL, calculation.outputs.remote_folder)
self.report_error_handled(calculation, action)
return ProcessHandlerReport(True)

mixing_beta = self.ctx.inputs.parameters.get('ELECTRONS', {}).get('mixing_beta', self.defaults.qe.mixing_beta)
if mixing_mode == 'plain' and (low_symmetry_structure or low_dim_structure):

self.ctx.inputs.parameters['ELECTRONS'].setdefault('mixing_mode', 'local-TF')
action = (
'electronic convergence not reached and structure is inhomogeneous: switch to local-TF mixing and '
'restart from the last calculation.'
)
self.set_restart_type(RestartType.FULL, calculation.outputs.remote_folder)
self.report_error_handled(calculation, action)
return ProcessHandlerReport(True)

if mixing_beta > 0.1:

mixing_beta_new = mixing_beta * self.defaults.delta_factor_mixing_beta
mixing_ndim_new = mixing_ndim + self.defaults.delta_addition_mixing_ndim

self.ctx.inputs.parameters['ELECTRONS']['mixing_beta'] = mixing_beta_new
self.ctx.inputs.parameters['ELECTRONS']['mixing_ndim'] = mixing_ndim_new
action = (
f'reduced beta mixing from {mixing_beta} to {mixing_beta_new} and restarting from the last '
'calculation'
f'reduced beta mixing from {mixing_beta} to {mixing_beta_new}, increased `mixing_ndim` from '
f'{mixing_ndim} to {mixing_ndim_new} and restarting from the last calculation.'
)

self.set_restart_type(RestartType.FULL, calculation.outputs.remote_folder)
self.report_error_handled(calculation, action)
return ProcessHandlerReport(True)
Expand Down
6 changes: 3 additions & 3 deletions tests/workflows/protocols/pw/test_bands/test_default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ bands:
mixing_beta: 0.4
startingpot: file
SYSTEM:
degauss: 0.01
degauss: 0.02
ecutrho: 240.0
ecutwfc: 30.0
nosym: false
Expand Down Expand Up @@ -65,7 +65,7 @@ relax:
electron_maxstep: 50
mixing_beta: 0.4
SYSTEM:
degauss: 0.01
degauss: 0.02
ecutrho: 240.0
ecutwfc: 30.0
nosym: false
Expand Down Expand Up @@ -101,7 +101,7 @@ scf:
electron_maxstep: 50
mixing_beta: 0.4
SYSTEM:
degauss: 0.01
degauss: 0.02
ecutrho: 240.0
ecutwfc: 30.0
nosym: false
Expand Down
2 changes: 1 addition & 1 deletion tests/workflows/protocols/pw/test_base/test_default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pw:
electron_maxstep: 50
mixing_beta: 0.4
SYSTEM:
degauss: 0.01
degauss: 0.02
ecutrho: 240.0
ecutwfc: 30.0
nosym: false
Expand Down
4 changes: 2 additions & 2 deletions tests/workflows/protocols/pw/test_relax/test_default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ base:
electron_maxstep: 50
mixing_beta: 0.4
SYSTEM:
degauss: 0.01
degauss: 0.02
ecutrho: 240.0
ecutwfc: 30.0
nosym: false
Expand Down Expand Up @@ -59,7 +59,7 @@ base_final_scf:
electron_maxstep: 50
mixing_beta: 0.4
SYSTEM:
degauss: 0.01
degauss: 0.02
ecutrho: 240.0
ecutwfc: 30.0
nosym: false
Expand Down
2 changes: 1 addition & 1 deletion tests/workflows/protocols/test_pdos/test_default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ scf:
electron_maxstep: 50
mixing_beta: 0.4
SYSTEM:
degauss: 0.01
degauss: 0.02
ecutrho: 240.0
ecutwfc: 30.0
nosym: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ scf:
electron_maxstep: 50
mixing_beta: 0.4
SYSTEM:
degauss: 0.01
degauss: 0.02
ecutrho: 240.0
ecutwfc: 30.0
nosym: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ core:
electron_maxstep: 50
mixing_beta: 0.4
SYSTEM:
degauss: 0.01
degauss: 0.02
ecutrho: 240.0
ecutwfc: 30.0
nosym: false
Expand Down Expand Up @@ -105,7 +105,7 @@ relax:
electron_maxstep: 50
mixing_beta: 0.4
SYSTEM:
degauss: 0.01
degauss: 0.02
ecutrho: 240.0
ecutwfc: 30.0
nosym: false
Expand Down

0 comments on commit 33a7259

Please sign in to comment.