Skip to content

Commit

Permalink
Add tests for restart validation
Browse files Browse the repository at this point in the history
  • Loading branch information
mbercx committed Sep 21, 2021
1 parent 600681c commit 335da8f
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 12 deletions.
2 changes: 1 addition & 1 deletion aiida_quantumespresso/calculations/pw.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def validate_inputs(value, _):
return f'`restart_mode` should be set to `from_scratch` for a `{calculation_type}` calculation.'
elif 'parent_folder' in value:
if not any([
parameters.get('CONTROL', {}).get('calculation', None) == 'restart',
parameters.get('CONTROL', {}).get('restart_mode', None) == 'restart',
parameters.get('ELECTRONS', {}).get('startingpot', None) == 'file',
parameters.get('ELECTRONS', {}).get('startingwfc', None) == 'file'
]):
Expand Down
64 changes: 64 additions & 0 deletions tests/calculations/test_pw.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,3 +250,67 @@ def test_pw_parallelization_duplicate_cmdline_flag(fixture_sandbox, generate_cal
with pytest.raises(InputValidationError) as exc:
generate_calc_job(fixture_sandbox, entry_point_name, inputs)
assert 'Conflicting' in str(exc.value)


@pytest.mark.parametrize('calculation', ['nscf', 'bands', 'scf', 'relax', 'vc-relax'])
def test_pw_validate_inputs_restart(
fixture_sandbox, generate_calc_job, generate_inputs_pw, fixture_localhost, generate_remote_data, calculation
):
"""Test the input validation of restart settings for the ``PwCalculation``."""
remote_data = generate_remote_data(computer=fixture_localhost, remote_path='/cat_stevens')
entry_point_name = 'quantumespresso.pw'

inputs = generate_inputs_pw()
parameters = inputs['parameters'].get_dict()
parameters['CONTROL']['calculation'] = calculation

if calculation in ('nscf', 'bands'):

# No parent_folder -> raise
inputs['parameters'] = orm.Dict(dict=parameters)
with pytest.raises(ValueError) as exc:
generate_calc_job(fixture_sandbox, entry_point_name, inputs)
assert f'`parent_folder` not provided for `{calculation}` calculation.' in str(exc.value)

# Parent_folder + defaults -> works
inputs['parent_folder'] = remote_data
generate_calc_job(fixture_sandbox, entry_point_name, inputs)

# Set `startingpot` to `'atomic'` -> raise
parameters['ELECTRONS']['startingpot'] = 'atomic'
inputs['parameters'] = orm.Dict(dict=parameters)
with pytest.raises(ValueError) as exc:
generate_calc_job(fixture_sandbox, entry_point_name, inputs)
assert f'`startingpot` should be set to `file` for a `{calculation}` calculation.' in str(exc.value)

# Set `restart_mode` to `'restart'` -> raise
parameters['ELECTRONS'].pop('startingpot')
parameters['CONTROL']['restart_mode'] = 'restart'
inputs['parameters'] = orm.Dict(dict=parameters)
with pytest.raises(ValueError) as exc:
generate_calc_job(fixture_sandbox, entry_point_name, inputs)
assert f'`restart_mode` should be set to `from_scratch` for a `{calculation}` calculation.' in str(exc.value)

else:
# Add `parent_folder` but no restart tags -> warning
inputs['parent_folder'] = remote_data
with pytest.warns(Warning) as warnings:
generate_calc_job(fixture_sandbox, entry_point_name, inputs)
assert any('`parent_folder` input was provided for the' in str(warning.message) for warning in warnings.list)

# Set `restart_mode` to `'restart'` -> no warning
parameters['CONTROL']['restart_mode'] = 'restart'
inputs['parameters'] = orm.Dict(dict=parameters)
with pytest.warns(None) as warnings:
generate_calc_job(fixture_sandbox, entry_point_name, inputs)
assert len(warnings.list) == 0
parameters['CONTROL'].pop('restart_mode')

# Set `startingwfc` or `startingpot` to `'file'` -> no warning
for restart_setting in ('startingpot', 'startingwfc'):
parameters['ELECTRONS'][restart_setting] = 'file'
inputs['parameters'] = orm.Dict(dict=parameters)
with pytest.warns(None) as warnings:
generate_calc_job(fixture_sandbox, entry_point_name, inputs)
assert len(warnings.list) == 0
parameters['ELECTRONS'].pop(restart_setting)
1 change: 1 addition & 0 deletions tests/calculations/test_pw/test_pw_default.in
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
ntyp = 1
/
&ELECTRONS
electron_maxstep = 60
/
ATOMIC_SPECIES
Si 28.0855 Si.upf
Expand Down
31 changes: 20 additions & 11 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,18 +516,27 @@ def _generate_inputs_pw():
from aiida_quantumespresso.utils.resources import get_default_options

inputs = {
'code': fixture_code('quantumespresso.pw'),
'structure': generate_structure(),
'kpoints': generate_kpoints_mesh(2),
'parameters': Dict(dict={
'CONTROL': {
'calculation': 'scf'
},
'SYSTEM': {
'ecutrho': 240.0,
'ecutwfc': 30.0
'code':
fixture_code('quantumespresso.pw'),
'structure':
generate_structure(),
'kpoints':
generate_kpoints_mesh(2),
'parameters':
Dict(
dict={
'CONTROL': {
'calculation': 'scf'
},
'SYSTEM': {
'ecutrho': 240.0,
'ecutwfc': 30.0
},
'ELECTRONS': {
'electron_maxstep': 60,
}
}
}),
),
'pseudos': {
'Si': generate_upf_data('Si')
},
Expand Down
3 changes: 3 additions & 0 deletions tests/tools/test_immigrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ def test_create_builder(fixture_sandbox, fixture_code, generate_upf_data, genera
'ecutrho': 240.0,
'ecutwfc': 30.0,
'ibrav': 0,
},
'ELECTRONS': {
'electron_maxstep': 60
}
}
assert 'kpoints' in builder
Expand Down

0 comments on commit 335da8f

Please sign in to comment.