unitaryfund / mitiq

Mitiq is an open source toolkit for implementing error mitigation techniques on most current intermediate-scale quantum computers.
https://mitiq.readthedocs.io
GNU General Public License v3.0
363 stars 160 forks source link

Pytest RuntimeWarning #2103

Closed purva-thakre closed 8 months ago

purva-thakre commented 11 months ago

Following warning is raised by pytest:

mitiq/rem/tests/test_inverse_confusion_matrix.py::test_closest_positive_distribution_error
  /home/runner/work/mitiq/mitiq/mitiq/rem/inverse_confusion_matrix.py:145: RuntimeWarning: invalid value encountered in divide
    init_guess /= np.sum(init_guess)

Test in question

https://github.com/unitaryfund/mitiq/blob/3457774734f9759c2a828d84ad5af3801eab23e1/mitiq/rem/tests/test_inverse_confusion_matrix.py#L187-L190

To close this issue, need to disable this warning as the test is expected to raise an error with an invalid input. https://stackoverflow.com/a/23116937

natestemen commented 11 months ago

We should be able to use @pytest.mark.filterwarnings to accomplish this: https://docs.pytest.org/en/6.2.x/warnings.html#pytest-mark-filterwarnings

natestemen commented 8 months ago

More info about writing warnings filters: https://docs.python.org/3/library/warnings.html#warning-filter