Skip to content

refactor: example Analysis reduces chi-squared with xp.sum #1774

Closed

Description

@Jammy2211

Overview

af.ex.Analysis.log_likelihood_function (autofit/example/analysis.py:148) reduces the chi-squared map with the Python builtin sum(chi_squared_map). Under JAX this only works by iterating the traced array element by element, and it is the wrong pattern for the example analysis that tutorials and workspace scripts copy from. Replace it with self._xp.sum(...).

Plan

  • Swap the builtin sum for self._xp.sum in the example Analysis log likelihood (matches the self._xp pattern already used in model_data_1d_from).
  • Leave the unused xp=np parameter untouched (signature change is out of scope).
  • Verify with the existing example-Analysis tests under both NumPy and JAX.

Tier: glance — merge mode: auto-merge on green if the Witness passes, post-merge summary

Detailed implementation plan

Affected Repositories

  • PyAutoFit (primary)

Branch Survey

Repository Current Branch Dirty?
PyAutoFit main clean

PyAutoFit is also claimed by three-autos-public-framing (docs) and ep-projected-model-shared-prior (samples.py + tests); human-approved conflict override 2026-11-15 — non-overlapping file, separate branch off main.

Suggested branch: feature/example-analysis-xp-sum

Implementation Steps

  1. autofit/example/analysis.py: log_likelihood = -0.5 * self._xp.sum(chi_squared_map).
  2. Witness: grep shows self._xp.sum( and no bare sum( in log_likelihood_function.
  3. Run pytest test_autofit including the JAX users of af.ex.Analysis: non_linear/test_fitness_assertions_jax.py, non_linear/search/mle/test_bfgs_jax_gradient.py, graphical/test_shared_state.py, non_linear/test_fitness_objective.py.

Key Files

  • autofit/example/analysis.py — example Analysis log likelihood

Original Prompt

Click to expand starting prompt

Example Analysis should reduce with xp.sum not builtin sum

Type: refactor
Target: PyAutoFit
Repos:

  • PyAutoFit
    Difficulty: small
    Autonomy: safe
    Priority: normal
    Status: formalised
    Consequence: glance
    Witness: autofit/example/analysis.py log_likelihood_function contains self._xp.sum( and no bare sum( call; the example test suite passes under both NumPy and JAX.
    Review-minutes: 3
    Unattended: ready
    Lane: any

af.ex.Analysis.log_likelihood_function (autofit/example/analysis.py:147) reduces the chi-squared map with the Python builtin sum(chi_squared_map) instead of self._xp.sum. It works under JAX only by iterating the traced array element by element, and it is the wrong pattern for the example analysis that tutorials and workspace scripts copy from. Replace it with self._xp.sum(...). Found 2026-09-10.

Activity

  1. Jammy2211 commented on Nov 15, 2026

    @Jammy2211
    CollaboratorAuthor

    Shipped

    • Library PR: refactor: example Analysis reduces chi-squared with xp.sum #1775 — merged as 5f580d5
    • Change: af.ex.Analysis.log_likelihood_function now reduces the chi-squared map with self._xp.sum(...) instead of the builtin sum.
    • Witness: passed — self._xp.sum( present, no bare sum( in the method.
    • Tests: full test_autofit locally (Python 3.13, jax 0.12, .[optional]): 4288 passed / 2 skipped / 1 xfailed. CI: unittest 3.12, 3.13, nojax, docs-build, generated-search-docs all green.
    • Workspace impact: none (no API change).
    • Release: carries pending-release until the next PyAutoFit release.
    • Revert: git revert -m 1 5f580d5

    Generated by Claude Code

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