Skip to content

fix: hash 0-d NumPy arrays as scalars in the model identifier - #1785

Merged
Jammy2211 merged 1 commit into
mainfrom
feature/model-identifier-0d-array
Nov 19, 2026
Merged

Jammy2211 merged 1 commit into
mainfrom
feature/model-identifier-0d-array

Conversation

@Jammy2211

Copy link
Copy Markdown
Collaborator

Summary

Putting a model instance whose attribute is a 0-d NumPy array into an af.Collection made Identifier raise TypeError: iteration over a 0-d array (autofit/mapper/identifier.py:185). A 0-d array passes the Iterable check but cannot be iterated. It now hashes as the scalar it holds (value.item()), so it gets the same identifier as the equivalent Python value.

No existing identifier changes: the new branch fires only for input that used to raise. NumPy scalars (np.float64, np.int64) are not Iterable, and JAX arrays take the earlier __dict__ branch, so neither reaches the new code.

Closes #1784

Decision taken (decide-and-flag)

The plan on #1784 said the fix "covers NumPy and JAX". JAX arrays never crashed: they have a __dict__ and hash as just ['ArrayImpl'], whatever their value or shape. That is a separate value-blind collision bug, and fixing it would change the identifiers (output folders) of existing models that hold JAX arrays. I narrowed this PR to the NumPy crash and queued a judge follow-up draft: draft/bug/autofit/model_identifier_ignores_jax_array_and_numpy_scalar_values.md (it also covers np.float32/np.int64 scalars, which are left out of the hash).

API Changes

None. Internal change only.

Test Plan

  • New test_instance_with_0d_numpy_array_attribute: identifier computes, is stable across two builds, equals the Python-float model's identifier, and changes when the value changes. It fails on main and passes on the branch.
  • Full test_autofit (-x): 4310 passed, 2 skipped, 1 xfailed.
  • Reproducer run twice in separate processes: identical identifier 2903b6b80434ac99eeb2a42ec9d76684.

Validation checklist (--auto run — plan was not pre-approved)

  • Effective level: supervised (header: safe, cap: bug → supervised); tier glance
  • Plan: on the issue (fix: model identifier raises TypeError on 0-d array attributes #1784), written at start; narrowed as flagged above
  • Gate: tests 4310 pass · smoke 213/0 (all default workspaces + autocti, branch via the task activate.sh) · review (independent Opus) CLEAN, 1 claim basis-cited (test + edge run over float/int/bool/str/None 0-d arrays) · Heart dev-ship GREEN (PyAutoFit + dependants; shown: shift-acked yellows: manifest drift x2, no release rehearsal) · adversary (Sonnet) CLEAN: Witness held across separate processes; old vs new hashes identical for np.float64/np.int64/np.bool_, 1-d arrays and JAX 0-d
  • Human: plan sound in hindsight?
  • Human: diff matches plan (no scope creep)?
  • Human: merge, amend, or reject — then log the outcome

🤖 Generated with Claude Code

An instance in a model with a 0-d NumPy array attribute made Identifier
raise "TypeError: iteration over a 0-d array": the array passes the
Iterable check but cannot be iterated. Hash the scalar it holds instead,
so it matches the equivalent Python value. No existing identifier changes.

Closes #1784

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Jammy2211 Jammy2211 added pending-release PR queued for the next release build decision-taken labels Nov 18, 2026
@Jammy2211
Jammy2211 merged commit 99b04b1 into main Nov 19, 2026
6 checks passed
@Jammy2211
Jammy2211 deleted the feature/model-identifier-0d-array branch November 19, 2026 08:19
@pyautolabs-bot pyautolabs-bot Bot removed the pending-release PR queued for the next release build label Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: model identifier raises TypeError on 0-d array attributes

1 participant