Skip to content

fix: raw-flux latents + soft-fail magzero-required µJy#557

Merged
Jammy2211 merged 1 commit into
mainfrom
feature/flux-latents-raw
May 28, 2026
Merged

fix: raw-flux latents + soft-fail magzero-required µJy#557
Jammy2211 merged 1 commit into
mainfrom
feature/flux-latents-raw

Conversation

@Jammy2211
Copy link
Copy Markdown
Collaborator

@Jammy2211 Jammy2211 commented May 28, 2026

Summary

The first first-class A100 search run from autolens_profiling (HPC job 322548)
converged cleanly in ~11 minutes, then search.fit() crashed inside
SearchUpdater._compute_latent_samples with:

ValueError: magzero must be passed to the Analysis via kwargs to compute
the 'total_lens_flux_mujy' latent. ...

The raise lived in autolens/analysis/latent.py:_require_magzero and gated
three µJy flux latents. Any workspace that enabled them without supplying
magzero= to AnalysisImaging would silently kill its own metric output
after every fit.

This PR:

  1. Adds three new raw-flux latents that need no instrument inputs and ship
    default-on: total_lens_flux, total_lensed_source_flux, total_source_flux.
  2. Replaces the hard _require_magzero raise with a _maybe_magzero_warn
    helper that returns NaN and emits one logger warning per latent name per
    process. The three _mujy latents now soft-fail and can never crash a
    search.
  3. Leaves the existing _mujy keys default-off — workspaces with a known
    zero-point (e.g. euclid_strong_lens_modeling_pipeline) keep their
    override and continue to receive populated µJy columns.

Mirrors the PyAutoGalaxy change at PyAutoLabs/PyAutoGalaxy#463 (linked once that PR is open).

API Changes

  • Added three raw-flux latents (total_lens_flux, total_lensed_source_flux,
    total_source_flux), default-on. Same image-source and exception-handling
    contract as their _mujy siblings — they just skip the AB-mag → µJy step.
  • Added module-level helper _maybe_magzero_warn(magzero, name) -> bool.
  • Removed _require_magzero (replaced by the helper above).
  • Behaviour change on the three _mujy latents: magzero=None no
    longer raises — returns xp.nan + one warning per process per latent name.
  • Default config change: three new raw-flux keys default-on in
    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 pass
  • Full test_autolens/ suite (subagent runs in CI commit)
  • End-to-end (post-merge): re-run an autolens_profiling/searches/nautilus/imaging/mge.py cell without PYAUTO_SKIP_LATENTS=1 and confirm latent.csv has finite raw-flux columns + NaN µJy columns + one WARNING per µJy name in the log.
  • euclid_strong_lens_modeling_pipeline regression read: config/latent.yaml still has _mujy: true and 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_from imports 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 of fit.galaxy_image_dict[fit.tracer.galaxies[0]].array.
  • autolens.analysis.latent.total_lensed_source_flux(fit, magzero=None, xp=np) — raw image-unit sum of fit.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 via fit.tracer_linear_light_profiles_to_light_profiles.
  • autolens.analysis.latent._maybe_magzero_warn(magzero, name) -> bool — module-private helper. Returns True (and logs one WARNING) when magzero is None; False otherwise.
  • 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.
  • The three _mujy latents no longer raise ValueError("magzero must be passed ...") on magzero=None. Callers that previously caught this ValueError will instead see xp.nan + a logging.WARNING record.

Changed Behaviour

  • total_lens_flux_mujy(fit, magzero, xp=np): same signature; magzero=None now → (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, but magzero=None now propagates NaN / NaN = NaN (with two warnings emitted on first call — one per µJy sibling) instead of raising. Previously the underlying _require_magzero raise short-circuited the function.
  • LATENT_FUNCTIONS registry now has 8 keys: 3 raw-flux + 3 µJy + magnification + effective_einstein_radius.

Default Config

  • autolens/config/latent.yaml gains:
    • total_lens_flux: true
    • total_lensed_source_flux: true
    • total_source_flux: true
  • Existing keys (*_flux_mujy: false, magnification: false, effective_einstein_radius: false) preserved.

Migration

  • No migration required for code that passes magzero (Euclid pipeline pattern unchanged).
  • Code that previously caught the ValueError: drop the catch; the value is now NaN.
  • Workspaces that want a µJy column auto-populated: enable the relevant _mujy: true in their config/latent.yaml AND construct AnalysisImaging(..., magzero=<value>).
  • Workspaces that want raw flux only: nothing to do — the three new latents are default-on.

🤖 Generated with Claude Code

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
@Jammy2211
Copy link
Copy Markdown
Collaborator Author

Workspace PR: PyAutoLabs/autolens_workspace#214

@Jammy2211
Copy link
Copy Markdown
Collaborator Author

Workspace PR: PyAutoLabs/autogalaxy_workspace#108

@Jammy2211
Copy link
Copy Markdown
Collaborator Author

Workspace PR: PyAutoLabs/autolens_workspace_test#133

@Jammy2211
Copy link
Copy Markdown
Collaborator Author

@Jammy2211 Jammy2211 merged commit 0f67334 into main May 28, 2026
6 checks passed
@Jammy2211 Jammy2211 deleted the feature/flux-latents-raw branch May 28, 2026 13:25
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