scipy: test_lobpcg test failure macOS
Finding a lobpcg error on macOS Python3.7.3. I’ve git bisected and the offending commit is
9c026fb5a937f88ab1e03664bbc1b8d6c0928067
>>> import sys, scipy, numpy; print(scipy.__version__, numpy.__version__, sys.version_info)
1.3.1 1.16.4 sys.version_info(major=3, minor=7, micro=3, releaselevel='final', serial=0)
________________________________________________________________________________ test_tolerance _________________________________________________________________________________
def test_tolerance():
"""Check lobpcg for attainable tolerance in float32.
"""
np.random.seed(1234)
n = 50
m = 4
vals = -np.arange(1, n + 1)
A = diags([vals], [0], (n, n))
A = A.astype(np.float32)
X = np.random.rand(n, m)
X = X.astype(np.float32)
for tol in [1e-4, 1-5, 1e-8, 1e-10]:
eigvals, _ = lobpcg(A, X, tol=tol, maxiter=50, verbosityLevel=0)
> assert_allclose(eigvals, -np.arange(1, 1 + m), atol=1e-5)
E AssertionError:
E Not equal to tolerance rtol=1e-07, atol=1e-05
E
E Mismatch: 100%
E Max absolute difference: 261.09988403
E Max relative difference: 261.09988403
E x: array([260.09988 , -0.999998, -1.999979, -3.000023], dtype=float32)
E y: array([-1, -2, -3, -4])
A = <50x50 sparse matrix of type '<class 'numpy.float32'>'
with 50 stored elements (1 diagonals) in DIAgonal format>
X = array([[0.19151945, 0.62210876, 0.43772775, 0.7853586 ],
[0.77997583, 0.2725926 , 0.27646425, 0.8018722 ],
...17146526, 0.7370865 , 0.12702939, 0.3696499 ],
[0.604334 , 0.10310444, 0.8023742 , 0.94555324]], dtype=float32)
_ = array([[ 1.86979128e-06, 1.00000155e+00, 4.54118663e-06,
1.24531130e-06],
[-4.00696081e-06, 5.41655... -1.26994780e-06],
[-4.44376748e-03, -3.91872845e-09, -6.75413503e-10,
7.24804750e-08]], dtype=float32)
eigvals = array([260.09988 , -0.9999976, -1.9999794, -3.0000226], dtype=float32)
m = 4
n = 50
tol = -4
vals = array([ -1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12, -13,
-14, -15, -16, -17, -18, -19, -20, -21,..., -29, -30, -31, -32, -33, -34, -35, -36, -37, -38, -39,
-40, -41, -42, -43, -44, -45, -46, -47, -48, -49, -50])
scipy/sparse/linalg/eigen/lobpcg/tests/test_lobpcg.py:287: AssertionError
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 25 (25 by maintainers)
Commits related to this issue
- Merge pull request #10725 from lobpcg/lobpcg-10718 MAINT: fix test_lobpcg test failure macOS #10718 — committed to scipy/scipy by rgommers 5 years ago
@rgommers it may be an issue with a low-level library, not written carefully enough to handle round-off errors well. The two main low-level functions used in lobpcg are Cholesky and generalized symmetric eigenvalue solver.
Testing lobpcg in float32 with 4 all positive initial vectors in 50 dim space intentionally pushes lobpcg stability hard, so all low-level libraries need to be stable. The previous lobpcg revision was not tested in float32 at all, and would fail most tests. The merged in #10621 revision is much more stable, and should be usable in practical float32 ruins.
Since I cannot reproduce the error myself, I would need more info to help. The verbosityLevel option in lobpcg is for debugging. verbosityLevel=0 is silent, verbosityLevel=1 puts screen output. Some large value, to my recollection, e.g., verbosityLevel=20 starts saving many intermediate small matrices to the disk. Running with maxiter=1 then maxiter=2 etc on two installs with different libraries and comparing the resulting output matrices, it may be easy to find out which function starts deviating between the two libraries.
Lobpcg is purely python, so easy to check and change if needed. I’d be glad to help, if more info is available what specific part of lobpcg may need more attention.