Skip to content

Commit 55b3fd5

Browse files
Jammy2211Jammy2211claude
authored
test: skip jax-backed tests when jax is absent (Python matrix) (#1358)
These tests exercise jax-only code paths (vmapped profiles / blackjax NUTS / nufft sparse operator / use_jax=True), so they need jax installed to run — it ships via the [optional] extras and is present in the per-repo CI (3.12/3.13). The PyAutoBuild Python Version Matrix installs the NumPy-only stack (and jax can't install on 3.9 anyway), so guard the 3 affected test(s) with a skipif on jax availability rather than letting them ModuleNotFoundError. Numpy-only tests in the same files are unaffected. Co-authored-by: Jammy2211 <JNightingale2211@gmail.com> Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
1 parent ae47751 commit 55b3fd5

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

test_autofit/analysis/test_latent_variables.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
1+
import importlib.util
2+
13
import numpy as np
24
import pytest
35

46
import autofit as af
57
from autoconf.conf import with_config
68
from autofit import DirectoryPaths, SamplesPDF
9+
10+
# This test drives the `use_jax=True` path, which needs jax installed (it ships
11+
# via the `[optional]` extras). The NumPy-only Python-version matrix has no jax,
12+
# so skip there rather than fail.
13+
requires_jax = pytest.mark.skipif(
14+
importlib.util.find_spec("jax") is None,
15+
reason="requires jax (installed via the [optional] extras; absent on the NumPy-only matrix env)",
16+
)
717
from autofit.text.text_util import result_info_from
818

919

@@ -104,6 +114,7 @@ def test_latent_batch_mode_default_is_vmap():
104114
assert Analysis.LATENT_BATCH_MODE == "vmap"
105115

106116

117+
@requires_jax
107118
def test_latent_batch_mode_invalid_value_raises_clear_error():
108119
"""
109120
Misspelt `LATENT_BATCH_MODE` values should fail with a clear ValueError

test_autofit/non_linear/search/mcmc/test_blackjax_nuts.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import importlib.util
12
import os
23
import numpy as np
34
import pytest
@@ -7,6 +8,14 @@
78
_times_from_positions,
89
)
910

11+
# `_times_from_positions` is jax-backed; it needs jax installed to run (jax
12+
# ships via the `[optional]` extras). The NumPy-only Python-version matrix has
13+
# no jax, so skip there rather than fail.
14+
requires_jax = pytest.mark.skipif(
15+
importlib.util.find_spec("jax") is None,
16+
reason="requires jax (installed via the [optional] extras; absent on the NumPy-only matrix env)",
17+
)
18+
1019
pytestmark = pytest.mark.filterwarnings("ignore::FutureWarning")
1120

1221

@@ -92,6 +101,7 @@ def test__identifier_fields_distinguish_run_shape():
92101
assert (c.num_warmup, c.num_samples, c.num_chains) == (100, 999, 1)
93102

94103

104+
@requires_jax
95105
def test__times_from_positions_clamps_low_ess():
96106
# Construct a degenerate "chain" — every sample is identical → ESS
97107
# collapses; the clamp must keep ``times`` finite and equal to N.
@@ -108,6 +118,7 @@ def test__times_from_positions_clamps_low_ess():
108118
assert np.all(times <= n_samples + 1e-9)
109119

110120

121+
@requires_jax
111122
def test__times_from_positions_independent_chain():
112123
# Independent draws → ESS ≈ N, so τ ≈ 1.
113124
rng = np.random.default_rng(1)

0 commit comments

Comments
 (0)