Skip to content

fix: drop AdaptImages single-pixelated-galaxy fallback in lens.to_inversion - #474

Merged
Jammy2211 merged 1 commit into
mainfrom
feature/adapt-images-pytree-fix
Apr 26, 2026
Merged

Jammy2211 merged 1 commit into
mainfrom
feature/adapt-images-pytree-fix

Conversation

@Jammy2211

Copy link
Copy Markdown
Collaborator

Summary

Replaces the fragile single-pixelated-galaxy fallback in autolens/lens/to_inversion.py with the new AdaptImages.image_for_galaxy helper from PyAutoGalaxy. The fallback (lines 280-290) was a workaround for the same jax.jit-unflatten Galaxy-identity issue: when a fit had exactly one pixelization, it picked the only entry in galaxy_image_dict by has(cls=Pixelization). That covers the common single-source case but is incorrect once a fit has multiple pixelizations.

The new helper looks up adapt images by path-tuple via tracer.galaxies ordering, which is stable across the JIT boundary. Per-plane GalaxiesToInversion constructions in image_plane_mesh_grid_pg_list now pass path_galaxies=self.tracer.galaxies so the autogalaxy-side helper sees the full list (the per-plane subset would otherwise misalign with galaxy_path_list).

Depends on PyAutoLabs/PyAutoGalaxy#370, which introduces image_for_galaxy and the path_galaxies constructor argument on GalaxiesToInversion. Merge order: PyAutoGalaxy first.

API Changes

Analysis.fit_from (imaging + interferometer) passes galaxies=tracer.galaxies into adapt_images_via_instance_from. No public symbols added or removed in autolens. Internal change. See full details below.

Test Plan

  • Existing test_autolens/ suite remains green (256 pass locally).
  • After PyAutoGalaxy PR lands and merges, run the autolens_workspace_test smoke tests for jax_likelihood_functions/imaging/{rectangular,rectangular_mge,delaunay,delaunay_mge}.py to confirm the fallback removal doesn't regress single-pixelization fits.
Full API Changes (for automation & release notes)

Removed

  • Single-pixelated-galaxy fallback at autolens/lens/to_inversion.py:280-290. The pattern (search dict keys for has(cls=Pixelization) and grab [0] when len(galaxies_with_pixelization_list) == 1) is replaced by the path-tuple lookup in AdaptImages.image_for_galaxy.

Changed Behaviour

  • TracerToInversion.adapt_galaxy_image_pg_list resolves adapt images via image_for_galaxy(galaxy, self.tracer.galaxies) for all pixelization counts, not only the single-pixelization case.
  • TracerToInversion.image_plane_mesh_grid_pg_list constructs per-plane GalaxiesToInversion instances with path_galaxies=self.tracer.galaxies so the autogalaxy helper's positional lookup aligns with the full galaxy list rather than the per-plane subset.

Migration

  • Internal — no migration needed. Public Analysis.fit_from signatures unchanged.

🤖 Generated with Claude Code

…ersion

Replaces the autolens/lens/to_inversion.py:280-290 workaround (search
dict keys for has(cls=Pixelization) when galaxies_with_pixelization_list
has length 1) with the new AdaptImages.image_for_galaxy helper from
PyAutoGalaxy. Per-plane GalaxiesToInversion now passes
path_galaxies=tracer.galaxies so the autogalaxy-side positional lookup
sees the full galaxy list rather than a per-plane subset. Analysis.
fit_from passes galaxies=tracer.galaxies into adapt_images_via_instance_from.

Depends on PyAutoGalaxy PR (image_for_galaxy + path_galaxies). Merge
order: PyAutoGalaxy first.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@Jammy2211

Copy link
Copy Markdown
Collaborator Author

Workspace PR: PyAutoLabs/autogalaxy_workspace_test#12

@Jammy2211
Jammy2211 merged commit bd19c1e into main Apr 26, 2026
5 of 7 checks passed
@Jammy2211
Jammy2211 deleted the feature/adapt-images-pytree-fix branch April 26, 2026 19:10
@Jammy2211 Jammy2211 removed the pending-release PR queued for the next release build label Sep 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant