fix: raw-flux latents + soft-fail magzero-required µJy#557
Merged
Conversation
The three µJy flux latents (total_lens_flux_mujy, total_lensed_source_flux_mujy, total_source_flux_mujy) used to raise ValueError when enabled in latent.yaml without magzero on the Analysis. The raise fired post-fit inside SearchUpdater._compute_latent_samples, killing the metric write of an otherwise-converged search (surfaced by autolens_profiling HPC job 322548).
This commit:
- adds three raw-flux latents (total_lens_flux, total_lensed_source_flux,
total_source_flux), default-on, no instrument inputs needed
- replaces _require_magzero with _maybe_magzero_warn; the three _mujy
latents now return xp.nan + one warning per process per latent name
- keeps the _mujy latents default-off (workspaces that pass magzero
opt in via their own latent.yaml override — Euclid pipeline pattern)
Refs #556
This was referenced May 28, 2026
Collaborator
Author
|
Workspace PR: PyAutoLabs/autolens_workspace#214 |
Collaborator
Author
|
Workspace PR: PyAutoLabs/autogalaxy_workspace#108 |
Collaborator
Author
|
Workspace PR: PyAutoLabs/autolens_workspace_test#133 |
Collaborator
Author
|
Workspace PR: PyAutoLabs/euclid_strong_lens_modeling_pipeline#19 |
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
The first first-class A100 search run from
autolens_profiling(HPC job 322548)converged cleanly in ~11 minutes, then
search.fit()crashed insideSearchUpdater._compute_latent_sampleswith:The raise lived in
autolens/analysis/latent.py:_require_magzeroand gatedthree µJy flux latents. Any workspace that enabled them without supplying
magzero=toAnalysisImagingwould silently kill its own metric outputafter every fit.
This PR:
default-on:
total_lens_flux,total_lensed_source_flux,total_source_flux._require_magzeroraise with a_maybe_magzero_warnhelper that returns NaN and emits one logger warning per latent name per
process. The three
_mujylatents now soft-fail and can never crash asearch.
_mujykeys default-off — workspaces with a knownzero-point (e.g.
euclid_strong_lens_modeling_pipeline) keep theiroverride and continue to receive populated µJy columns.
Mirrors the PyAutoGalaxy change at PyAutoLabs/PyAutoGalaxy#463 (linked once that PR is open).
API Changes
total_lens_flux,total_lensed_source_flux,total_source_flux), default-on. Same image-source and exception-handlingcontract as their
_mujysiblings — they just skip the AB-mag → µJy step._maybe_magzero_warn(magzero, name) -> bool._require_magzero(replaced by the helper above)._mujylatents:magzero=Nonenolonger raises — returns
xp.nan+ one warning per process per latent name.autolens/config/latent.yaml; existing keys unchanged.See full details below.
Test Plan
python -m pytest test_autolens/analysis/test_latent.py -v— 23/23 passtest_autolens/suite (subagent runs in CI commit)autolens_profiling/searches/nautilus/imaging/mge.pycell withoutPYAUTO_SKIP_LATENTS=1and confirmlatent.csvhas finite raw-flux columns + NaN µJy columns + one WARNING per µJy name in the log.euclid_strong_lens_modeling_pipelineregression read:config/latent.yamlstill has_mujy: trueand magzero is wired through — change is invisible to it.Refs #556. Depends on PyAutoGalaxy sibling PR for the helper's symmetry (the underlying
ab_mag_via_flux_from/flux_mujy_via_ab_mag_fromimports from PyAutoGalaxy are unchanged, so this PR's tests pass against PyAutoGalaxy main; the sibling PR can be merged in either order).Full API Changes (for automation & release notes)
Added
autolens.analysis.latent.total_lens_flux(fit, magzero=None, xp=np)— raw image-unit sum offit.galaxy_image_dict[fit.tracer.galaxies[0]].array.autolens.analysis.latent.total_lensed_source_flux(fit, magzero=None, xp=np)— raw image-unit sum offit.galaxy_image_dict[fit.tracer.galaxies[-1]].array.autolens.analysis.latent.total_source_flux(fit, magzero=None, xp=np)— raw image-unit sum of the source-plane image read viafit.tracer_linear_light_profiles_to_light_profiles.autolens.analysis.latent._maybe_magzero_warn(magzero, name) -> bool— module-private helper. ReturnsTrue(and logs one WARNING) whenmagzero is None;Falseotherwise.autolens.analysis.latent._MAGZERO_WARNED— module-level set tracking which latent names have already warned in this process.Removed
autolens.analysis.latent._require_magzero— replaced by_maybe_magzero_warn. Was module-private, but any external import would break._mujylatents no longer raiseValueError("magzero must be passed ...")onmagzero=None. Callers that previously caught thisValueErrorwill instead seexp.nan+ alogging.WARNINGrecord.Changed Behaviour
total_lens_flux_mujy(fit, magzero, xp=np): same signature;magzero=Nonenow →(xp.nan, logger.warning(...))instead of raise.total_lensed_source_flux_mujy(fit, magzero, xp=np): same.total_source_flux_mujy(fit, magzero, xp=np): same.magnification(fit, magzero, xp=np): unchanged signature, butmagzero=Nonenow propagatesNaN / NaN = NaN(with two warnings emitted on first call — one per µJy sibling) instead of raising. Previously the underlying_require_magzeroraise short-circuited the function.LATENT_FUNCTIONSregistry now has 8 keys: 3 raw-flux + 3 µJy + magnification + effective_einstein_radius.Default Config
autolens/config/latent.yamlgains:total_lens_flux: truetotal_lensed_source_flux: truetotal_source_flux: true*_flux_mujy: false,magnification: false,effective_einstein_radius: false) preserved.Migration
magzero(Euclid pipeline pattern unchanged).ValueError: drop the catch; the value is nowNaN._mujy: truein theirconfig/latent.yamlAND constructAnalysisImaging(..., magzero=<value>).🤖 Generated with Claude Code