Repository navigation
Description
Overview
SimulatorImaging(use_jax=True) and SimulatorInterferometer(use_jax=True) work in JAX-eager mode but cannot be wrapped in @jax.jit. The blocker is array_2d_via_indexes_from — it calls tuple(native_index_for_slim_index_2d.T), which iterates the outermost axis of a JAX array and triggers TracerArrayConversionError. This is the last structural JAX-compatibility gap in the simulator path. Fixing it completes the "JIT-it-yourself" image-simulation story.
Plan
- Refactor
array_2d_via_indexes_fromto use 2D advanced indexing ([:, 0], [:, 1]) instead oftuple(...T)on the JAX path — no Python iteration of traced arrays - Remove the temporary
if xp is npguard in the imaging simulator that was working around the broken.native - Update simulator docstrings to drop the "@jax.jit currently blocked" caveats
- Restore the disabled
@jax.jitroundtrip tests in workspace_test parity scripts - Remove "blocked by Array2D.native" notes from all workspace JAX variant blocks
Detailed implementation plan
Affected Repositories
- PyAutoArray (primary)
- autolens_workspace_test
- autolens_workspace
- autogalaxy_workspace
Work Classification
Both (library first, workspace follow-up)
Branch Survey
| Repository | Current Branch | Dirty? |
|---|---|---|
| PyAutoArray | main | clean |
| autolens_workspace_test | main | dirty (dataset rebuilds + untracked parity scripts) |
| autolens_workspace | main | dirty (dataset rebuilds) |
| autogalaxy_workspace | main | dirty (dataset rebuilds) |
Suggested branch: feature/array2d-native-jit-safety
Worktree root: ~/Code/PyAutoLabs-wt/array2d-native-jit-safety/ (created later by /start_library)
Implementation Steps
-
Fix
array_2d_via_indexes_frominautoarray/structures/arrays/array_2d_util.py:557-564:
Replacearray.at[tuple(native_index_for_slim_index_2d.T)].set(...)witharray.at[native_index_for_slim_index_2d[:, 0], native_index_for_slim_index_2d[:, 1]].set(...)— 2D advanced indexing instead of tuple-unpacked rows. -
Remove imaging simulator workaround in
autoarray/dataset/imaging/simulator.py:235-244:
Remove theif xp is np: image.native else: image.arrayguard and its comment, restore the simpleArray2D(values=image.native, mask=mask). -
Update simulator docstrings:
autoarray/dataset/imaging/simulator.py:99-105— remove "Note: @jax.jit wrapping ... currently blocked" paragraphautoarray/dataset/interferometer/simulator.py:68-70— remove "@jax.jit wrapping is currently blocked" sentence
-
Restore workspace_test parity scripts:
autolens_workspace_test/scripts/imaging/simulator_use_jax_parity.py:96-114— replace commented-out JIT block with active@jax.jitroundtrip testautolens_workspace_test/scripts/interferometer/simulator_use_jax_parity.py— update docstring + add JIT roundtrip test
-
Workspace doc cleanup — remove "blocked by Array2D.native" notes from JAX variant blocks in:
autolens_workspace/scripts/imaging/simulator.pyautolens_workspace/scripts/interferometer/simulator.pyautolens_workspace/scripts/group/simulator.pyautolens_workspace/scripts/point_source/simulator.pyautolens_workspace/scripts/point_source/fit.pyautogalaxy_workspace/scripts/imaging/simulator.pyautogalaxy_workspace/scripts/interferometer/simulator.py
Key Files
autoarray/structures/arrays/array_2d_util.py— core fix (the onlytuple(...T)pattern on traced arrays)autoarray/dataset/imaging/simulator.py— workaround removal + docstringautoarray/dataset/interferometer/simulator.py— docstringautolens_workspace_test/scripts/imaging/simulator_use_jax_parity.py— restore JIT testautolens_workspace_test/scripts/interferometer/simulator_use_jax_parity.py— restore JIT test
Original Prompt
Click to expand starting prompt
Refactor Array2D.native / array_2d_via_indexes_from for JAX-jit safety
SimulatorImaging.use_jax=True and SimulatorInterferometer.use_jax=True
work end-to-end on JAX-eager today (shipped in Phase 2 of
z_features/jax_user_intro.md — PRs PyAutoArray#335, #336 +
PyAutoLens#539, #540 + PyAutoGalaxy#442, #443) but cannot currently
be wrapped in @jax.jit. This task unblocks that.
The blocker
When the user wraps a simulator in their own @jax.jit:
simulator = al.SimulatorImaging(..., use_jax=True)
@jax.jit
def simulate(tracer):
return simulator.via_tracer_from(tracer=tracer, grid=grid)The call fails with TracerArrayConversionError: __array__() was called on traced array. The two failing sites are:
array_2d_via_indexes_from(array_2d_util.py:535-562) —tuple(jax_array.T)iterates the outermost axis, forcing__array__().Array2D.native(uniform_2d.py:295) — routes through (1).Imaging.trimmed_after_convolution_from— same.nativeaccess.
Scope
- Refactor
array_2d_via_indexes_fromto use JAX-traceable 2D advanced indexing - Remove the temporary
if xp is npsimulator guard - Update simulator docstrings to drop the "jit currently blocked" caveat
- Restore the disabled @jax.jit tests in workspace_test parity scripts
- Remove "blocked by Array2D.native" notes from workspace JAX variant blocks
Activity
Jammy2211 commentedon May 25, 2026
Library PR Created — 2025-05-25
PR
Status
Workspace changes needed. Next: /start_workspace
API Changes
None — internal changes only.
array_2d_via_indexes_fromJAX path now uses 2D advanced indexing; imaging simulator workaround removed; docstring caveats cleaned up.Workspace follow-up: restore
@jax.jitparity tests in autolens_workspace_test, remove "blocked by Array2D.native" notes from autolens_workspace + autogalaxy_workspace scripts.Jammy2211 commentedon May 25, 2026
Shipped — 2026-05-25
PRs
Summary
Replaced
tuple(native_index_for_slim_index_2d.T)with 2D advanced indexing inarray_2d_via_indexes_from, makingArray2D.nativejit-traceable. Removed the temporaryif xp is npworkaround in the imaging simulator and cleaned up all "jit blocked" docstring caveats. Restored active@jax.jitroundtrip tests in the workspace_test parity scripts and removed "blocked by Array2D.native" notes from all workspace JAX variant blocks. The entire "JIT-it-yourself" image-simulation story is now functional.