Skip to content

Commit

Permalink
PwCalculation: Add exit code and handler for scale_h error (#913)
Browse files Browse the repository at this point in the history
This exit code appears when a cell relaxation produces a significant
volume contraction. This means the pseudopotentials tables must be
recalculated. This parameter is controlled by `CELL.cell_factor`.

The solution, as suggested by the Quantum ESPRESSO error itself, is to
restart with an increased `cell_factor`. The handler restarts from
scratch using the last output structure, doubling the cell factor which
should be 2 by default.
  • Loading branch information
bastonero authored Apr 17, 2023
1 parent 29a0dfa commit d350d7e
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/aiida_quantumespresso/calculations/pw.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ def define(cls, spec):
message='The electronic minimization cycle did not reach self-consistency.')
spec.exit_code(541, 'ERROR_SYMMETRY_NON_ORTHOGONAL_OPERATION',
message='The variable cell optimization broke the symmetry of the k-points.')
spec.exit_code(542, 'ERROR_RADIAL_FFT_SIGNIFICANT_VOLUME_CONTRACTION',
message=('The cell relaxation caused a significant volume contraction '
'and there is not enough space allocated for radial FFT.'))

# Strong warnings about calculation results, but something tells us that you're ok with that
spec.exit_code(710, 'WARNING_ELECTRONIC_CONVERGENCE_NOT_REACHED',
Expand Down
1 change: 1 addition & 0 deletions src/aiida_quantumespresso/parsers/parse_raw/pw.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ def detect_important_message(logs, line):
'probably because G_par is NOT a reciprocal lattice vector': 'ERROR_G_PAR',
'eigenvectors failed to converge': 'ERROR_EIGENVECTOR_CONVERGENCE',
'Error in routine broyden': 'ERROR_BROYDEN_FACTORIZATION',
'Not enough space allocated for radial FFT: try restarting with a larger cell_factor': 'ERROR_RADIAL_FFT_SIGNIFICANT_VOLUME_CONTRACTION',
REG_ERROR_NPOOLS_TOO_HIGH: 'ERROR_NPOOLS_TOO_HIGH',
},
'warning': {
Expand Down
1 change: 1 addition & 0 deletions src/aiida_quantumespresso/parsers/pw.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ def validate_premature_exit(self, logs):
'ERROR_G_PAR',
'ERROR_EIGENVECTOR_CONVERGENCE',
'ERROR_BROYDEN_FACTORIZATION',
'ERROR_RADIAL_FFT_SIGNIFICANT_VOLUME_CONTRACTION',
]:
if error_label in logs['error']:
return self.exit_codes.get(error_label)
Expand Down
26 changes: 26 additions & 0 deletions src/aiida_quantumespresso/workflows/pw/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,32 @@ def handle_relax_recoverable_ionic_convergence_error(self, calculation):
self.report_error_handled(calculation, action)
return ProcessHandlerReport(True)

@process_handler(
priority=559, exit_codes=[
PwCalculation.exit_codes.ERROR_RADIAL_FFT_SIGNIFICANT_VOLUME_CONTRACTION,
]
)
def handle_vcrelax_recoverable_fft_significant_volume_contraction_error(self, calculation):
"""Handle exit code for recoverable `vc-relax` calculations with significant volume contraction.
This exit code appears when a cell relaxation produces a significant volume scaling (contraction or expansion).
This means the pseudopotentials tables must be recalculated. This parameter is controlled by `CELL.cell_factor`.
The solution, as suggested by the QuantumESPRESSO error itself, is to restart with an increased `cell_factor`.
We then start from scratch using the last output structure and we double the cell factor.
"""
self.ctx.inputs.structure = calculation.outputs.output_structure
self.ctx.inputs.parameters.setdefault('CELL', {}) # as it is not compulsory for ``vc-relax`` calculations
cell_factor = 2 * self.ctx.inputs.parameters['CELL'].get('cell_factor', 2)
self.ctx.inputs.parameters['CELL']['cell_factor'] = cell_factor

self.set_restart_type(RestartType.FROM_SCRATCH)
action = (
'significant volume scaling but clean shutdown: '
f'restarting from scratch using output structure and ``cell_factor = {cell_factor}``.'
)
self.report_error_handled(calculation, action)
return ProcessHandlerReport(True)

@process_handler(
priority=550,
exit_codes=[
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Error in routine scale_h (1):
Not enough space allocated for radial FFT: try restarting with a larger cell_factor.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# NOTE: lines of output removed
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Error in routine scale_h (1):
Not enough space allocated for radial FFT: try restarting with a larger cell_factor.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# NOTE: lines of output removed
22 changes: 21 additions & 1 deletion tests/parsers/test_pw.py
Original file line number Diff line number Diff line change
Expand Up @@ -1093,7 +1093,27 @@ def test_pw_vcrelax_failed_not_converged_nstep(
assert 'output_kpoints' in results
assert 'output_parameters' in results
assert 'output_structure' in results
assert 'output_trajectory' in results


@pytest.mark.parametrize('filename', ('', '_stdout'))
def test_pw_vcrelax_failed_fft_significant_volume_contraction(
fixture_localhost, generate_calc_job_node, generate_parser, generate_inputs, filename
):
"""Test a `vc-relax` that failed due to significant volume contraction."""
name = f'vcrelax_failed_fft_significant_volume_contraction{filename}'
entry_point_calc_job = 'quantumespresso.pw'
entry_point_parser = 'quantumespresso.pw'

inputs = generate_inputs(calculation_type='vc-relax')
node = generate_calc_job_node(entry_point_calc_job, fixture_localhost, name, inputs)
parser = generate_parser(entry_point_parser)
results, calcfunction = parser.parse_from_node(node, store_provenance=False)
expected_exit_status = node.process_class.exit_codes.ERROR_RADIAL_FFT_SIGNIFICANT_VOLUME_CONTRACTION.status

assert calcfunction.is_failed
assert calcfunction.exit_status == expected_exit_status
assert orm.Log.collection.get_logs_for(node)
assert 'output_structure' in results


def test_magnetic_moments_v68(
Expand Down
18 changes: 18 additions & 0 deletions tests/workflows/pw/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,24 @@ def test_handle_relax_recoverable_ionic_convergence_error(generate_workchain_pw,
assert result.status == 0


def test_handle_vcrelax_recoverable_fft_significant_volume_contraction_error(generate_workchain_pw, generate_structure):
"""Test `PwBaseWorkChain.handle_vcrelax_recoverable_fft_significant_volume_contraction_error`."""
exit_code = PwCalculation.exit_codes.ERROR_RADIAL_FFT_SIGNIFICANT_VOLUME_CONTRACTION
structure = generate_structure()
process = generate_workchain_pw(pw_outputs={'output_structure': structure}, exit_code=exit_code)
process.setup()

result = process.handle_vcrelax_recoverable_fft_significant_volume_contraction_error(process.ctx.children[-1])
assert isinstance(result, ProcessHandlerReport)
assert result.do_break
assert result.exit_code.status == 0
assert process.ctx.inputs.parameters['CONTROL']['restart_mode'] == 'from_scratch'
assert process.ctx.inputs.parameters['CELL']['cell_factor'] == 4

result = process.inspect_process()
assert result.status == 0


def test_handle_electronic_convergence_warning(generate_workchain_pw, generate_structure):
"""Test `PwBaseWorkChain.handle_electronic_convergence_warning`."""
inputs = generate_workchain_pw(return_inputs=True)
Expand Down

0 comments on commit d350d7e

Please sign in to comment.