PythonOT/POT

Too low tolerance in `test_solve_sample_methods`

Opened this issue · 0 comments

gspr commented

Describe the bug

In test_solve_sample_methods, ot.solve_sample is called with the same random argument in the two first positions. The expectation is, of course, to find a solution of 0. This is checked with np.testing.assert_allclose(sol2.value, 0), with sol2 being said solution. Since assert_allclose defaults to an rtol of 1e-7 and an atol of 0, this means that since the desired value is 0, no deviation is allowed (zero tolerance). This test thus checks for exact equality, and can therefore easily fail.

To Reproduce

Steps to reproduce the behavior:

  1. Load attached pot-bug.npy.gz file into variable x. (The attachment is gzip-compressed because apparently GitHub doesn't like the file extension .npy?)
  2. Compute sol2 = ot.solve_sample(x, x, **{'method': 'gaussian'})).
  3. Observe that np.testing.assert_allclose(sol2.value, 0) fails.

Code sample

See steps to reproduce above.

Expected behavior

The test should use a non-zero atol in assert_allclose to allow for floating point rounding errors.

Environment (please complete the following information):

  • OS: Linux
  • Python version: Python 3.11.2
  • How was POT installed: source, from git commit ab12dd6
  • Build command you used (if compiling from source): pip3 install --user --break-system-packages . from source tree

Output of the following code snippet:

import platform; print(platform.platform())
import sys; print("Python", sys.version)
import numpy; print("NumPy", numpy.__version__)
import scipy; print("SciPy", scipy.__version__)
import ot; print("POT", ot.__version__)
Linux-6.1.0-18-amd64-x86_64-with-glibc2.36
Python 3.11.2 (main, Mar 13 2023, 12:18:29) [GCC 12.2.0]
NumPy 1.24.2
SciPy 1.10.1
POT 0.9.3dev