Tests do not pass on Apple M1 running python 3
Closed this issue · 1 comments
mathDR commented
Hi! I just git cloned the repo into a new virtual environment. I ran pip install -e .
on the repo, then pytest tests
. That failed (I needed to pip install pytest
).
After running pytest tests
I show 71 failed, 11 passed, 2 skipped in 14.64 s.
I am running macOS Monterey on an Apple M1 Max running python 3.9.10.
A particular instance was running pytest test_noise.py
:
test_noise.py FF. [100%]
======================================================= FAILURES ========================================================
_____________________________________________________ test_diagonal _____________________________________________________
def test_diagonal():
N = 50
random = np.random.default_rng(9432)
diag = random.normal(size=N)
noise = tinygp.noise.Diagonal(diag=diag)
> check_noise_model(noise, np.diag(diag))
test_noise.py:42:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
noise = Diagonal(diag=array([ 1.58860105, 0.38873816, 0.43751174, -0.11334617, 0.14765921,
-1.65553085, -0.62329537,...44718, 1.76214413, 1.19522174, -0.97858096,
-0.46264887, -1.94102813, 0.30831414, -0.31562414, -1.43893292]))
dense_rep = array([[ 1.58860105, 0. , 0. , ..., 0. ,
0. , 0. ],
[ 0. ...414, 0. ],
[ 0. , 0. , 0. , ..., 0. ,
0. , -1.43893292]])
def check_noise_model(noise, dense_rep):
random = np.random.default_rng(6675)
np.testing.assert_allclose(noise.diagonal(), jnp.diag(dense_rep))
np.testing.assert_allclose(noise + np.zeros_like(dense_rep), dense_rep)
y1 = random.normal(size=dense_rep.shape)
> np.testing.assert_allclose(noise + y1, dense_rep + y1)
E AssertionError:
E Not equal to tolerance rtol=1e-07, atol=0
E
E Mismatched elements: 6 / 2500 (0.24%)
E Max absolute difference: 1.392429e-07
E Max relative difference: 1.21363102e-06
E x: array([[ 1.922384, -1.28015 , -0.315337, ..., -0.567188, 0.508422,
E -0.657338],
E [-1.391238, 0.80504 , 0.164051, ..., 0.481563, -1.469477,...
E y: array([[ 1.922384, -1.28015 , -0.315337, ..., -0.567188, 0.508422,
E -0.657338],
E [-1.391238, 0.80504 , 0.164051, ..., 0.481563, -1.469477,...
test_noise.py:17: AssertionError
______________________________________________________ test_banded ______________________________________________________
def test_banded():
N, J = 50, 5
random = np.random.default_rng(9432)
# Create a random symmetric banded matrix
R = random.normal(size=(N, N))
R[np.triu_indices(N, J + 1)] = 0
R[np.tril_indices(N)] = R.T[np.tril_indices(N)]
# Extract the diagonal and off-diagonal elements
diag = np.diag(R)
off_diags = np.zeros((N, J))
for j in range(J):
off_diags[: N - j - 1, j] = R[
(np.arange(0, N - j - 1), np.arange(j + 1, N))
]
noise = tinygp.noise.Banded(diag=diag, off_diags=off_diags)
> check_noise_model(noise, R)
test_noise.py:63:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
noise = Banded(diag=array([ 1.58860105, -2.16543909, -0.52223767, 2.62247777, -0.51765523,
0.41917606, 1.36994167, ....00000000e+00],
[ 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00]]))
dense_rep = array([[ 1.58860105, 0.38873816, 0.43751174, ..., 0. ,
0. , 0. ],
[ 0.3887381...348, -1.30796807],
[ 0. , 0. , 0. , ..., 2.26915227,
-1.30796807, -1.53816113]])
def check_noise_model(noise, dense_rep):
random = np.random.default_rng(6675)
np.testing.assert_allclose(noise.diagonal(), jnp.diag(dense_rep))
np.testing.assert_allclose(noise + np.zeros_like(dense_rep), dense_rep)
y1 = random.normal(size=dense_rep.shape)
> np.testing.assert_allclose(noise + y1, dense_rep + y1)
E AssertionError:
E Not equal to tolerance rtol=1e-07, atol=0
E
E Mismatched elements: 52 / 2500 (2.08%)
E Max absolute difference: 3.63120751e-07
E Max relative difference: 1.09484999e-05
E x: array([[ 1.922384e+00, -8.914119e-01, 1.221748e-01, ..., -5.671883e-01,
E 5.084218e-01, -6.573380e-01],
E [-1.002500e+00, -1.749138e+00, 2.532022e+00, ..., 4.815633e-01,...
E y: array([[ 1.922384e+00, -8.914119e-01, 1.221748e-01, ..., -5.671883e-01,
E 5.084218e-01, -6.573380e-01],
E [-1.002500e+00, -1.749137e+00, 2.532022e+00, ..., 4.815633e-01,...
test_noise.py:17: AssertionError
================================================ short test summary info ================================================
FAILED test_noise.py::test_diagonal - AssertionError:
FAILED test_noise.py::test_banded - AssertionError:
============================================== 2 failed, 1 passed in 0.50s ==============================================
dfm commented
This is to be expected - the tests must be run with double precision enabled. The preferred mode for running the tests (as described in the docs) is with tox which will handle the settings appropriately.