Repository navigation
Description
Overview
Putting a model instance into an af.Collection (e.g. fixing a lens to its truth by inserting the true al.Galaxy) makes the model identifier raise TypeError: iteration over a 0-d array at autofit/mapper/identifier.py:185 when an attribute of that instance is a 0-d NumPy (or JAX) array. Found 2026-11-14 in the ep_gnfw_slope science project, worked around there with model.replacing floats.
Reproduced on main (45e8cd3a):
inst = Profile(centre=np.array(0.5), slope=np.array(2.0))
model = af.Collection(lens=inst, g=af.Model(af.ex.Gaussian))
Identifier(model) # TypeError: iteration over a 0-d array (identifier.py:185)Cause: a 0-d array satisfies isinstance(value, Iterable) (it defines __iter__), so _add_value_to_hash_list tries to loop over it.
Plan
- Hash a 0-d array as the scalar it holds (
value.item()), so it goes through the existing float/int/bool branches. - A 0-d float array then hashes exactly like the equivalent Python float (same identifier as the
model.replacingworkaround); no existing identifier changes. - Covers NumPy and JAX (both expose
ndimand.item()). - Add unit tests: identifier computes without error, is stable across two computations, and equals the plain-float identifier.
Tier: glance — effective level: supervised; merge mode: auto-merge on green if the Witness passes after a merge slot (shift worker: ends at PR-open).
Detailed implementation plan
Affected repositories
- PyAutoFit (primary)
Work classification
Library
Branch survey
| Repository | Current Branch | Dirty? |
|---|---|---|
| ./PyAutoFit | main | clean |
Suggested branch: feature/model-identifier-0d-array
Worktree root: ~/Code/PyAutoLabs-wt/model-identifier-0d-array/
Implementation steps
autofit/mapper/identifier.py,Identifier._add_value_to_hash_list: before the__dict__branch, ifgetattr(value, "ndim", None) == 0and the value has.item, replace it withvalue.item()and recurse.test_autofit/mapper/test_identifier.py(or the existing identifier test module): reproducer with a plain class holding 0-dnp.arrayattributes inside anaf.Collection; assert no error, stable across twoIdentifiercalls, equal to the float-valued model's identifier.
Key files
autofit/mapper/identifier.py— hashing walk- identifier unit tests
Witness
the identifier of a model holding an instance with a 0-d array attribute is computed without error and is identical across two runs
Activity
Jammy2211 commentedon Nov 18, 2026
Library PR opened: #1785 (shift 2026-11-18-pm2, supervised, glance → stops at PR-open, labelled
decision-taken).Workspace impact: (iii) none. It is an internal hashing fix that changes no existing identifier, and smoke passed 213/0.
Decision flagged: the PR covers only the NumPy 0-d crash. JAX arrays hash value-blind (
['ArrayImpl']) and never crashed; fixing that changes existing identifiers, so it went to a separate judge draft.Jammy2211 commentedon Nov 19, 2026
Shipped: #1785 merged 2026-11-19T08:19Z (99b04b1) by human /prm after shift 2026-11-18-pm2. 0-d NumPy arrays now hash as their scalar in the model identifier; no existing identifier changes. JAX-array and NumPy-scalar hashing follow up in draft/bug/autofit/model_identifier_ignores_jax_array_and_numpy_scalar_values.md. Pending release.