Skip to content

Commit

Permalink
PwBaseWorkChain: Set restart_mode in parameters if parent_folder
Browse files Browse the repository at this point in the history
Typically, if a user launches a `PwBaseWorkChain` with a `parent_folder`
they want to restart from a previously completed but unconverged run. In
this case the `CONTROL.restart_mode` parameter should be set to
`from_scratch`. This used to be done automatically but was removed in
commit cb32be5.

Here we reinstate the behavior by calling `set_restart_type` to
`RestartType.FULL` if the `parent_folder` is defined and the
`CONTROL.restart_mode` hasn't already been set explicitly in the
parameters to `from_scratch`. In this case, it was likely set by the
caller and we don't want to silently override this.
  • Loading branch information
sphuber committed Nov 20, 2022
1 parent dcb17a5 commit 450290f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/aiida_quantumespresso/workflows/pw/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,13 @@ def setup(self):

self.ctx.inputs.settings = self.ctx.inputs.settings.get_dict() if 'settings' in self.ctx.inputs else {}

# If a ``parent_folder`` is specified, automatically set the parameters for a ``RestartType.Full`` unless the
# ``CONTROL.restart_mode`` has explicitly been set to ``from_scratch``. In that case, the user most likely set
# that, and we do not want to override it.
restart_mode = self.ctx.inputs.parameters['CONTROL'].get('restart_mode', None)
if 'parent_folder' in self.ctx.inputs and restart_mode != 'from_scratch':
self.set_restart_type(RestartType.FULL, self.ctx.inputs.parent_folder)

def validate_kpoints(self):
"""Validate the inputs related to k-points.
Expand Down
23 changes: 23 additions & 0 deletions tests/workflows/pw/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""Tests for the `PwBaseWorkChain` class."""
from aiida.common import AttributeDict
from aiida.engine import ExitCode, ProcessHandlerReport
from aiida.orm import Dict
import pytest

from aiida_quantumespresso.calculations.pw import PwCalculation
Expand Down Expand Up @@ -230,3 +231,25 @@ def test_set_max_seconds(generate_workchain_pw):

assert 'max_seconds' in process.ctx.inputs['parameters']['CONTROL']
assert process.ctx.inputs['parameters']['CONTROL']['max_seconds'] == max_seconds


@pytest.mark.parametrize('restart_mode, expected', (
(None, 'restart'),
('from_scratch', 'from_scratch'),
))
def test_parent_folder(generate_workchain_pw, generate_calc_job_node, restart_mode, expected):
"""Test that ``parameters`` gets automatically updated if ``parent_folder`` in the inputs.
Specifically, the ``parameters`` should define the ``CONTROL.restart_mode`` unless it was explicitly set to
``from_scratch`` by the caller.
"""
node = generate_calc_job_node('pw', test_name='default')

inputs = generate_workchain_pw(return_inputs=True)
inputs['pw']['parent_folder'] = node.outputs.remote_folder
inputs['pw']['parameters'] = Dict({'CONTROL': {'restart_mode': restart_mode}})

process = generate_workchain_pw(inputs=inputs)
process.setup()

assert process.ctx.inputs['parameters']['CONTROL']['restart_mode'] == expected

0 comments on commit 450290f

Please sign in to comment.