fix: AdaptImages galaxy-identity mismatch across jax.jit boundary#370
Merged
Conversation
Resolves dict-keyed-by-Galaxy-instance crash for adapt-image models after jax.jit unflatten produces fresh Galaxy objects with new .id values. Adds galaxy_path_list parallel to the analysis-time galaxies list and two helpers (image_for_galaxy, image_plane_mesh_grid_for_galaxy) that fall back to path-tuple keying via galaxy_name_image_dict. Drops the single-mesh-grid fallback at to_inversion.py:428-442 — replaced by the proper fix. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This was referenced Apr 26, 2026
Collaborator
Author
|
Workspace PR: PyAutoLabs/autogalaxy_workspace_test#12 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes
AdaptImageslookups crashing across thejax.jitboundary for any model that uses adapt images (Adaptregularization,RectangularAdaptImage,Delaunay,Hilbert). AfterModel.instance_unflattenrebuilds galaxies viaself.cls(*constructor_arguments)they get fresh.idvalues, sogalaxy_image_dict[galaxy](keyed by Galaxy instances, hashed viaint(self.id)) misses and downstreammesh_weight_map_from(adapt_data=None)crashes withAttributeError.The fix carries a path-tuple list (
AdaptImages.galaxy_path_list) parallel to the analysis-time galaxies list.AdaptImagesrides asauxthrough theFitImagingpytree, so the path list survives unflatten unchanged. New helpersimage_for_galaxy(galaxy, galaxies)/image_plane_mesh_grid_for_galaxytry the existing by-instance fast path first, then fall back to identity-positional lookup againstgalaxy_path_listandgalaxy_name_image_dict(already path-keyed, also aux-stable).The previous one-element fallback at
to_inversion.py:428-442(mesh grid) is dropped — it was a workaround for the same root cause and only happened to cover single-pixelization fits.API Changes
AdaptImagesgained agalaxy_path_listattribute and two new lookup helpers (image_for_galaxy,image_plane_mesh_grid_for_galaxy).updated_via_instance_fromaccepts an optionalgalaxiesarg used to align the path list with the analysis-time galaxy ordering.GalaxiesToInversionaccepts an optionalpath_galaxiesarg, defaulting to its owngalaxies(the autogalaxy single-plane case stays unchanged).Analysis.adapt_images_via_instance_fromforwards an optionalgalaxiesarg. All new arguments are optional and default to None — existing callers and tests pass unchanged. See full details below.Test Plan
test_autogalaxy/suite remains green (840 pass locally).test__image_for_galaxy__resolves_after_galaxy_identity_changesandtest__image_plane_mesh_grid_for_galaxy__resolves_after_galaxy_identity_changesintest_autogalaxy/analysis/test_adapt_images.pyexercise the post-unflatten lookup with fresh-Galaxy instances at the same paths.autogalaxy_workspace_testre-enablesrectangular.py(adapt variant),rectangular_mge.py,delaunay.py,delaunay_mge.pyunderjax_likelihood_functions/imaging/.Full API Changes (for automation & release notes)
Added
AdaptImages.galaxy_path_list: Optional[List[str]]— path-tuple list parallel to the analysis-time galaxies list, populated byupdated_via_instance_from.AdaptImages.image_for_galaxy(galaxy, galaxies=None) -> Optional[Array2D]— JIT-safe lookup helper. Triesgalaxy_image_dict[galaxy]first, falls back togalaxy_name_image_dict[path]via positional alignment.AdaptImages.image_plane_mesh_grid_for_galaxy(galaxy, galaxies=None) -> Optional[Grid2DIrregular]— companion helper for the mesh-grid path.Changed Signature
AdaptImages.__init__— new optional kwarggalaxy_path_list: Optional[List[str]] = None.AdaptImages.updated_via_instance_from(instance, mask=None)->updated_via_instance_from(instance, mask=None, galaxies=None). Whengalaxiesis provided, the resultinggalaxy_path_listis aligned with that list.GalaxiesToInversion.__init__— new optional kwargpath_galaxies: Optional[List[Galaxy]] = None. Defaults to the constructor'sgalaxiesargument; only autolens currently supplies a different value (the fulltracer.galaxieslist).Analysis.adapt_images_via_instance_from(instance)->adapt_images_via_instance_from(instance, galaxies=None).Changed Behaviour
GalaxiesToInversion.image_plane_mesh_grid_listno longer falls back to the single-mesh-grid value when the by-instance lookup misses. Lookup now resolves correctly viaimage_plane_mesh_grid_for_galaxyfor any number of pixelized galaxies.GalaxiesToInversion.mapper_galaxy_dictadapt-image lookup usesimage_for_galaxyinstead ofgalaxy_image_dict[galaxy]directly.Migration
Analysis.fit_fromis updated to pass the freshly-builtgalaxieslist toadapt_images_via_instance_from. External callers that already passinstancecontinue to work.🤖 Generated with Claude Code