Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 28 additions & 13 deletions src/openfermion/linalg/davidson_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import logging
import unittest

import pytest
import numpy
import numpy.linalg
import scipy.linalg
Expand Down Expand Up @@ -406,9 +407,10 @@ def test_get_lowest_z_real(self):
initial_guess = 1.0j * numpy.random.rand(dimension, n_lowest)
numpy.random.seed(dimension * 2)
initial_guess += numpy.random.rand(dimension, n_lowest)
success, eigen_values, eigen_vectors = davidson.get_lowest_n(
n_lowest, initial_guess, max_iterations=10
)
with pytest.warns(RuntimeWarning):
success, eigen_values, eigen_vectors = davidson.get_lowest_n(
n_lowest, initial_guess, max_iterations=10
)

# one half of the eigenvalues is -1 and the other half is +1, together
# with the coefficient.
Expand Down Expand Up @@ -436,9 +438,13 @@ def test_get_lowest_y_real_fail(self):
initial_guess = 1.0j * numpy.random.rand(dimension, n_lowest)
numpy.random.seed(dimension * 2)
initial_guess += numpy.random.rand(dimension, n_lowest)
success, _, eigen_vectors = davidson.get_lowest_n(
n_lowest, initial_guess, max_iterations=10
)
with pytest.warns(
RuntimeWarning,
match=("Unable to get real only eigenvectors|Initial guess is not real only!"),
):
success, _, eigen_vectors = davidson.get_lowest_n(
n_lowest, initial_guess, max_iterations=10
)

self.assertFalse(success)

Expand All @@ -458,9 +464,13 @@ def test_get_lowest_y_real(self):
initial_guess = 1.0j * numpy.random.rand(dimension, n_lowest)
numpy.random.seed(dimension * 2)
initial_guess += numpy.random.rand(dimension, n_lowest)
success, eigen_values, eigen_vectors = davidson.get_lowest_n(
n_lowest, initial_guess, max_iterations=10
)
with pytest.warns(
RuntimeWarning,
match=("Unable to get real only eigenvectors|Initial guess is not real only!"),
):
success, eigen_values, eigen_vectors = davidson.get_lowest_n(
n_lowest, initial_guess, max_iterations=10
)

# one half of the eigenvalues is -1 and the other half is +1, together
# with the coefficient.
Expand All @@ -487,9 +497,13 @@ def test_get_lowest_y_complex(self):
initial_guess = 1.0j * numpy.random.rand(dimension, n_lowest)
numpy.random.seed(dimension * 2)
initial_guess += numpy.random.rand(dimension, n_lowest)
success, eigen_values, eigen_vectors = davidson.get_lowest_n(
n_lowest, initial_guess, max_iterations=10
)
with pytest.warns(
RuntimeWarning,
match=("Unable to get real only eigenvectors|Initial guess is not real only!"),
):
success, eigen_values, eigen_vectors = davidson.get_lowest_n(
n_lowest, initial_guess, max_iterations=10
)

# one half of the eigenvalues is -1 and the other half is +1, together
# with the coefficient.
Expand Down Expand Up @@ -658,7 +672,8 @@ def test_append_vectors_big_col(self):
"""Test append_random_vectors() with too many failed trial."""
row = 10
vectors = numpy.eye(row, row)
new_vectors = append_random_vectors(vectors, 1)
with pytest.warns(RuntimeWarning):
new_vectors = append_random_vectors(vectors, 1)

self.assertTrue(numpy.allclose(new_vectors, vectors))

Expand Down
4 changes: 3 additions & 1 deletion src/openfermion/ops/operators/qubit_operator_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,9 @@ def check_sum(operators, operator):
def test_get_operator_groups_zero():
"""Tests get_operator_groups() with one group."""
operator = generate_operator(0, 20)
operator_groups = list(operator.get_operator_groups(0))
with pytest.warns(RuntimeWarning, match="Invalid num_groups 0 < 1"):
# Min. is 1; get_operator_groups() should issue warning and use 1.
operator_groups = list(operator.get_operator_groups(0))

# Using 1 group instead.
assert check_length(operator_groups, [20])
Expand Down
Loading