-
Notifications
You must be signed in to change notification settings - Fork 375
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
modify low_rank for one-body-matrix truncation reference #833
base: master
Are you sure you want to change the base?
Conversation
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.
see comments
def test_one_body_squared_truncated(self): | ||
one_body_matrix = numpy.array([[2.0, 1.5, 0.2],[1.5, 3.0, 1.0],[0.2, 1.0, 4.0]]) | ||
truncation_reference = 1.0 | ||
with self.assertRaises(ValueError): |
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.
why is this raising an error? please use assertRaisesRegex
to test against (and document) the error message you expect
truncation_ref (float): Eigenvalues under this threshold reference will | ||
be truncated for density matrix calculation. |
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.
document that this is optional and that None
turns off truncation
# If the truncation reference is valid, | ||
# build truncated eigenvalues and eigenvectors | ||
# based on the reference for density matrix | ||
if truncation_ref is not None and isinstance(truncation_ref, float): |
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.
Let's rely on python duck typing for the type of truncation_ref
instead of mandating that it is a float. E.g.: what if it's a np.float64
?
@@ -328,3 +328,11 @@ def test_one_body_squared_nonhermitian_raises_error(self): | |||
with self.assertRaises(ValueError): | |||
prepare_one_body_squared_evolution(one_body_matrix, | |||
spin_basis=False) | |||
|
|||
def test_one_body_squared_truncated(self): |
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.
can you add a test that actually works rather then just testing error handling
retained_indices = numpy.where(eigenvalues < truncation_ref)[0] | ||
eigenvalues = eigenvalues[valid_indices] | ||
eigenvectors = eigenvectors[:, valid_indices] | ||
print(f"Retained {len(valid_indices)} eigenvalues and truncated {len(retained_indices)} eigenvalues from the one-body-matrix.") |
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.
please do not print in library code
This MR adds eigenvalue truncation parameter according to incomplete TODO for
prepare_one_body_squared_evolution
method.