Skip to content

Commit fcf875e

Browse files
Jammy2211claude
authored andcommitted
Fix JAX array leak from PointSolver.solve() into Grid2DIrregular
When the solver uses a JAX backend, the final boolean-indexed solution was a JAX DeviceArray. Wrapping it in Grid2DIrregular without conversion caused downstream np.array() calls in the visualizer to raise: ValueError: object __array__ method not producing an array Fix: convert solution to numpy via np.asarray() before constructing the return Grid2DIrregular. Safe because solve() is never called inside jax.jit (variable-length boolean indexing prevents it). Also updates the Returns docstring to document the numpy-backed guarantee. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 1120edf commit fcf875e

2 files changed

Lines changed: 25 additions & 13 deletions

File tree

CLAUDE.md

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,31 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
99
pip install -e ".[dev]"
1010
```
1111

12-
### Run Tests
13-
```bash
14-
# All tests
15-
python -m pytest test_autolens/
12+
### Run Tests
13+
```bash
14+
# All tests
15+
python -m pytest test_autolens/
1616

1717
# Single test file
1818
python -m pytest test_autolens/lens/test_tracer.py
1919

20-
# With output
21-
python -m pytest test_autolens/imaging/test_fit_imaging.py -s
22-
```
23-
24-
### Formatting
25-
```bash
26-
black autolens/
20+
# With output
21+
python -m pytest test_autolens/imaging/test_fit_imaging.py -s
22+
```
23+
24+
### Codex / sandboxed runs
25+
26+
When running Python from Codex or any restricted environment, set writable cache directories so `numba` and `matplotlib` do not fail on unwritable home or source-tree paths:
27+
28+
```bash
29+
NUMBA_CACHE_DIR=/tmp/numba_cache MPLCONFIGDIR=/tmp/matplotlib python -m pytest test_autolens/
30+
```
31+
32+
This workspace is often imported from `/mnt/c/...` and Codex may not be able to write to module `__pycache__` directories or `/home/jammy/.cache`, which can cause import-time `numba` caching failures without this override.
33+
34+
### Formatting
35+
```bash
36+
black autolens/
2737
```
2838

2939
## Architecture

autolens/point/solver/point_solver.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import logging
2020
from typing import Tuple, Optional
2121

22+
import numpy as np
2223
import autoarray as aa
2324
from autoarray.structures.triangles.shape import Point
2425

@@ -66,7 +67,8 @@ def solve(
6667
6768
Returns
6869
-------
69-
A list of image plane coordinates that are traced to the source plane coordinate.
70+
A ``Grid2DIrregular`` of image-plane coordinates, always numpy-backed even when the
71+
solver uses a JAX backend internally.
7072
"""
7173
kept_triangles = super().solve_triangles(
7274
tracer=tracer,
@@ -90,4 +92,4 @@ def solve(
9092

9193
solution = solution[~self._xp.isinf(solution).any(axis=1)]
9294

93-
return aa.Grid2DIrregular(solution)
95+
return aa.Grid2DIrregular(np.asarray(solution))

0 commit comments

Comments
 (0)