-
Notifications
You must be signed in to change notification settings - Fork 209
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
Fix the AngularMomentum
(again)
#1292
Fix the AngularMomentum
(again)
#1292
Conversation
Prior to this fix, the `AngularMomentum` operator was working on the assumption that the number of alpha-spin particles would always exceed the number of beta-spin particles (for non-singlet systems). However, this is not guaranteed to be the case. This commit fixes this problem by using a symmetric formula for S^2 which is the average of the two cases (alpha- vs. beta-spin particles exceeding the other).
When dealing with active spaces obtained from unrestricted-spin orbitals, the alpha-beta overlap matrix which is used to construct the S^2 operator can become non-unitary (for example, when the active set of alpha- and beta-spin orbitals do not span the same space). This can result in an <S^2> value measured on the active space that is largely different from (e.g.) the UHF <S^2> value. More importantly, when this is the case, the difference between these two <S^2> values is "hidden" in the inactive+inactive and inactive+active interactions. Especially when spin contamination is present, this can lead to vastly unexpected results and may indicate a poor choice of active space.
528f24b
to
531bb81
Compare
Pull Request Test Coverage Report for Build 7083799155
💛 - Coveralls |
""" | ||
self.num_spatial_orbitals = num_spatial_orbitals | ||
self._overlap: np.ndarray | None = None | ||
self.overlap = overlap |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For my education: isn't this overridden by the overlap
property?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see it now (I think! 😺) this line will call the setter and apply the initialization logic. But then is there a point to type-hint self._overlap
a union type? Couldn't it be just np.ndarray
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The first line here makes sure that pylint does not complain about the private _overlap
attribute not being defined inside the __init__
(because otherwise it would be defined inside the property
method.
I am typing it for the sake of completeness 👍
self.overlap = overlap | ||
|
||
@property | ||
def overlap(self) -> np.ndarray | None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it ever possible for this to return None
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this can be left as None
in which case the methods will internally treat it as an identity matrix of the correct size (but there is no need to store that square matrix so I left it as None
👍)
* fix: use the symmetric formula for S^2 Prior to this fix, the `AngularMomentum` operator was working on the assumption that the number of alpha-spin particles would always exceed the number of beta-spin particles (for non-singlet systems). However, this is not guaranteed to be the case. This commit fixes this problem by using a symmetric formula for S^2 which is the average of the two cases (alpha- vs. beta-spin particles exceeding the other). * feat: log a warning when the alpha-beta overlap is non-unitary When dealing with active spaces obtained from unrestricted-spin orbitals, the alpha-beta overlap matrix which is used to construct the S^2 operator can become non-unitary (for example, when the active set of alpha- and beta-spin orbitals do not span the same space). This can result in an <S^2> value measured on the active space that is largely different from (e.g.) the UHF <S^2> value. More importantly, when this is the case, the difference between these two <S^2> values is "hidden" in the inactive+inactive and inactive+active interactions. Especially when spin contamination is present, this can lead to vastly unexpected results and may indicate a poor choice of active space. * Add reno * test: add a regression test * fix: update warning tolerance * Linting and formatting * docs: fix verbatim in RST (cherry picked from commit 55e6776)
* fix: use the symmetric formula for S^2 Prior to this fix, the `AngularMomentum` operator was working on the assumption that the number of alpha-spin particles would always exceed the number of beta-spin particles (for non-singlet systems). However, this is not guaranteed to be the case. This commit fixes this problem by using a symmetric formula for S^2 which is the average of the two cases (alpha- vs. beta-spin particles exceeding the other). * feat: log a warning when the alpha-beta overlap is non-unitary When dealing with active spaces obtained from unrestricted-spin orbitals, the alpha-beta overlap matrix which is used to construct the S^2 operator can become non-unitary (for example, when the active set of alpha- and beta-spin orbitals do not span the same space). This can result in an <S^2> value measured on the active space that is largely different from (e.g.) the UHF <S^2> value. More importantly, when this is the case, the difference between these two <S^2> values is "hidden" in the inactive+inactive and inactive+active interactions. Especially when spin contamination is present, this can lead to vastly unexpected results and may indicate a poor choice of active space. * Add reno * test: add a regression test * fix: update warning tolerance * Linting and formatting * docs: fix verbatim in RST (cherry picked from commit 55e6776) Co-authored-by: Max Rossmannek <[email protected]>
Summary
Fixes #1291
Details and comments
See also #1291 (comment) for some more details.