Skip to content

fix: make remaining message and compound-prior xp paths JAX-traceable #1459

Description

@Jammy2211

Overview

A focused prior/message backend audit performed while fixing #1458 found four additional, independently reproducible JAX tracing failures. Each affected method accepts an xp argument but still calls NumPy/SciPy directly, so a traced value is coerced through __array__ and raises jax.errors.TracerArrayConversionError.

This is not covered by the completed JAX-native prior transforms in #1262 or the NumPy/statistical fixes tracked in #1331.

Confirmed failures

On current main, each of these fails under jax.jit:

  • GammaMessage.log_partition(xp=jnp)
    • uses scipy.special.gammaln(alpha) and np.log(beta)
  • BetaMessage.log_partition(xp=jnp)
    • uses scipy.special.betaln(*self.parameters)
  • Log._instance_for_arguments(..., xp=jnp)
    • ignores xp and calls np.log
  • Log10._instance_for_arguments(..., xp=jnp)
    • ignores xp and calls np.log10

Minimal shape of the reproducer:

jax.jit(
    lambda x: GammaMessage(x + 1, x + 2).log_partition(xp=jnp)
)(jnp.asarray(2.0))

Equivalent JIT calls fail for the other three paths.

Proposed fix

  • Dispatch Gamma/Beta special functions through a JAX-compatible backend when xp is JAX, while preserving SciPy on the NumPy path.
  • Use xp.log / xp.log10 in the compound prior modifiers.
  • Confirm whether compound priors must forward xp recursively to child prior models; add coverage for nested modifiers/compound expressions if so.
  • Add scalar and batched jax.jit regression tests with NumPy/SciPy numerical parity.
  • Keep statistical semantics unchanged.

Verification

  • Direct tests must fail on current main with TracerArrayConversionError and pass after the fix.
  • Run the focused prior/message suites and full PyAutoFit suite.
  • Exercise at least one nested compound-prior expression through the real instance_for_arguments(..., xp=jnp) API.

Relationship to #1458

#1458 addresses fixed-array construction and GammaMessage.to_canonical_form. These four failures are separate call paths and should remain a follow-up PR to keep that repair reviewable.

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