Skip to content

Commit

Permalink
Fix exact floating-point comparison causing flaky test (#9021)
Browse files Browse the repository at this point in the history
This triggered semi-reliably on Windows with all optional packages
installed, with the output different by 2 ULP.  It's a floating-point
equality check, so what we care about asserting is approximate equality,
not exact.
  • Loading branch information
jakelishman authored Oct 28, 2022
1 parent b45afea commit 7987742
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions test/python/opflow/test_aer_pauli_expectation.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,12 +279,12 @@ def test_expectation_with_coeff(self):
with self.subTest("integer coefficients"):
exp = 3 * ~StateFn(X) @ (2 * Minus)
target = self.sampler.convert(self.expect.convert(exp)).eval()
self.assertEqual(target, -12)
self.assertAlmostEqual(target, -12)

with self.subTest("complex coefficients"):
exp = 3j * ~StateFn(X) @ (2j * Minus)
target = self.sampler.convert(self.expect.convert(exp)).eval()
self.assertEqual(target, -12j)
self.assertAlmostEqual(target, -12j)


if __name__ == "__main__":
Expand Down

0 comments on commit 7987742

Please sign in to comment.