Skip to content

Add support for arbitrarily large spin states#1370

Merged
mhucka merged 3 commits into
quantumlib:mainfrom
arettig:spin_naming
Jun 23, 2026
Merged

Add support for arbitrarily large spin states#1370
mhucka merged 3 commits into
quantumlib:mainfrom
arettig:spin_naming

Conversation

@arettig

@arettig arettig commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Fixes #809 Previously the spin state name was obtained using a dictionary mapping integer multiplicity to the name string. Only up to 11 unpaired electrons were supported this way, with an error thrown for anything larger. With this change, larger spins are named via n-multiplet (e.g. 12 unpaired electrons is named 13-multiplet).

Tests are added to check the naming for large spin states is correct, and that non-integer spin states still throw an error.

Previously the spin state name was obtained using a dictionary
mapping	integer	spin state to the name string. Only up to 11 unpaired
electrons were supported this way. With	this change, larger spins
are named via n-multiplet (e.g. 12 unpaired electrons gives
a 13-multiplet state).
@arettig arettig requested a review from mhucka June 22, 2026 19:27

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request updates molecular_data.py to support spin multiplicities greater than 12 by appending a generic _X-multiplet suffix, and adds corresponding unit tests. The reviewer pointed out an inconsistency where float-valued multiplicities (e.g., 2.0) are accepted if they are <= 12 (due to dictionary lookup behavior) but rejected if they are > 12 (due to strict type checking). The reviewer suggested normalizing and validating all integer-valued numeric types (including floats) before processing.

Comment thread src/openfermion/chem/molecular_data.py
The multiplicity parameter of molecular_data is now checked in the
constructor and a ValueError is thrown if a noninteger or negative
value is used. Tests are added to check errors are correctly thrown.
@mhucka mhucka removed the size: S label Jun 23, 2026
Comment thread src/openfermion/chem/molecular_data.py Outdated
Comment thread src/openfermion/chem/molecular_data_test.py Outdated
The error in molecular_data when providing an incorrect
multiplicity needs to remain a MoleculeNameError to ensure
backwards compatibility. This error type now inherits from
ValueError (which makes more sense physically).

@mhucka mhucka left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thank you for this!

@mhucka mhucka added this pull request to the merge queue Jun 23, 2026
Merged via the queue into quantumlib:main with commit dc129bb Jun 23, 2026
23 checks passed
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.

Multiplicity limitation in molecular data

2 participants