OpenFermion icon indicating copy to clipboard operation
OpenFermion copied to clipboard

Tests raise warnings

Open kevinsung opened this issue 7 years ago • 4 comments
trafficstars

On my setup:

src/openfermion/ops/_qubit_operator_test.py::test_get_operator_groups_zero
  /home/kjs/Projects/OpenFermion/src/openfermion/ops/_qubit_operator.py:223: RuntimeWarning: Invalid num_groups 0 < 1.
    RuntimeWarning)

src/openfermion/utils/_davidson_test.py::QubitDavidsonTest::test_get_lowest_y_complex
  /home/kjs/Projects/OpenFermion/src/openfermion/utils/_davidson.py:142: RuntimeWarning: Initial guess is not real only!
    warnings.warn('Initial guess is not real only!', RuntimeWarning)
  /home/kjs/Projects/OpenFermion/src/openfermion/utils/_davidson.py:213: RuntimeWarning: Unable to get real only eigenvectors, return complex vectors instead with success state True.
    .format(success), RuntimeWarning)

src/openfermion/utils/_davidson_test.py::QubitDavidsonTest::test_get_lowest_y_real
  /home/kjs/Projects/OpenFermion/src/openfermion/utils/_davidson.py:142: RuntimeWarning: Initial guess is not real only!
    warnings.warn('Initial guess is not real only!', RuntimeWarning)
  /home/kjs/Projects/OpenFermion/src/openfermion/utils/_davidson.py:213: RuntimeWarning: Unable to get real only eigenvectors, return complex vectors instead with success state True.
    .format(success), RuntimeWarning)

src/openfermion/utils/_davidson_test.py::QubitDavidsonTest::test_get_lowest_y_real_fail
  /home/kjs/Projects/OpenFermion/src/openfermion/utils/_davidson.py:142: RuntimeWarning: Initial guess is not real only!
    warnings.warn('Initial guess is not real only!', RuntimeWarning)
  /home/kjs/Projects/OpenFermion/src/openfermion/utils/_davidson.py:213: RuntimeWarning: Unable to get real only eigenvectors, return complex vectors instead with success state False.
    .format(success), RuntimeWarning)

src/openfermion/utils/_davidson_test.py::QubitDavidsonTest::test_get_lowest_z_real
  /home/kjs/Projects/OpenFermion/src/openfermion/utils/_davidson.py:142: RuntimeWarning: Initial guess is not real only!
    warnings.warn('Initial guess is not real only!', RuntimeWarning)

src/openfermion/utils/_davidson_test.py::DavidsonUtilityTest::test_append_vectors_big_col
  /home/kjs/Projects/OpenFermion/src/openfermion/utils/_davidson.py:413: RuntimeWarning: Unable to generate specified number of random vectors 1: returning 10 in total.
    col, vector_columns), RuntimeWarning)

src/openfermion/utils/_low_rank_test.py::LowRankTest::test_spatial_operator_consistency
  /home/kjs/Projects/OpenFermion/src/openfermion/utils/_low_rank.py:257: ComplexWarning: Casting complex values to real discards the imaginary part
    chemist_two_body_coefficients[p, q, r, s])

kevinsung avatar Aug 14 '18 03:08 kevinsung

@sheilaliuxl this seems to originate from the Davidson code. Any ideas what is going on there?

babbush avatar Aug 14 '18 06:08 babbush

@babbush Yes, that's intentional actually.

  1. Warns users of not that good usage;
  2. Makes sure tests cover this part of script.

What's your suggestion, 1) changing to logging.info, 2) remove completely?

sheilaliuxl avatar Aug 15 '18 19:08 sheilaliuxl

You can test that warnings are properly caught. An example from ops/_symbolic_operator_test.py:

    def test_warnings(self):
        """Test that warnings are raised appropriately."""
        with warnings.catch_warnings(record=True) as w:
            warnings.simplefilter("always")

            op1 = DummyOperator1()
            op1.isclose(op1)

            self.assertEqual(len(w), 1)
            self.assertTrue(issubclass(w[0].category, DeprecationWarning))
            self.assertTrue("deprecated" in str(w[0].message))

kevinsung avatar Aug 15 '18 19:08 kevinsung

@sheilaliuxl sorry for the huge delay! I would suggest taking Kevin's suggestion.

babbush avatar Nov 01 '18 18:11 babbush