Skip to content

Commit

Permalink
take care of values below numerical precision
Browse files Browse the repository at this point in the history
  • Loading branch information
antoniolrm committed Jul 3, 2024
1 parent a87341c commit fc6ee24
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions dacp/tests/test_eigvalsh.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
N = 1000
N_block = 200
deg_n = 5
loop_n = 2
loop_n = 10
window_size = 0.1
window = [-window_size, window_size]
k = 12
Expand Down Expand Up @@ -49,8 +49,11 @@ def compute_errors(H, window, **dacp_kwargs):
]
eta = estimated_errors(eigvals=eigvals_dacp, tol=tol, filter_order=k, window=window)

diff = relative_error - 10 * eta
return diff
diff = (
relative_error * np.heaviside(np.finfo(float).eps - relative_error, 0)
- 10 * eta
)
return np.heaviside(diff - np.finfo(float).eps, 0) * diff


def eigvals_errors_test(deg=False, **dacp_kwargs):
Expand All @@ -73,7 +76,7 @@ def test_eigvals():
Test the eigenvalue with non-degenerate hamiltonians
"""
error_diff = eigvals_errors_test()
assert (error_diff < 0).all(), "Errors don't match the theoretical value."
assert (error_diff <= 0).all(), "Errors don't match the theoretical value."


@pytest.mark.repeat(loop_n)
Expand All @@ -82,4 +85,4 @@ def test_eigvals_deg():
Test the eigenvalue method with degenerate hamiltonians
"""
error_diff = eigvals_errors_test(deg=True, random_vectors=2)
assert (error_diff < 0).all(), "Errors don't match the theoretical value."
assert (error_diff <= 0).all(), "Errors don't match the theoretical value."

0 comments on commit fc6ee24

Please sign in to comment.