Skip to content

Commit 73cdf06

Browse files
Jammy2211Jammy2211claude
authored
fix(transformer): tell Python <3.12 users to upgrade, not to pip install nufftax (#409)
The nufftax ModuleNotFoundError said "Install it via the command `pip install nufftax`". On Python 3.11 that is actively bad advice. The nufftax releases that work with our JAX stack (0.4.x) declare requires_python >= 3.12, so pip resolves 0.6.x instead — and both 0.6.x releases break the interferometer inversion: - 0.6.0 uses jax.interpreters.batching.not_mapped, removed in JAX 0.10 - 0.6.1 cannot handle the rank-4 input transform_mapping_matrix produces under vmap (ValueError: too many values to unpack (expected 3)) So a 3.11 user who follows the old message installs a broken nufftax and fails partway through a fit instead of at import — strictly worse than the original error. There is currently no nufftax release that both installs on 3.11 and works. The message now branches on sys.version_info: below 3.12 it says not to install nufftax and offers upgrading to 3.12+ or the pynufft backend; 3.12+ keeps the existing text. Both branches covered by tests. Only the error text changes — no behaviour change on 3.12+. Claude-Session: https://claude.ai/code/session_012EZTtyLUAyKWuATyk4mkcm Co-authored-by: Jammy2211 <JNightingale2211@gmail.com> Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 1893885 commit 73cdf06

2 files changed

Lines changed: 74 additions & 0 deletions

File tree

autoarray/operators/transformer.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import copy
22
import numpy as np
3+
import sys
34
import warnings
45
from typing import Optional, Tuple
56

@@ -41,6 +42,32 @@ def pynufft_exception():
4142

4243

4344
def nufftax_exception():
45+
# On Python 3.11 `pip install nufftax` is actively bad advice. The releases
46+
# that work with our JAX stack (0.4.x) require Python >= 3.12, so pip resolves
47+
# 0.6.x instead — and 0.6.0/0.6.1 both break the interferometer inversion
48+
# (0.6.0 uses `jax.interpreters.batching.not_mapped`, removed in JAX 0.10;
49+
# 0.6.1 cannot handle the rank-4 input `transform_mapping_matrix` produces
50+
# under vmap). There is currently no nufftax release that both installs on
51+
# 3.11 and works, so send 3.11 users to 3.12+ or to the pynufft backend.
52+
if sys.version_info < (3, 12):
53+
raise ModuleNotFoundError(
54+
"\n--------------------\n"
55+
"You are attempting to perform interferometer analysis with the default "
56+
f"JAX-native `TransformerNUFFT`, on Python {sys.version_info.major}.{sys.version_info.minor}.\n\n"
57+
"The optional library nufftax (https://github.com/GragasLab/nufftax) is not installed, "
58+
"and on this Python version it CANNOT be usefully installed:\n\n"
59+
" - nufftax releases that work with PyAutoArray require Python >= 3.12.\n"
60+
" - The releases that do install here (0.6.x) are incompatible with the "
61+
"JAX version PyAutoArray requires, and fail partway through a fit.\n\n"
62+
"Do NOT `pip install nufftax` on this Python version. Instead either:\n\n"
63+
" 1. Upgrade to Python 3.12 or newer (recommended), then "
64+
"`pip install 'autoarray[optional]'`; or\n"
65+
" 2. Use the legacy pynufft backend, by passing "
66+
"`transformer_class=TransformerNUFFTPyNUFFT` and running "
67+
"`pip install pynufft==2022.2.2`.\n\n"
68+
"----------------------"
69+
)
70+
4471
raise ModuleNotFoundError(
4572
"\n--------------------\n"
4673
"You are attempting to perform interferometer analysis with the default "

test_autoarray/operators/test_transformer.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,3 +306,50 @@ def f(img_arr):
306306
assert np.asarray(result) == pytest.approx(
307307
np.asarray(expected), rel=1.0e-6, abs=1.0e-10
308308
)
309+
310+
311+
def test__nufftax_exception__pre_3_12_tells_user_to_upgrade_not_to_pip_install():
312+
"""
313+
On Python < 3.12 there is no usable nufftax release: the versions that work
314+
require >= 3.12, and the ones that do install (0.6.x) break mid-fit. The
315+
error must therefore steer the user away from `pip install nufftax`.
316+
"""
317+
import collections
318+
from unittest import mock
319+
from autoarray.operators import transformer
320+
321+
version_info = collections.namedtuple(
322+
"version_info", "major minor micro releaselevel serial"
323+
)
324+
325+
with mock.patch.object(
326+
transformer.sys, "version_info", version_info(3, 11, 0, "final", 0)
327+
):
328+
with pytest.raises(ModuleNotFoundError) as exc:
329+
transformer.nufftax_exception()
330+
331+
message = str(exc.value)
332+
assert "Python 3.11" in message
333+
assert "Do NOT `pip install nufftax`" in message
334+
assert "Python 3.12 or newer" in message
335+
assert "TransformerNUFFTPyNUFFT" in message
336+
337+
338+
def test__nufftax_exception__3_12_and_later_keeps_the_plain_install_instruction():
339+
import collections
340+
from unittest import mock
341+
from autoarray.operators import transformer
342+
343+
version_info = collections.namedtuple(
344+
"version_info", "major minor micro releaselevel serial"
345+
)
346+
347+
with mock.patch.object(
348+
transformer.sys, "version_info", version_info(3, 12, 0, "final", 0)
349+
):
350+
with pytest.raises(ModuleNotFoundError) as exc:
351+
transformer.nufftax_exception()
352+
353+
message = str(exc.value)
354+
assert "Install it via the command `pip install nufftax`" in message
355+
assert "Do NOT" not in message

0 commit comments

Comments
 (0)