aiidateam / aiida-quantumespresso

The official AiiDA plugin for Quantum ESPRESSO
https://aiida-quantumespresso.readthedocs.io
Other
55 stars 82 forks source link

`PhBaseWorkChain`: skip q-points validation if ports are excluded #1006

Closed mbercx closed 9 months ago

mbercx commented 9 months ago

Currently, the top-level validate_inputs validator for the PhBaseWorkChain will always check if either the qpoints or qpoints_distance inputs are provided. However, there are cases where a higher-level work chain that wraps the PhBaseWorkChain might provide the q-points input on the fly. Such a work chain would have to set the PhBaseWorkChain validator to None in its own define method.

However, as also discussed for a similar case for the PwCalculation in a389629, it's more elegant to check if the qpoints_distance and qpoints ports are present in the namespace. Typically a work chain that provides the q-points input on the fly will exclude these ports when exposing the PhBaseWorkChain inputs. By checking if the ports are present in the validator, we avoid having to set the validator to None as well in the higher-level work chain.

mbercx commented 9 months ago

Hehe, I was worried you might drop the word "tests". I'm also wondering what a good approach is for testing this change, maybe @sphuber can give a suggestion?

sphuber commented 9 months ago

Hehe, I was worried you might drop the word "tests". I'm also wondering what a good approach is for testing this change, maybe @sphuber can give a suggestion?

Something like this?

from aiida.engine import WorkChain
from aiida_quantumespresso.workflows.ph.base import PhBaseWorkChain

class SubPhBaseWorkChain(WorkChain):

    @classmethod
    def define(cls, spec):
        super().define(spec)
        spec.expose_inputs(PhBaseWorkChain, exclude=('qpoints', 'qpoints_distance'))

def test_validate_inputs_excluded_qpoints_distance(generate_inputs_ph_base):
    from aiida.engine.utils import instantiate_process
    from aiida.manage.manager import get_manager

    inputs = generate_inputs_ph_base
    inputs.pop('qpoints', None)
    inputs.pop('qpoints_distance', None)
    runner = get_manager().get_runner()
    instantiate_process(runner, SubPhBaseWorkChain, **inputs)