Skip to content

fix: PowerLawCore.convergence_2d_from drops xp (Isothermal not jit-traceable) #632

Description

@Jammy2211

Overview

ag.mp.Isothermal(...).convergence_2d_from(grid, xp=jnp) cannot be traced under jax.jit when ell_comps are tracers: it raises TracerArrayConversionError. The cause is that PowerLawCore.convergence_2d_from does not forward xp to convergence_func, so NumPy is used on JAX tracers. This blocks jit/grad of convergence for Isothermal and every PowerLawCore subclass (found in point-source phase 2b).

Plan

  • Forward xp in the one convergence_func(...) call that drops it (PowerLawCore.convergence_2d_from).
  • Add a jax-free regression test asserting convergence_func receives the xp passed to convergence_2d_from.
  • Confirm with a scratch jit witness that jit output equals NumPy output.
Detailed implementation plan

Affected Repositories

  • PyAutoGalaxy (primary)

Branch Survey

Repository Current Branch Dirty?
./PyAutoGalaxy main clean

Suggested branch: feature/isothermal-convergence-jit

Implementation Steps

  1. autogalaxy/profiles/mass/total/power_law_core.py:111: return self.convergence_func(grid_radius=grid_eta, xp=xp).
  2. test_autogalaxy/profiles/mass/total/test_isothermal.py: pass a numpy-delegating spy module as xp, wrap the instance's convergence_func to capture its xp kwarg, and assert it is the spy. Run red on unfixed main, then green; run pytest test_autogalaxy/profiles/mass.
  3. Scratch witness: jax.jit over ell_comps gives the same convergence as NumPy.

Key Files

  • autogalaxy/profiles/mass/total/power_law_core.py — the call that drops xp
  • test_autogalaxy/profiles/mass/total/test_isothermal.py — regression test

Original Prompt

Click to expand starting prompt

Isothermal.convergence_2d_from not jit-traceable (PowerLawCore drops xp)

Type: bug
Target: @PyAutoGalaxy

Original request (verbatim)

fix this - Isothermal.convergence_2d_from still can't be traced under jax.jit (the phase 2b bug).

Carried from the active.md row point-source-source-plane-p2c carried: intake list.

Witness (reproduced 2026-09-27 on PyAutoGalaxy main)

With ell_comps as JAX tracers, ag.mp.Isothermal(...).convergence_2d_from(grid, xp=jnp)
under jax.jit raises TracerArrayConversionError.

Root cause

PowerLawCore.convergence_2d_from (autogalaxy/profiles/mass/total/power_law_core.py:111)
calls self.convergence_func(grid_radius=grid_eta) without xp, so the default np is
used and Isothermal.axis_ratio(np) calls np.minimum on a tracer. The shared method means
PowerLaw, PowerLawIntermediate, IsothermalCore and other subclasses are affected too. It is
the only convergence_func(...) call site that omits xp.

Plan

  1. power_law_core.py:111 -> return self.convergence_func(grid_radius=grid_eta, xp=xp).
  2. jax-free regression test in test_autogalaxy/profiles/mass/total/test_isothermal.py:
    call convergence_2d_from with a numpy-delegating spy xp module and assert
    convergence_func receives that same xp. Red on unfixed main, then green.
  3. Scratch jit witness: jit output equals NumPy output.

Activity

  1. Jammy2211 commented on Sep 27, 2026

    @Jammy2211
    CollaboratorAuthor

    Shipped

    • PR: fix: PowerLawCore.convergence_2d_from drops xp (Isothermal not jit-traceable) #633 — merged as 152695e (CI green on all legs).
    • Fix: PowerLawCore.convergence_2d_from now passes xp through to convergence_func, so Isothermal (and PowerLaw, PowerLawIntermediate, IsothermalCore and other subclasses sharing the method) is traceable under jax.jit.
    • Regression test: jax-free spy-xp test in test_autogalaxy/profiles/mass/total/test_isothermal.py (red on unfixed main, green after).
    • API changes: none. Carries pending-release — live for users on the next PyAutoGalaxy 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