Skip to content

fix[next]: register jax.core.Tracer for embedded field dispatch on jax >= 0.11 - #2867

Merged
havogt merged 1 commit into
GridTools:mainfrom
havogt:fix-jax-tracer-dispatch
Sep 9, 2026
Merged

fix[next]: register jax.core.Tracer for embedded field dispatch on jax >= 0.11#2867
havogt merged 1 commit into
GridTools:mainfrom
havogt:fix-jax-tracer-dispatch

Conversation

@havogt

@havogt havogt commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

common._field / common._connectivity are functools.singledispatch functions; the embedded JAX backend registers them for jnp.ndarray (which is jax.Array). Since jax 0.11 jax.Array is built by a metaclass (ArrayMeta) and jax.core.Tracer is no longer in its MRO; only isinstance() still reports a tracer as a jax.Array, via ArrayMeta.__instancecheck__. singledispatch resolves on the class hierarchy, so constructing a field from a traced array (inside jax.jit, jax.grad, jax.lax.scan, ...) falls through to the base implementation and raises a bare NotImplementedError.

Fix: additionally register jax.core.Tracer. On older jax, where Tracer already subclasses jax.Array, the extra registration resolves to the same implementation and is a no-op.

…x >= 0.11

common._field / common._connectivity are functools.singledispatch and the
embedded JAX backend registers them for jnp.ndarray (== jax.Array). Since
jax 0.11, jax.Array is built by ArrayMeta and Tracer is no longer in its
MRO; only isinstance() reports it as a jax.Array. singledispatch resolves
on the MRO, so constructing a field from a traced array under jit/grad/scan
fell through to the base implementation and raised NotImplementedError.

Register jax.core.Tracer explicitly; it is a no-op on older jax where
Tracer already subclasses jax.Array.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HVrnd8v75kACJXMcdNovAN
@havogt
havogt marked this pull request as ready for review September 9, 2026 13:20
@havogt
havogt requested a review from egparedes September 9, 2026 13:21

@egparedes egparedes left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Would it make sense to also bump the minimum required version of jax ?

@egparedes egparedes left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@havogt
havogt merged commit 117c6d0 into GridTools:main Sep 9, 2026
24 checks passed
@havogt
havogt deleted the fix-jax-tracer-dispatch branch September 9, 2026 14:27
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.

2 participants