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

PwParser: Fix trajectory verification for fixed_coords #794

Merged
merged 6 commits into from
Apr 6, 2023

Conversation

mbercx
Copy link
Member

@mbercx mbercx commented Mar 7, 2022

Fixes #792

For relax and vc-relax calculations, the PwParser does an extra
check on the TrajectoryData output to see if the structure has been
properly converged. However, when comparing the final forces with the
threshold, it does not consider that some site coordinates may have been
fixed with the fixed_coords setting.

Here we extract the fixed_coords setting from the PwCalculation
inputs, and pass it to the verify_convergence_trajectory function.
This has been adapted to ignore forces for fixed coordinates by setting
the corresponding forces to zero before comparing them with the force
threshold.

@mbercx
Copy link
Member Author

mbercx commented Mar 7, 2022

@sphuber will add a test once we agree on the implementation!

@Sokseiha I already manually tried to parse the output files you sent me, but perhaps you can try to run another (cheap) example with the PR branch to see if it all works as expected?

Copy link
Contributor

@sphuber sphuber 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 the implementation is ok, it is quite elegant, but it needs validation and some comments explaining it.

aiida_quantumespresso/utils/validation/trajectory.py Outdated Show resolved Hide resolved
@mbercx
Copy link
Member Author

mbercx commented Mar 8, 2022

@sphuber have added some more explanation regarding the fixed_coords numpy magic and moved some checks into a validator instead of raising errors during the preparation for submission.

Note that since the structure isn't there for the PwCalculation when it is excluded in a higher-level work chain (e.g. in the PwRelaxWorkChain), the validation for checking that the number of sites matches the number of fixed_coords lists is only run if the structure input is there. So I still left the same check in the preparation step as well. I suppose it's still better for the work chain to except than fail because of bad inputs.

Copy link
Contributor

@sphuber sphuber 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 , overall the changes look good, just some minor things. Would be good to give this a go for real if possible.

aiida_quantumespresso/calculations/__init__.py Outdated Show resolved Hide resolved
aiida_quantumespresso/calculations/__init__.py Outdated Show resolved Hide resolved
aiida_quantumespresso/calculations/__init__.py Outdated Show resolved Hide resolved
sphuber
sphuber previously approved these changes Mar 9, 2022
Copy link
Contributor

@sphuber sphuber left a comment

Choose a reason for hiding this comment

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

Pre-approving but if possible would still be good to verify this works in real example with @Sokseiha

@mbercx
Copy link
Member Author

mbercx commented Mar 9, 2022

Pre-approving but if possible would still be good to verify this works in real example with @Sokseiha

I'm still testing + adding tests! And actually found some bugs, so good thing too ^^

@mbercx
Copy link
Member Author

mbercx commented Mar 9, 2022

There, now she's ready for another review. I've added tests for both the input file generation and the parsing (relax and vc-relax`).

@mbercx mbercx self-assigned this Jan 25, 2023
@mbercx
Copy link
Member Author

mbercx commented Feb 17, 2023

@sphuber still found a flaw in the current implementation (i.e. the parsing expected fixed_coords lowercase) and added a test. @AriannaCantarella maybe you can give this one a test for your hydrogen restorer work chain?

@mbercx
Copy link
Member Author

mbercx commented Feb 17, 2023

@sphuber: As a side note: what should the "best practises" for validator methods be? i.e. do you agree with the following:

  1. We add them as a classmethod or staticmethod on the process class they are validating the input ports for. Although those that do not use the cls could also be added as separate functions defined before the process class, I think the validators are typically directly tied to the class anyways and it is tidier to have them all in one place.
  2. We do not add them as hidden methods, i.e. they are not prefaced with an underscore _. Although it is rare to call the validators outside of the class, one could potentially think of a use case for this, and most of the methods defined on e.g. a work chain class are rarely called outside of the class, save for e.g. testing.

@sphuber
Copy link
Contributor

sphuber commented Feb 17, 2023

@sphuber: As a side note: what should the "best practises" for validator methods be? i.e. do you agree with the following:

  1. We add them as a classmethod or staticmethod on the process class they are validating the input ports for. Although those that do not use the cls could also be added as separate functions defined before the process class, I think the validators are typically directly tied to the class anyways and it is tidier to have them all in one place.
  2. We do not add them as hidden methods, i.e. they are not prefaced with an underscore _. Although it is rare to call the validators outside of the class, one could potentially think of a use case for this, and most of the methods defined on e.g. a work chain class are rarely called outside of the class, save for e.g. testing.

I agree on both points. I also add validators as public class methods or static methods

@mbercx
Copy link
Member Author

mbercx commented Feb 23, 2023

@sphuber this has been tested in the field by @AriannaCantarella. If you could give one final sign off on this one I'll then rebase #818 and we can merge that as well.

For `relax` and `vc-relax` calculations, the `PwParser` does an extra
check on the `TrajectoryData` output to see if the structure has been
properly converged. However, when comparing the final forces with the
threshold, it does not consider that some site coordinates may have been
fixed with the `fixed_coords` setting.

Here we extract the `fixed_coords` setting from the `PwCalculation`
inputs, and pass it to the `verify_convergence_trajectory` function.
This has been adapted to ignore forces for fixed coordinates by setting
the corresponding forces to zero before comparing them with the force
threshold.
Copy link
Contributor

@sphuber sphuber 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 good to go!

@mbercx mbercx merged commit 105670f into aiidateam:main Apr 6, 2023
@mbercx mbercx deleted the fix/792/fixed-coords branch April 6, 2023 13:08
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.

PwParser: trajectory verification doesn't consider fixed_coords
2 participants