-
Notifications
You must be signed in to change notification settings - Fork 83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PhBaseWorkChain
: skip q-points validation if ports are excluded
#1006
Conversation
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @mbercx , this looks good to me. Only a curiosity/question: can the logic of the namespace be tested?
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tests/workflows/ph/test_base.py
Outdated
|
||
inputs = {'ph': generate_inputs_ph()} | ||
inputs['ph'].pop('qpoints', None) | ||
inputs['ph'].pop('qpoints_distance', None) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is really needed right? Since it is an input of the PhBaseWorkChain
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean the qpoints_distance
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh fair, it's not in there anyways 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is really needed right? Since it is an input of the PhBaseWorkChain
I don't follow. That is the whole point of this test. It is checking that, even though qpoints
and qpoints_distance
are inputs to PhBaseWorkChain
and so they are validated in the inputs namespace validator, when a wrapping workchain explicitly excludes them, the validator does not raise a warning. So the test needs to make sure that inputs are passed that do not contain either qpoints
or qpoints_distance
. Right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct, but generate_inputs_ph()
would generate inputs of PhCalculation
, which doesn't have qpoints_distance
, so it's one line more which is not needed. The two qpoints input for PhBaseWorkChain
are moved into the "top level" namespace, and not nested in the ph
namespace.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah but I used the generate_inputs_ph
fixture which wouldn't have the qpoints_distance
(there is no generate_inputs_ph_base
afaik).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough, I do agree.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think one can use generate_ph_workchain_node(return_inputs=True)
or similar (don't remember exactly the name of the fixutre)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, feel free to change as I suggested, but not necessary. Also fine to merge as is for me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Somehow this absence of introduced scope creep feels like reverse psychology. 🤔
But I'll take it! 🥳
71f6591
to
6e36f91
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can approve it this way for the moment being. Thanks @mbercx
Currently, the top-level
validate_inputs
validator for thePhBaseWorkChain
will always check if either theqpoints
orqpoints_distance
inputs are provided. However, there are cases where a higher-level work chain that wraps thePhBaseWorkChain
might provide the q-points input on the fly. Such a work chain would have to set thePhBaseWorkChain
validator toNone
in its owndefine
method.However, as also discussed for a similar case for the
PwCalculation
in a389629, it's more elegant to check if theqpoints_distance
andqpoints
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 thePhBaseWorkChain
inputs. By checking if the ports are present in the validator, we avoid having to set the validator toNone
as well in the higher-level work chain.