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

Rename nprim to nexp where appropriate #357

Merged
merged 1 commit into from
Jul 4, 2024

Conversation

tovrstra
Copy link
Member

@tovrstra tovrstra commented Jul 4, 2024

This is an attempt to solve a terminology issue that has caused a lot of confusion in the past. It addresses part of #256. (I'm going through these clarifications before continuing with #191 to make future PRs related to #191 easier to process.)

The term number of primitives, abbreviated now in IOData is nprim (property of the Shell class), has different interpretations in different context and file formats:

  • In the FCHK format, the field Number of primitives per shell is an array with contraction lengths. Because this is one of the earliest supported file formats, it also led to the name nprim in the Shell class.
  • In the WFN and WFX formats, the GAUSSIAN line contains a number of primitives, e.g. 74 PRIMITIVES, which refers to the total number of individual basis functions, e.g. three primitives for a p-type shell (X, Y and Z), etc.
  • In the MWFN format, Nprims refers to the sum of all contraction lengths, counting those of SP generalized contractions twice, and Nprimshell is the sum of all contraction lengths, counting those of SP generalized contractions once.

I've considered a few alternatives for the name of the Shell.nprim property:

  • I do not like contraction_length, too long. This name is also assumes some familiarity with basis set terminology.
  • nexp (as in this PR) refers to its literal meaning, i.e. number of exponents in a contracted shell. (It is also implemented as return len(self.exponents) I prefer this one because it is short and semantic. It also uses the nsomething form to refer to the size of an array along one of its dimensions, as found elsewhere in IOData.
  • Also nexponent is possible, a bit clearer, more typing.

I'm trying to make only one name change per PR, to keep things easy to review. In case of concerns about other attribute names, properties, please add them to #256.

nprim-like variables in the WFN, WFX and MWFN formats were not renamed when they referred to the meaning of that file format (and not the one we had in the Shell class.)

I will YOLO-merge this on Wednesday, July 10 unless reviewed earlier.

Summary by Sourcery

This pull request addresses a terminology issue by renaming the nprim property to nexp across various files and test cases to improve clarity and consistency in the codebase.

  • Enhancements:
    • Renamed the nprim property to nexp across multiple files to improve clarity and consistency in terminology.
  • Tests:
    • Updated test cases to reflect the renaming of nprim to nexp.

@tovrstra tovrstra added the API breaking Should be done first to stabilize API label Jul 4, 2024
Copy link

deepsource-io bot commented Jul 4, 2024

Here's the code health analysis summary for commits 0ca750f..e025110. View details on DeepSource ↗.

Analysis Summary

AnalyzerStatusSummaryLink
DeepSource Shell LogoShell✅ SuccessView Check ↗
DeepSource Python LogoPython✅ SuccessView Check ↗

💡 If you’re a repository administrator, you can configure the quality gates from the settings.

@tovrstra
Copy link
Member Author

tovrstra commented Jul 4, 2024

@sourcery-ai review

Copy link
Member

@PaulWAyers PaulWAyers left a comment

Choose a reason for hiding this comment

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

Thanks for the detailed explanation. I think nexp is a clear name, and the documentation seems clear when it is invoked too.

@tovrstra
Copy link
Member Author

tovrstra commented Jul 4, 2024

Thanks for reviewing Paul!

@tovrstra tovrstra merged commit f520645 into theochem:main Jul 4, 2024
12 checks passed
@tovrstra tovrstra deleted the rename-nprim branch July 4, 2024 18:29
Copy link
Contributor

sourcery-ai bot commented Jul 5, 2024

Reviewer's Guide by Sourcery

This pull request addresses a terminology issue by renaming the nprim variable to nexp across multiple files. The changes include updating variable names in loops, function calls, and assertions to reflect the new terminology. This aims to reduce confusion and improve code clarity.

File-Level Changes

Files Changes
iodata/formats/fchk.py
iodata/formats/molden.py
iodata/formats/mwfn.py
iodata/formats/wfn.py
iodata/formats/wfx.py
Renamed nprim to nexp in multiple locations, updated variable names in loops and function calls to reflect the new terminology.
iodata/test/test_basis.py
iodata/test/test_fchk.py
iodata/test/test_molden.py
iodata/test/test_mwfn.py
iodata/test/test_molekel.py
Renamed nprim to nexp in assertions.
iodata/basis.py Renamed nprim to nexp in class Shell, updated docstrings to reflect the new terminology.

Tips
  • Trigger a new Sourcery review by commenting @sourcery-ai review on the pull request.
  • Continue your discussion with Sourcery by replying directly to review comments.
  • You can change your review settings at any time by accessing your dashboard:
    • Enable or disable the Sourcery-generated pull request summary or reviewer's guide;
    • Change the review language;
  • You can always contact us if you have any questions or feedback.

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @tovrstra - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟡 Testing: 4 issues found
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment to tell me if it was helpful.

Comment on lines +97 to +101
assert shells[0].nexp == 6
assert shells[1].nexp == 3
assert shells[2].nexp == 1
assert shells[3].nexp == 2
assert shells[4].nexp == 1
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion (testing): Consider adding edge cases for nexp values

It would be beneficial to add tests for edge cases such as nexp being 0 or negative, even if these cases are not expected in normal operation. This ensures robustness against unexpected input.

Suggested change
assert shells[0].nexp == 6
assert shells[1].nexp == 3
assert shells[2].nexp == 1
assert shells[3].nexp == 2
assert shells[4].nexp == 1
assert shells[0].nexp == 6
assert shells[1].nexp == 3
assert shells[2].nexp == 1
assert shells[3].nexp == 2
assert shells[4].nexp == 1
assert all(shell.nexp >= 0 for shell in shells)

Comment on lines 123 to +126
assert mol.title == "h_sto3g"
assert len(mol.obasis.shells) == 1
assert mol.obasis.nbasis == 1
assert mol.obasis.shells[0].nprim == 3
assert mol.obasis.shells[0].nexp == 3
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion (testing): Add tests for invalid nexp values

Consider adding tests to handle invalid nexp values, such as non-integer or negative values, to ensure the system behaves correctly under these conditions.

Comment on lines +43 to +52
assert_equal(np.sum([shell.nexp * shell.nbasis for shell in mol.obasis.shells]), 24)
assert_equal(len(mol.obasis.shells), 6)
assert_equal(np.sum([shell.nprim for shell in mol.obasis.shells]), 18)
assert_equal(np.sum([shell.nexp for shell in mol.obasis.shells]), 18)
assert_equal(mol.charge, 0.0)
assert_equal(mol.nelec, 9)
assert_equal(mol.natom, 4)
assert_equal(mol.energy, -3.90732095e01)
assert_allclose([shell.angmoms[0] for shell in mol.obasis.shells], [0, 0, 1, 0, 0, 0])
assert_allclose([shell.icenter for shell in mol.obasis.shells], [0, 0, 0, 1, 2, 3])
assert_allclose([shell.nprim for shell in mol.obasis.shells], [3, 3, 3, 3, 3, 3])
assert_allclose([shell.nexp for shell in mol.obasis.shells], [3, 3, 3, 3, 3, 3])
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion (testing): Add tests for boundary values of nexp

Consider adding tests for boundary values of nexp, such as 0 or very large numbers, to ensure the system can handle these cases without issues.

@@ -122,7 +122,7 @@ def test_load_mkl_ethanol():
# assert_allclose(mol.obasis.shells[-1].coeffs[-1, -1], 0.181380684)
assert_equal([shell.icenter for shell in mol.obasis.shells[:5]], [0, 0, 1, 1, 1])
assert_equal([shell.angmoms[0] for shell in mol.obasis.shells[:5]], [0, 0, 0, 0, 1])
assert_equal([shell.nprim for shell in mol.obasis.shells[:5]], [3, 1, 6, 3, 3])
assert_equal([shell.nexp for shell in mol.obasis.shells[:5]], [3, 1, 6, 3, 3])
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion (testing): Include tests for invalid nexp values

It would be beneficial to include tests for invalid nexp values, such as non-integer or negative values, to ensure the system handles these gracefully.

Suggested change
assert_equal([shell.nexp for shell in mol.obasis.shells[:5]], [3, 1, 6, 3, 3])
assert_equal([shell.nexp for shell in mol.obasis.shells[:5]], [3, 1, 6, 3, 3])
assert_equal(mol.mo.coeffs.shape, (39, 39))
assert_equal(mol.mo.energies.shape, (39,))
assert_equal(mol.mo.occs.shape, (39,))
with pytest.raises(ValueError):
mol.obasis.shells[0].nexp = -1
with pytest.raises(TypeError):
mol.obasis.shells[0].nexp = "invalid"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API breaking Should be done first to stabilize API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants