Skip to content

fix: SersicCore.intensity_prime ZeroDivisionError on effective_radius=0 (#514) - #515

Merged
Jammy2211 merged 1 commit into
mainfrom
feature/sersic-core-effective-radius-zero
Jul 21, 2026
Merged

fix: SersicCore.intensity_prime ZeroDivisionError on effective_radius=0 (#514)#515
Jammy2211 merged 1 commit into
mainfrom
feature/sersic-core-effective-radius-zero

Conversation

@Jammy2211

Copy link
Copy Markdown
Collaborator

Summary

SersicCore.intensity_prime raised ZeroDivisionError when effective_radius == 0 because it divided a Python scalar with a plain /. Every other profile (e.g. Sersic.image_2d_via_radii, sersic.py:99/157) divides a numpy array by effective_radius, yielding inf — a non-finite value the non-linear search resamples on — rather than crashing. This switches the scalar division to xp.divide so SersicCore behaves identically (numpy/jax parity; same raise-vs-resample lineage as PyAutoLens#607).

Surfaced by autolens_workspace multi/features/wavelength_dependence/modeling (split out from autolens_workspace#300), whose effective_radius = wavelength*m + c relation — m ~ U(-0.1,0.1), c ~ U(-10,10), both symmetric about 0 — yields effective_radius=0 at the test-mode median instance. alpha was never the cause (Constant 3.0; probe-verified).

API Changes

No signature changes. One behaviour change:

Changed Behaviour
  • SersicCore.intensity_prime() (and hence SersicCore / SersicCoreSph image evaluation) with effective_radius <= 0 now returns a non-finite value (inf/nan) instead of raising ZeroDivisionError. Callers that fit SersicCore get the standard non-finite → FitException/resample path rather than a hard crash. The return is now a numpy/jax scalar (was a Python float) for the affected term; numeric results for physical effective_radius > 0 are unchanged (existing exact-value tests still pass).

Migration: none required. Any downstream code that relied on the ZeroDivisionError (there is none in the stack) should instead check np.isfinite.

Test Plan

  • test_autogalaxy/profiles/light/standard/test_sersic_core.py — new numpy-only test: effective_radius=0.0 → non-finite intensity_prime(), no raise (3 passed)
  • test_autogalaxy/profiles/light/ — 94 passed
  • Full test_autogalaxy/ — 1004 passed
  • Downstream: autolens_workspace multi/features/wavelength_dependence/modeling runs green under the CI smoke env (workspace PR follows)

Downstream

Workspace follow-up (autolens_workspace, ships after this merges): add the missing auto-simulate block to the multi-wavelength script + drop its no_run.yaml marker.

Generated by the PyAutoLabs agent workflow.

…ead of ZeroDivisionError

`intensity_prime` divided a Python scalar by `self.effective_radius` with a plain
`/`, so `effective_radius == 0` raised `ZeroDivisionError`. Every other profile
(e.g. `Sersic.image_2d_via_radii`) divides a numpy array and yields `inf` — a
non-finite value the non-linear search resamples on — rather than crashing.
Switch the scalar division to `xp.divide` so `SersicCore` behaves the same
(numpy/jax parity; same raise-vs-resample lineage as PyAutoLens#607).

Surfaced by autolens_workspace multi/features/wavelength_dependence/modeling,
whose `effective_radius = wavelength*m + c` relation (m,c priors symmetric about
0) yields `effective_radius=0` at the test-mode median instance. `alpha` was
never the cause (Constant 3.0).

Added a numpy-only unit test asserting `effective_radius=0` gives a non-finite
`intensity_prime()` without raising.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@Jammy2211

Copy link
Copy Markdown
Collaborator Author

Workspace PR: PyAutoLabs/autolens_workspace#306 (merges after this, library-first).

@Jammy2211
Jammy2211 merged commit 771c6f0 into main Jul 21, 2026
5 checks passed
@Jammy2211
Jammy2211 deleted the feature/sersic-core-effective-radius-zero branch July 21, 2026 16:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pending-release PR queued for the next release build

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant