Skip to content

fix: JAX 0.12.1 breaks step-0 structured triangle containment #703

Closed

Description

@Jammy2211

Overview

JAX 0.12.1 (on PyPI since 2026-11-18) breaks the default structured step-0 triangle containment route. On jax 0.12.1, 5 of the test__step0_route_is_bit_identical_to_gather[...-structured] cases fail (83–836 points per case get different kept triangles from the reference gather route). On the same source with jax 0.12.0.1, all 15 pass. Reproduced locally. The PyAutoNerves pin jax>=0.12.0,<0.13 admits 0.12.1, so fresh installs of the released 2026.11.13.1 are affected, and this blocks the pending library release (PyAutoHands release.yml run 44501247836 failed on this).

Plan

  • Find out what the differences are: points on or very near a shared triangle edge whose rounding changed (e.g. XLA fusion / fused multiply-add in 0.12.1), or genuinely wrong containment.
  • If fixable, make the structured branch of _step0_contains match the gather route exactly on both jax 0.12.0.1 and 0.12.1, keeping its no-gather property.
  • If not cleanly fixable within about an hour of investigation, switch the default _STEP0_CONTAINMENT back to "gather" (the reference path), measure the CPU cost, and file a follow-up to fix the structured route.
  • Leave the PyAutoNerves jax pin alone (excluding 0.12.1 only hides the problem; 0.12.2 would very likely bring it back).
  • Validate on both jax versions, then ship as a pending-release PR so it goes out with the pending release.

Effective level: supervised; merge mode: human /prm.

Detailed implementation plan

Affected Repositories

  • PyAutoArray (primary)

Branch Survey

Repository Current Branch Dirty?
./PyAutoArray main (5815019d) clean

Other PyAutoArray worktrees (magnification-maps-wiring, places-to-be-readme, repository-guidance-cleanup) do not touch triangles.

Suggested branch: feature/jax-0121-step0-structured

Implementation Steps

  1. Reproduce. Make a scratch venv with jax==0.12.1 jaxlib==0.12.1, chained to the PyAuto313 site-packages through a .pth file. Run pytest test_autoarray/structures/triangles/test_coordinate_jax.py -k step0_route_is_bit_identical: 5 fail on 0.12.1, 15 pass on 0.12.0.1.
  2. Investigate. In autoarray/structures/triangles/array.py, look at _step0_contains, specifically the structured branch (about lines 260–296), and at _barycentric_contains.
    • Compare the structured mask with the gather mask for the failing cases.
    • For each differing triangle, recompute the barycentric terms in float64 and measure the distance to the edge.
    • Try disabling XLA fused-multiply-add contraction to test the fusion hypothesis.
  3. Fix (preferred). Make the structured branch feed _barycentric_contains operands of the same form, operation order and dtype as the gather route. Keep the zero-gather property and the existing HLO guard tests. Add a regression comment naming jax 0.12.1.
  4. Fallback. Set _STEP0_CONTAINMENT = "gather" and update the comment block. Re-measure the step-0 CPU cost from point-source phase 4c and record it. File a Mind follow-up to restore structured.
  5. Tests.
    • Full test_autoarray on jax 0.12.0.1 (local ~/venv/PyAuto313) and on 0.12.1 (the scratch venv).
    • PyAutoLens test_autolens/point on 0.12.1.
    • The PR's CI installs 0.12.1 itself.

Key Files

  • autoarray/structures/triangles/array.py: _STEP0_CONTAINMENT switch, _step0_contains structured branch, _barycentric_contains.
  • autoarray/structures/triangles/coordinate_array.py: Step0Layout and the grid layout used by the structured route.
  • test_autoarray/structures/triangles/test_coordinate_jax.py: the bit-identity fuzz (the witness) and HLO guards.

Original Prompt

Click to expand starting prompt

JAX 0.12.1 breaks step-0 structured triangle containment (bit-identity vs gather fails)

Type: bug
Target: PyAutoArray
Repos:

  • PyAutoArray
    Themes:
  • jax
  • triangles
  • point-source
  • release-blocker
    Difficulty: small
    Autonomy: supervised
    Priority: high
    Status: draft
    Consequence: judge
    Witness: on jax 0.12.1, pytest test_autoarray/structures/triangles/test_coordinate_jax.py -k step0_route_is_bit_identical passes (or jax 0.12.1 is excluded from the pin with a recorded reason), and the PyAutoHands release.yml TestPyPI test step passes for PyAutoArray.
    Lane: any

Found 2026-11-19 by the release session (/release, stopped at vitals). The PyAutoHands release.yml TestPyPI test step
(run 44501247836, 2026-11-19T09:58Z) failed on PyAutoArray: 5 of 2473 tests failed, all
test_autoarray/structures/triangles/test_coordinate_jax.py::test__step0_route_is_bit_identical_to_gather[...-structured]
(cases solver, solver_deflected, alternating, alternating_padded, even_rows). The structured route's containment differs
from the gather route at 83–836 points per case, e.g. "structured on solver: 83 of 15443 points differ from gather,
first at [-6.75 9.8726896]".

Cause (strongly indicated): the JAX version, not a code change. Yesterday's run 44279589911 passed on the same PyAutoArray
main (5815019) with jax/jaxlib 0.12.0.1; today's installed jax/jaxlib 0.12.1 (PyPI 2026-11-18T13:57Z). The test and the
triangles code are unchanged since 2026-09-27 (#579 step-0 routes; 462ad09 MAX_CONTAINING_SIZE 15->20). Library CI on
main last ran before 0.12.1 existed, so it still shows green.

Impact: the pin jax>=0.12,<0.13 admits 0.12.1, so fresh installs of the released 2026.11.13.1 are also affected
(point-source containment on the structured step-0 route may be wrong). It blocks the pending library release (18
pending-release PRs across Fit/Galaxy/Array/Lens): a rehearsal would fail the same way.

Fix options: (1) exclude jax 0.12.1 in the pin (!=0.12.1 or <0.12.1) — fast and protects current users; needs the
DNA/Nerves version-policy view (memory: jax-version-policy, pin jax>=0.12,<0.13 shipped 2026.11.12.1); (2) reproduce
locally on 0.12.1, find which op changed (likely a sort/searchsorted/float rounding or scatter semantics change in the
structured route) and fix it so the route is bit-identical on both versions. Prefer (2) if small; else (1) now and (2)
as a follow-up.

Activity

  1. Jammy2211 commented on Nov 19, 2026

    @Jammy2211
    CollaboratorAuthor

    Library PR created

    • PR: fix(triangles): keep step-0 structured containment bit-identical on jax 0.12.1 #704 (pending-release), head 3b2ba0f8
    • Root cause: XLA CPU FMA contraction of the barycentric beta numerator differs between the structured route's per-class 2-D blocks and the gather path on jax 0.12.1; every differing triangle was an exact edge tie.
    • Fix: interleave the vertex components to row-major first, then call _barycentric_contains once on flat (N,) operands. No gather; default route stays structured.
    • Tests: test_autoarray 2473 passed on jax 0.12.0.1 and 0.12.1; PyAutoLens test_autolens/point 319 passed / 1 xfailed on 0.12.1.
    • Heart dev gate: GREEN. Workspace impact: none (internal; no API change). Workspace smoke running now; merge via human /prm.
  2. Jammy2211 commented on Nov 19, 2026

    @Jammy2211
    CollaboratorAuthor

    Smoke results (pyauto-heart smoke --root <task worktree> --jobs 3)

    Workspace Result Time
    autofit PASS 72s
    autogalaxy PASS 172s
    autolens PASS 464s
    autolens_test PASS 690s
    euclid PASS 117s
    howtolens PASS 337s
    autocti PASS 385s
    autocti_test PASS 66s

    8/8 passed, including the autolens_test point-source scripts (point.py, solver_extent.py). Note: the cached smoke environments run jax 0.12.0.1, so this is the no-regression check; jax 0.12.1 coverage is the unit/point test runs above plus PR CI. Ready for human /prm on #704.

  3. Jammy2211 commented on Nov 19, 2026

    @Jammy2211
    CollaboratorAuthor

    Shipped

    Merged #704 (merge commit e398b808) on 2026-11-19. CI green on jax 0.12.1 (unittest 3.12/3.13 + nojax). Awaiting the next library release (pending-release).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions