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

Patch QE n_electrons #271

Merged
merged 10 commits into from
Jan 20, 2025
Merged

Patch QE n_electrons #271

merged 10 commits into from
Jan 20, 2025

Conversation

ndaelman-hu
Copy link
Contributor

A user pointed out that with spin-polarization turned on, the QE parser extracts 3 values for the total electron count and attempts to assign them, causing an error:

"exception":string"Traceback (most recent call last): File "/home/cecilia/lavoro/nomad-distro-dev-aa/packages/nomad-FAIR/nomad/processing/data.py", line 1508, in parsing parser.parse( File "/home/cecilia/lavoro/nomad-distro-dev-aa/packages/nomad-FAIR/nomad/parsing/parser.py", line 460, in parse self.mainfile_parser.parse(mainfile, archive, logger) File "/home/cecilia/lavoro/nomad-distro-dev-aa/.venv/lib/python3.12/site-packages/electronicparsers/quantumespresso/parser.py", line 3563, in parse self.parse_method(run) File "/home/cecilia/lavoro/nomad-distro-dev-aa/.venv/lib/python3.12/site-packages/electronicparsers/quantumespresso/parser.py", line 3499, in parse_method sec_method.electronic.n_electrons = number_of_electrons ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/cecilia/lavoro/nomad-distro-dev-aa/packages/nomad-FAIR/nomad/metainfo/metainfo.py", line 1090, in __setattr__ return super().__setattr__(name, value) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/cecilia/lavoro/nomad-distro-dev-aa/packages/nomad-FAIR/nomad/metainfo/metainfo.py", line 727, in wrapper return method(self, obj, value, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/cecilia/lavoro/nomad-distro-dev-aa/packages/nomad-FAIR/nomad/metainfo/metainfo.py", line 3273, in __set__ value = self.type.normalize(value, section=obj, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/cecilia/lavoro/nomad-distro-dev-aa/packages/nomad-FAIR/nomad/metainfo/data_type.py", line 546, in normalize return super().normalize(value, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/cecilia/lavoro/nomad-distro-dev-aa/packages/nomad-FAIR/nomad/metainfo/data_type.py", line 294, in normalize raise ValueError( ValueError: Cannot set [7. 4. 3.] for the scalar quantity runschema.method.Electronic.n_electrons:Quantity."
"timestamp":string"2025-01-16 15:53.12"
"level":string"ERROR"
}

@ndaelman-hu ndaelman-hu added the bug Something isn't working. It also represents a quick fix in response to a bug. label Jan 16, 2025
@ndaelman-hu ndaelman-hu requested a review from ladinesa January 16, 2025 21:10
@ndaelman-hu ndaelman-hu self-assigned this Jan 16, 2025
@ndaelman-hu
Copy link
Contributor Author

I now split the extraction between the total count and the one divided by spin-channel.
The latter is used is when the former is missing or corrupted.

@@ -2037,7 +2037,12 @@ def str_to_sticks(val_in):
),
Quantity(
'number_of_electrons',
rf'number of electrons\s*=\s*({re_float})\s*(?:\(up:\s*({re_float})\s*,\s*down:\s*({re_float}))?',
Copy link
Collaborator

Choose a reason for hiding this comment

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

can you send me the text which fails for this regex pattern? as far as i can see this is generic enough for both cases. we should try to keep it in one quantity.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The pattern isn't failing itself. The schema only needs the 1st match. There was a bug where the parser passed along all 3, violating the shape. The new shape rules actually brought it too light. So we should maybe consider reprocessing QE calcs...

If for some God-foresaken reason the 1st number can't be extracted, it can still be reconstructed from the latter 2.
It's very niche, I can remove that logic.

Copy link
Collaborator

Choose a reason for hiding this comment

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

can you then simply put this logic in swtting the value based on the length of the list

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried that first (it's in an older commit). The answer's no, since idk which value(s) is missing when the list is of length 2 or 1. The only choice is to support this corruption recovery or not. Up to you.

Copy link
Collaborator

Choose a reason for hiding this comment

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

we can then make this as a sub-parser to resolve the electron type, this i think is still a better way than introducing multiple quantites

@coveralls
Copy link

coveralls commented Jan 16, 2025

Pull Request Test Coverage Report for Build 12835994247

Details

  • 10 of 14 (71.43%) changed or added relevant lines in 2 files are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage decreased (-0.009%) to 93.056%

Changes Missing Coverage Covered Lines Changed/Added Lines %
electronicparsers/quantumespresso/parser.py 9 13 69.23%
Files with Coverage Reduction New Missed Lines %
electronicparsers/quantumespresso/parser.py 1 94.88%
Totals Coverage Status
Change from base Build 12379654277: -0.009%
Covered Lines: 35819
Relevant Lines: 38492

💛 - Coveralls

@ndaelman-hu ndaelman-hu requested a review from ladinesa January 17, 2025 19:37
@ladinesa ladinesa merged commit c999500 into develop Jan 20, 2025
4 checks passed
@ladinesa ladinesa deleted the patch_fhiaims_nelectrons branch January 29, 2025 11:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working. It also represents a quick fix in response to a bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants