XanaduAI / blackbird

Blackbird is a quantum assembly language for continuous-variable quantum computation, that can be used to program Xanadu's quantum photonics hardware and Strawberry Fields simulator.
https://quantum-blackbird.readthedocs.io
Apache License 2.0
70 stars 26 forks source link

Switch to `isclose` and `allclose` instead of equality checks in tests #45

Closed thisac closed 3 years ago

thisac commented 3 years ago

On some computers precision issues turn up causing some tests to fail.

As noted in #44, it e.g. happens on aarch64 systems for the test_auxiliary.TestExpression.test_brackets test. It also seems to be the case that the test_auxiliary.TestFunction.test_function_arccos fails on the Mac M1 architecture. The latter is due to the lvalue being complex while the rvalue is not (e.g. np.arccos(0.543) is not equal to np.arccos(0.543 + 0j))

Changes: All tests that are comparing either floats/complex or mathematical statements are changed to use isclose or allclose instead of comparing with ==.

codecov[bot] commented 3 years ago

Codecov Report

Merging #45 (d944105) into master (0d9c3b2) will not change coverage. The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master      #45   +/-   ##
=======================================
  Coverage   97.17%   97.17%           
=======================================
  Files          12       12           
  Lines        1914     1914           
=======================================
  Hits         1860     1860           
  Misses         54       54           
Impacted Files Coverage Δ
blackbird_python/blackbird/tests/test_auxiliary.py 100.00% <100.00%> (ø)
blackbird_python/blackbird/tests/test_listener.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 0d9c3b2...d944105. Read the comment docs.