Skip to content
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

Merged
merged 2 commits into from
Feb 12, 2024

Conversation

mbercx
Copy link
Member

@mbercx mbercx commented Feb 12, 2024

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.

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 mbercx requested a review from bastonero February 12, 2024 11:18
bastonero
bastonero previously approved these changes Feb 12, 2024
Copy link
Collaborator

@bastonero bastonero left a 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?

@mbercx
Copy link
Member Author

mbercx commented Feb 12, 2024

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
Copy link
Contributor

sphuber commented Feb 12, 2024

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)

Copy link
Collaborator

@bastonero bastonero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @mbercx, very happy that a test has been added, and thanks @sphuber for the suggestion. Just a minor question, and it's good to go


inputs = {'ph': generate_inputs_ph()}
inputs['ph'].pop('qpoints', None)
inputs['ph'].pop('qpoints_distance', None)
Copy link
Collaborator

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

Copy link
Collaborator

@bastonero bastonero Feb 12, 2024

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

Copy link
Member Author

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 👍

Copy link
Contributor

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?

Copy link
Collaborator

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.

Copy link
Member Author

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).

Copy link
Collaborator

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.

Copy link
Collaborator

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)

Copy link
Contributor

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

Copy link
Member Author

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! 🥳

@mbercx mbercx force-pushed the fix/phbase-validation branch from 71f6591 to 6e36f91 Compare February 12, 2024 16:01
@mbercx mbercx requested a review from bastonero February 12, 2024 16:02
Copy link
Collaborator

@bastonero bastonero left a 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

@mbercx mbercx merged commit 32536e8 into aiidateam:main Feb 12, 2024
7 checks passed
@mbercx mbercx deleted the fix/phbase-validation branch February 12, 2024 17:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants