pedrorrivero / qrand

A multiprotocol and multiplatform quantum random number generation framework
https://pypi.org/project/qrand/
Apache License 2.0
23 stars 14 forks source link

Test case associated with `get_random_complex_polar` failing #13

Open Avhijit-codeboy opened 3 years ago

Avhijit-codeboy commented 3 years ago

Describe the bug

TestBitCache.test_get_random_complex_polar test case failing

To Reproduce

Steps to reproduce the behavior:

  1. Go to 'qrng.py'
  2. Make some relevant changes to the file
  3. Git commit the file
  4. See error

Expected behavior

All the test cases passing and the commit being successful.

Screenshots

image

Desktop (please complete the following information):

Additional context

The entire error message -

isort....................................................................Passed
mypy.....................................................................Passed
black....................................................................Passed
flake8...................................................................Passed
pytest...................................................................Failed
- hook id: pytest
- exit code: 1

============================= test session starts =============================
platform win32 -- Python 3.8.3, pytest-6.2.4, py-1.10.0, pluggy-0.13.1
rootdir: F:\QuantumProgrammes\unitaryHack\qrand
plugins: cov-2.11.1
collected 32 items

tests\test_qiskit_bit_generator.py .....................                 [ 65%]
tests\test_qrand.py ..                                                   [ 71%]
tests\test_qrng.py .F.......                                             [100%]

================================== FAILURES ===================================
_________________ TestBitCache.test_get_random_complex_polar __________________

self = <tests.test_qrng.TestBitCache object at 0x000001BCCF8B1E20>

    def test_get_random_complex_polar(self):
        bitgen = QiskitBitGenerator()
        qrng = Qrng(bitgen)
        cache = "100" * 1000
        bitgen.load_cache(cache)
        assert (
            qrng.get_random_complex_polar()
            == 0.4713139887723277 + 0.5910090485061033j
        )
        assert (
            qrng.get_random_complex_polar(4)
            == -1.9263524684802522 - 0.9276824556973191j
        )
>       assert (
            qrng.get_random_complex_polar(4, 3.14)
            == 0.9431657500378959 + 1.1815890375548252j
        )
E       assert (0.9431657500378958+1.1815890375548252j) == (0.9431657500378959 + 1.1815890375548252j)
E        +  where (0.9431657500378958+1.1815890375548252j) = <bound method Qrng.get_random_complex_polar of <qrand.qrng.Qrng object at 0x000001BCCF8B1AF0>>(4, 3.14)
E        +    where <bound method Qrng.get_random_complex_polar of <qrand.qrng.Qrng object at 0x000001BCCF8B1AF0>> = <qrand.qrng.Qrng object at 0x000001BCCF8B1AF0>.get_random_complex_polar

tests\test_qrng.py:57: AssertionError
============================== warnings summary ===============================
tests/test_qiskit_bit_generator.py: 15 warnings
tests/test_qrand.py: 1 warning
tests/test_qrng.py: 9 warnings
  F:\QuantumProgrammes\unitaryHack\qrand\qrand\_qiskit_bit_generator.py:119: FutureWarning: QiskitBitGenerator will be deprecated in version 1.0.0. Use QuantumBitGenerator and QiskitPlatform instead.
    warn(WARNING_MESSAGE, FutureWarning)

tests/test_qrng.py::TestBitCache::test_state
  F:\QuantumProgrammes\unitaryHack\qrand\qrand\qrng.py:308: FutureWarning: state() will be deprecated in version 1.0.0.
    warn(WARNING_MESSAGE, FutureWarning)

-- Docs: https://docs.pytest.org/en/stable/warnings.html

----------- coverage: platform win32, python 3.8.3-final-0 -----------
Coverage HTML written to dir coverage-html

=========================== short test summary info ===========================
FAILED tests/test_qrng.py::TestBitCache::test_get_random_complex_polar - asse...
================== 1 failed, 31 passed, 26 warnings in 2.91s ==================
pedrorrivero commented 3 years ago

The least significant digit is off. This has to do with the way we pack the bits and pythons floating point precision: apparently there is something non-deterministic going on.