Skip to content

Commit 11757fd

Browse files
authored
Merge pull request #527 from PyAutoLabs/claude/nightly-build-release-failure-qqru5o
fix: make the dPIEMass ellipticity→ell_comps conversion JAX-tracer safe
2 parents fad6253 + 1c4b715 commit 11757fd

1 file changed

Lines changed: 26 additions & 4 deletions

File tree

autogalaxy/profiles/mass/total/dual_pseudo_isothermal_mass.py

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,26 @@ def _b0_from_lenstool_sigma(
4141
return 6.0 * 648000.0 * (sigma / c_km_s) ** 2 * (d_ls / d_s)
4242

4343

44+
def _xp_from(*values):
45+
"""
46+
numpy, unless any input is a JAX array/tracer — constructor arguments carry no
47+
``xp`` threading, so when a free parameter arrives traced (model-fitting under
48+
``jax.jit``) the backend must be inferred from the values themselves.
49+
"""
50+
try:
51+
from jax import Array
52+
from jax.core import Tracer
53+
except Exception:
54+
return np
55+
56+
if any(isinstance(value, (Array, Tracer)) for value in values):
57+
import jax.numpy as jnp
58+
59+
return jnp
60+
61+
return np
62+
63+
4464
# Within this profile family, PIEMass, dPIEMassB0, and dPIEMassB0Sph are directly ported from Lenstool's C code, and have been thoroughly annotated and adapted for PyAutoLens.
4565
# dPIEMass and dPIEMassSph (the default profiles) expose the same physics in Lenstool's native parameterization.
4666
# The dPIEPotential and dPIEPotentialSph profiles are modified from the original `dPIEPotential` and `dPIEPotentialSph`, which were implemented to PyAutoLens by Jackson O'Donnell.
@@ -621,8 +641,9 @@ class docstring), quoted by Bergamini et al. 2019, Eq. 5 — so a measured
621641

622642
cosmology = Planck15()
623643

624-
axis_ratio = np.sqrt((1.0 - ellipticity) / (1.0 + ellipticity))
625-
ell_comps = convert.ell_comps_from(axis_ratio=axis_ratio, angle=angle_pos)
644+
xp = _xp_from(ellipticity, angle_pos)
645+
axis_ratio = xp.sqrt((1.0 - ellipticity) / (1.0 + ellipticity))
646+
ell_comps = convert.ell_comps_from(axis_ratio=axis_ratio, angle=angle_pos, xp=xp)
626647

627648
b0 = _b0_from_lenstool_sigma(
628649
sigma=sigma,
@@ -1186,8 +1207,9 @@ def __init__(
11861207
# them only so af.Model composition works.
11871208
cosmology = FlatLambdaCDM(H0=H0, Om0=Om0)
11881209

1189-
axis_ratio = np.sqrt((1.0 - ellipticity) / (1.0 + ellipticity))
1190-
ell_comps = convert.ell_comps_from(axis_ratio=axis_ratio, angle=angle_pos)
1210+
xp = _xp_from(ellipticity, angle_pos)
1211+
axis_ratio = xp.sqrt((1.0 - ellipticity) / (1.0 + ellipticity))
1212+
ell_comps = convert.ell_comps_from(axis_ratio=axis_ratio, angle=angle_pos, xp=xp)
11911213

11921214
b0 = _b0_from_lenstool_sigma(
11931215
sigma=sigma,

0 commit comments

Comments
 (0)