fix: SersicCore.intensity_prime ZeroDivisionError on effective_radius=0 (#514) - #515
Merged
Merged
Conversation
…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>
Collaborator
Author
|
Workspace PR: PyAutoLabs/autolens_workspace#306 (merges after this, library-first). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
SersicCore.intensity_primeraisedZeroDivisionErrorwheneffective_radius == 0because 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 byeffective_radius, yieldinginf— a non-finite value the non-linear search resamples on — rather than crashing. This switches the scalar division toxp.dividesoSersicCorebehaves 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), whoseeffective_radius = wavelength*m + crelation —m ~ U(-0.1,0.1),c ~ U(-10,10), both symmetric about 0 — yieldseffective_radius=0at the test-mode median instance.alphawas never the cause (Constant 3.0; probe-verified).API Changes
No signature changes. One behaviour change:
Changed Behaviour
SersicCore.intensity_prime()(and henceSersicCore/SersicCoreSphimage evaluation) witheffective_radius <= 0now returns a non-finite value (inf/nan) instead of raisingZeroDivisionError. Callers that fitSersicCoreget the standard non-finite →FitException/resample path rather than a hard crash. The return is now a numpy/jax scalar (was a Pythonfloat) for the affected term; numeric results for physicaleffective_radius > 0are 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 checknp.isfinite.Test Plan
test_autogalaxy/profiles/light/standard/test_sersic_core.py— new numpy-only test:effective_radius=0.0→ non-finiteintensity_prime(), no raise (3 passed)test_autogalaxy/profiles/light/— 94 passedtest_autogalaxy/— 1004 passedautolens_workspace multi/features/wavelength_dependence/modelingruns 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.yamlmarker.Generated by the PyAutoLabs agent workflow.