Skip to content

V2 pint unit management - #1684

Open
amandadumi wants to merge 38 commits into
cclib:mainfrom
amandadumi:v2_pint
Open

amandadumi wants to merge 38 commits into
cclib:mainfrom
amandadumi:v2_pint

Conversation

@amandadumi

@amandadumi amandadumi commented Oct 15, 2025

Copy link
Copy Markdown
Member

This pull request integrates pint in for managing units. Specifically this pull request

  • starts a single unit registry for the code base
  • attaches units to the scfenergies attributes
  • changes the test which use scfenergies, but don't have units implemented themselves to reference just the magnitude of the unit-labeled number (testMP and testCC)

@codecov

codecov Bot commented Jan 7, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 84.96732% with 23 lines in your changes missing coverage. Please review.
✅ Project coverage is 12.31%. Comparing base (fbde549) to head (fa1a4ee).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
cclib/attribute_parsers/scfenergies.py 67.85% 9 Missing ⚠️
cclib/attributes/attribute.py 28.57% 5 Missing ⚠️
cclib/attribute_parsers/moenergies.py 88.23% 4 Missing ⚠️
cclib/attribute_parsers/mpenergies.py 90.69% 3 Missing and 1 partial ⚠️
cclib/attribute_parsers/coreelectrons.py 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1684      +/-   ##
==========================================
+ Coverage   12.07%   12.31%   +0.24%     
==========================================
  Files         116      117       +1     
  Lines       19159    19221      +62     
  Branches     4483     4485       +2     
==========================================
+ Hits         2313     2368      +55     
- Misses      16763    16770       +7     
  Partials       83       83              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@amandadumi
amandadumi marked this pull request as ready for review January 9, 2026 16:13
@amandadumi
amandadumi requested a review from shivupa January 21, 2026 02:40
Comment thread cclib/attribute_parsers/ccenergies.py Outdated

@berquist berquist left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is great. The one thing IMO we need to decide on is where exactly to attach the units in the parsers. My initial thought was right at the parse location (utils.float(line.split()[0]) * ureg.... etc.) but there is something to be said for in the return value like return {scfenergies.__name__: [constructed_data] * ureg.hartree}. That way is cleaner but further from where the data was parsed, esp. if it's in non-standard units.

Comment thread cclib/__init__.py Outdated
Comment thread cclib/__init__.py Outdated
Comment thread cclib/attribute_parsers/scfenergies.py Outdated
Comment thread test/data/testCC.py Outdated
@amandadumi

Copy link
Copy Markdown
Member Author

This is great. The one thing IMO we need to decide on is where exactly to attach the units in the parsers. My initial thought was right at the parse location (utils.float(line.split()[0]) * ureg.... etc.) but there is something to be said for in the return value like return {scfenergies.__name__: [constructed_data] * ureg.hartree}. That way is cleaner but further from where the data was parsed, esp. if it's in non-standard units.

Yes this is true. I have introduced one change, but i think there may be another.

  • I made one change which is instantiating the list with units as the array is created.
  • What might be missing is attaching units to the specific parsed value that results from this entry into the specific parser.
# initialize empty array with units attached
>>> a = np.array([])*ureg.hartree
>>> a
<Quantity([], 'hartree')>

# adding unit tagged option of same unit is a clean process.
>>> b = 4.5*ureg.hartree
>>> b
<Quantity(4.5, 'hartree')>
>>> np.append(a,b)
<Quantity([4.5], 'hartree')>

# if for any reason different units come up during parsing, this can still be cleanly kept. (can't think of a use case, but just what's possible)
>>> c = 3.5*ureg.eV
>>> c
<Quantity(3.5, 'electron_volt')>
>>> np.append(a,c)
<Quantity([0.12862263], 'hartree')>

From in person conversations, I am just attaching native units from the given program and we will determine when to convert to cclib units at a different point, but it's not clear where that will happen yet.

@amandadumi
amandadumi requested a review from berquist August 11, 2026 01:38
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