From 33a7259a542db3ae097e30783c985494d10f2d2f Mon Sep 17 00:00:00 2001 From: Marnik Bercx Date: Tue, 28 Nov 2023 21:48:59 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=A4=94=20A=20bunch=20of=20questionable=20?= =?UTF-8?q?changes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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 --- .../workflows/protocols/pw/base.yaml | 6 ++- .../workflows/pw/base.py | 44 +++++++++++++++---- .../protocols/pw/test_bands/test_default.yml | 6 +-- .../protocols/pw/test_base/test_default.yml | 2 +- .../protocols/pw/test_relax/test_default.yml | 4 +- .../protocols/test_pdos/test_default.yml | 2 +- .../xspectra/test_core/test_default.yml | 2 +- .../xspectra/test_crystal/test_default.yml | 4 +- 8 files changed, 51 insertions(+), 19 deletions(-) diff --git a/src/aiida_quantumespresso/workflows/protocols/pw/base.yaml b/src/aiida_quantumespresso/workflows/protocols/pw/base.yaml index 9d6f84326..411145226 100644 --- a/src/aiida_quantumespresso/workflows/protocols/pw/base.yaml +++ b/src/aiida_quantumespresso/workflows/protocols/pw/base.yaml @@ -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 @@ -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 @@ -53,3 +55,5 @@ protocols: parameters: CONTROL: forc_conv_thr: 1.e-3 + SYSTEM: + degauss: 0.0275 diff --git a/src/aiida_quantumespresso/workflows/pw/base.py b/src/aiida_quantumespresso/workflows/pw/base.py index e50f6f986..0c720eb20 100644 --- a/src/aiida_quantumespresso/workflows/pw/base.py +++ b/src/aiida_quantumespresso/workflows/pw/base.py @@ -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 @@ -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) diff --git a/tests/workflows/protocols/pw/test_bands/test_default.yml b/tests/workflows/protocols/pw/test_bands/test_default.yml index 10666d19d..bd0458565 100644 --- a/tests/workflows/protocols/pw/test_bands/test_default.yml +++ b/tests/workflows/protocols/pw/test_bands/test_default.yml @@ -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 @@ -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 @@ -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 diff --git a/tests/workflows/protocols/pw/test_base/test_default.yml b/tests/workflows/protocols/pw/test_base/test_default.yml index ee7d38851..9c00c7705 100644 --- a/tests/workflows/protocols/pw/test_base/test_default.yml +++ b/tests/workflows/protocols/pw/test_base/test_default.yml @@ -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 diff --git a/tests/workflows/protocols/pw/test_relax/test_default.yml b/tests/workflows/protocols/pw/test_relax/test_default.yml index 67b69b014..f07617b88 100644 --- a/tests/workflows/protocols/pw/test_relax/test_default.yml +++ b/tests/workflows/protocols/pw/test_relax/test_default.yml @@ -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 @@ -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 diff --git a/tests/workflows/protocols/test_pdos/test_default.yml b/tests/workflows/protocols/test_pdos/test_default.yml index 4a6d7a620..22fab1e82 100644 --- a/tests/workflows/protocols/test_pdos/test_default.yml +++ b/tests/workflows/protocols/test_pdos/test_default.yml @@ -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 diff --git a/tests/workflows/protocols/xspectra/test_core/test_default.yml b/tests/workflows/protocols/xspectra/test_core/test_default.yml index 684e2858e..4f1d73f82 100644 --- a/tests/workflows/protocols/xspectra/test_core/test_default.yml +++ b/tests/workflows/protocols/xspectra/test_core/test_default.yml @@ -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 diff --git a/tests/workflows/protocols/xspectra/test_crystal/test_default.yml b/tests/workflows/protocols/xspectra/test_crystal/test_default.yml index 60b033dc7..4df58d566 100644 --- a/tests/workflows/protocols/xspectra/test_crystal/test_default.yml +++ b/tests/workflows/protocols/xspectra/test_crystal/test_default.yml @@ -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 @@ -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