Commit 4332ec2
fix: make the interferometer simulator's @jax.jit path work
Follow-up to #420/#421, which fixed the imaging simulator and deliberately
excluded the interferometer. Two causes, and one of them was not what #422
predicted.
1. Interferometer was not a registered pytree, so it could not cross the jit
RETURN boundary. Added _register_interferometer_pytrees, mirroring
_register_imaging_pytrees: `data` and `noise_map` dynamic; uv_wavelengths,
real_space_mask, transformer, grids, the over-sample sizes and the Nones as
aux. It must also register Visibilities and VisibilitiesNoiseMap — unlike
Array2D on the imaging path, nothing else registers those, so they surfaced as
bare leaves ("returned a value of type Visibilities at output component [0]").
2. `via_image_from` called `transformer.visibilities_from(image=image)` WITHOUT
`xp=xp`. That is the whole of the second fix — one line.
#422 characterised (2) as `TransformerNUFFT._forward_native` hard-converting to
NumPy and needing restructuring. That was wrong, and transformer.py is
deliberately untouched here: `_forward_native` already has a complete, jittable
JAX branch (lax.scan + dynamic_slice). The reported failure at transformer.py:660
was in the *NumPy* branch — the traceback pointed at the symptom while the cause
was one frame up, in a caller that never threaded xp. Same root shape as site 1
of #421.
TransformerDFT had been passing by luck: its arithmetic flows through tracers, so
the missing xp never showed. Only NUFFT, which calls into _nufftax and then
converts, exposed it.
Verified:
- DFT and NUFFT, numpy-eager vs jax-jit, agree to ~1e-11 on real AND imaginary
parts (complex visibilities)
- both NUFFT chunk branches under jit match NumPy to ~5e-13 — single-shot and
the lax.scan path (chunk_size is a transformer arg the simulator never sets,
so that branch was exercised on the transformer directly)
- the returned Interferometer keeps uv_wavelengths, real_space_mask, noise map
- NumPy path still ndarray-backed
- test_autoarray 929, test_autogalaxy 1009, test_autolens 488 — all unchanged
TransformerNUFFTPyNUFFT remains out of scope: the legacy pynufft backend is not
JAX-traceable and is not expected to be.
Closes #422
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CWqjHGXUut25TEB8octU8H1 parent e994485 commit 4332ec2
1 file changed
Lines changed: 56 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
10 | 62 | | |
11 | 63 | | |
12 | 64 | | |
| |||
115 | 167 | | |
116 | 168 | | |
117 | 169 | | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
118 | 173 | | |
119 | 174 | | |
120 | 175 | | |
121 | 176 | | |
122 | | - | |
| 177 | + | |
123 | 178 | | |
124 | 179 | | |
125 | 180 | | |
| |||
0 commit comments