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

modify low_rank for one-body-matrix truncation reference #833

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dogukantai
Copy link

This MR adds eigenvalue truncation parameter according to incomplete TODO for prepare_one_body_squared_evolution method.

Copy link
Collaborator

@mpharrigan mpharrigan left a 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):
Copy link
Collaborator

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

Comment on lines +176 to +177
truncation_ref (float): Eigenvalues under this threshold reference will
be truncated for density matrix calculation.
Copy link
Collaborator

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):
Copy link
Collaborator

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):
Copy link
Collaborator

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.")
Copy link
Collaborator

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

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.

None yet

2 participants