From ef311f3fb422a5dbf642d973d0a6708fe3682a0a Mon Sep 17 00:00:00 2001 From: Jammy2211 Date: Fri, 21 Aug 2026 18:19:51 -0400 Subject: [PATCH] fix: Basis linear-profile placeholder on irregular grids MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `Basis.image_2d_list_from` built the zero placeholder for its `LightProfileLinear` members as `Array2D(values=..., mask=grid.mask)`, which assumes a masked `Grid2D`. Evaluating a basis containing a linear light profile on a `Grid2DIrregular` therefore raised AttributeError: Grid2DIrregular does not have attribute mask This is the grid type JIT-traced likelihood paths use, so any such path with a linear-light basis (e.g. an MGE lens light) was unreachable — `autolens_workspace_developer/jax_profiling/jit/imaging/pixelization.py` died on it at step 2. Return an `ArrayIrregular` for irregular grids and keep the `Array2D` for `Grid2D`, mirroring how `ArrayMaker.via_grid_2d` / `via_grid_2d_irr` already dispatch the non-linear profiles' return type. Regression test added; full test_autogalaxy suite passes (1113). Refs #580 Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_01SdsQ7c6y3iuiQf2jy8gx6K --- autogalaxy/profiles/basis.py | 6 +++++- test_autogalaxy/profiles/test_basis.py | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/autogalaxy/profiles/basis.py b/autogalaxy/profiles/basis.py index f54f184e..db4b4387 100644 --- a/autogalaxy/profiles/basis.py +++ b/autogalaxy/profiles/basis.py @@ -159,10 +159,14 @@ def image_2d_list_from( ) elif kwargs.get("binned", True) is False: image_2d_list.append(xp.zeros((grid.over_sampled.shape[0],))) - else: + elif isinstance(grid, aa.Grid2D): image_2d_list.append( aa.Array2D(values=xp.zeros((grid.shape[0],)), mask=grid.mask) ) + else: + image_2d_list.append( + aa.ArrayIrregular(values=xp.zeros((grid.shape[0],))) + ) return image_2d_list diff --git a/test_autogalaxy/profiles/test_basis.py b/test_autogalaxy/profiles/test_basis.py index 6e239a89..75a8300c 100644 --- a/test_autogalaxy/profiles/test_basis.py +++ b/test_autogalaxy/profiles/test_basis.py @@ -61,6 +61,25 @@ def test__image_2d_from__returns_array2d_for_linear_only_basis(grid_2d_7x7): assert isinstance(image, aa.Array2D) +def test__image_2d_from__grid_2d_irregular__linear_profile_placeholder_has_no_mask(): + # Regression test: the linear-intensity-unknown placeholder used to be built as + # `Array2D(..., mask=grid.mask)`, which raised `AttributeError: Grid2DIrregular + # does not have attribute mask` whenever a basis containing a linear light + # profile was evaluated on an irregular grid (as JIT-traced likelihood paths do). + grid = aa.Grid2DIrregular(values=[(1.0, 1.0), (2.0, 2.0), (3.0, 3.0)]) + + lp = ag.lp.Sersic(intensity=0.1) + lp_linear = ag.lp_linear.Sersic(effective_radius=2.0, sersic_index=2.0) + + basis = ag.lp_basis.Basis(profile_list=[lp, lp_linear]) + + image = basis.image_2d_from(grid=grid) + + assert isinstance(image, aa.ArrayIrregular) + assert image.shape == (3,) + assert image == pytest.approx(np.asarray(lp.image_2d_from(grid=grid)), 1.0e-8) + + def test__image_2d_from__operated_only_false__returns_only_non_operated_profile_image( grid_2d_7x7, lp_0, lp_operated_0 ):