Skip to content

fix: ship log_likelihood_ceiling disabled by default — the magnitude is not unit-safe - #1550

Merged
Jammy2211 merged 1 commit into
mainfrom
feature/log-likelihood-ceiling-default-off
Aug 30, 2026
Merged

Jammy2211 merged 1 commit into
mainfrom
feature/log-likelihood-ceiling-default-off

Conversation

@Jammy2211

Copy link
Copy Markdown
Collaborator

Summary

Follow-up to #1545 (merged b70cf7fc3), which shipped the general.test.log_likelihood_ceiling guard enabled at 1.0e+20.

The threshold is not unit-safe. A log likelihood is -0.5 * chi_squared - 0.5 * noise_normalization, and both terms scale with the noise-map units — chi_squared as noise ** -2, noise_normalization linearly in the pixel count. A dataset whose noise map is expressed in a small unit can therefore produce a legitimate log likelihood above 1e20; every model would be silently mapped to the resample figure of merit, and the search would see nothing but rejections and could not fit at all. The guard reads only a magnitude in unspecified units, so it cannot distinguish that from the fp64-Cholesky garbage it was built for (a non-positive-definite regularization matrix returning finite ~3e+303, which a nested sampler accepts as its peak and never terminates on).

A default that can silently break a correctly-specified fit is the wrong default. The code path stays; the packaged default flips off, and the guard becomes opt-in on surfaces whose units are known. autolens_profiling enables it at 1.0e+20 in its own config, citing run 341908_5 (PyAutoLabs/autolens_profiling — separate, independent PR). Whether real PyAutoLens analyses should enable it is deferred until the Wave-B harvest gives enough results to say what magnitudes science fits actually reach.

Also added: a first-fire warning. A rejection is invisible from inside the search — it looks exactly like a bad model — so the numpy path says so once per process, naming the value, the ceiling and the units caveat. The jax.jit / jax.vmap paths cannot warn: the rejection is an xp.where on a tracer, with no Python-visible moment at which the guard fires, so they reject silently by construction. No fire counter is offered for them either — incrementing one from traced code needs a host callback or a donated buffer, which perturbs the code being profiled and does not survive vmap/grad, and a counter blind to the traced paths would read 0 on a jitted run that rejected every sample. Both facts are documented at the call site.

API Changes

The guard's default behaviour changes: general.test.log_likelihood_ceiling now ships blank, and a config that omits the key is now treated as disabled rather than 1.0e20. Fits that were silently rejecting finite log likelihoods above 1e20 will now accept them, restoring pre-#1545 behaviour unless a config opts in. LOG_LIKELIHOOD_CEILING_DEFAULT is still exported but its value changes from 1.0e20 to inf. No symbol is removed or renamed, and no signature changes.
See full details below.

Test Plan

  • pytest test_autofit/ — 2375 passed, 3 skipped
  • pytest test_autofit/non_linear/ — 791 passed, 2 skipped
  • The three ceiling test files (numpy, JAX jit/vmap, NSS closure) — 40 passed, none skipped (JAX present)
  • Both packaged general.yaml files parse the blank key as None → get_log_likelihood_ceiling() returns inf
  • A workspace with no key at all (autolens_workspace) resolves to inf
  • autolens_profiling's layered override resolves to 1e+20 while its sibling test: keys still merge from the packaged defaults
Full API Changes (for automation & release notes)

Changed Behaviour

  • general.test.log_likelihood_ceiling (config) — ships blank/disabled; was 1.0e+20. Applies to autofit/config/general.yaml and test_autofit/config/general.yaml.
  • autofit.non_linear.fitness.get_log_likelihood_ceiling() — an absent config key now returns inf (disabled); it previously returned 1.0e20. null, non-positive and unparseable entries still map to inf, unchanged.
  • autofit.non_linear.fitness.Fitness.call — emits a single logger.warning per process the first time the magnitude guard rejects a value on the numpy path. The jax.jit / jax.vmap paths are unchanged and silent.
  • autofit.non_linear.search.nest.nss.search.nss_log_likelihood_from — its default ceiling (read from config) is now disabled; an explicit log_likelihood_ceiling= argument is unchanged. Its non-finite (NaN/inf) guard is unaffected and still unconditional.

Changed Value

  • autofit.non_linear.fitness.LOG_LIKELIHOOD_CEILING_DEFAULT — 1.0e20 → float("inf").

Added

  • autofit.non_linear.fitness.Fitness._is_jax (private property) — whether the array backend is JAX, so the warning stays off the traced paths.

Migration

  • To keep the previous behaviour, set the key explicitly in your workspace config/general.yaml:
    test:
      log_likelihood_ceiling: 1.0e+20
  • To disable it (the new default), leave the key blank or omit it entirely.

Closes #1549.

Generated by the PyAutoLabs agent workflow.

…is not unit-safe

PR #1545 shipped the `general.test.log_likelihood_ceiling` guard enabled at
1.0e+20. The threshold is not unit-safe: a log likelihood is
`-0.5 * chi_squared - 0.5 * noise_normalization`, and both terms scale with the
noise map — chi_squared as `noise ** -2`, noise_normalization linearly in the
pixel count. A dataset whose noise map is expressed in a small unit can produce
a legitimate log likelihood above 1e20, and every model would be silently mapped
to the resample sentinel, leaving the search unable to fit at all. The guard
reads only a magnitude, so it cannot tell that case from the fp64-Cholesky
garbage it was built for.

The code path stays; the packaged default flips off.

- `autofit/config/general.yaml` and `test_autofit/config/general.yaml`:
  `log_likelihood_ceiling` is now blank (disabled), with the units argument in
  the comment and a pointer at the surface that opts in.
- `LOG_LIKELIHOOD_CEILING_DEFAULT` is now `inf`, so a config that never mentions
  the key inherits today's default rather than the one that shipped with the
  guard's first release.
- `Fitness.call` warns once per process, on the numpy path, the first time the
  guard actually rejects a value — a rejection is otherwise indistinguishable
  from "the model is bad" from inside the search. The jit/vmap paths reject
  silently by construction (the mask is a tracer); no fire counter is exposed
  for them, because incrementing one from traced code needs a host callback or a
  donated buffer, and a counter blind to the traced paths would read 0 on a
  jitted run that rejected every sample.
- Docstrings in `fitness.py` and `nss/search.py` describe an opt-in guard.
- Tests: the "default 1e20" expectations become "default disabled"; every
  enabled-path test sets the ceiling explicitly, as a user's `general.yaml`
  would; new coverage for the first-fire warning, its once-per-process latch,
  its silence when nothing is rejected, and its absence on the jit path.

autolens_profiling opts in at 1.0e+20 (its own config), citing run 341908_5.

Refs #1549.
@Jammy2211 Jammy2211 added the pending-release PR queued for the next release build label Aug 29, 2026
@Jammy2211
Jammy2211 merged commit dc53a25 into main Aug 30, 2026
4 checks passed
@Jammy2211
Jammy2211 deleted the feature/log-likelihood-ceiling-default-off branch August 30, 2026 01:16
@Jammy2211 Jammy2211 removed the pending-release PR queued for the next release build label Sep 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: ship log_likelihood_ceiling disabled by default — the magnitude is not unit-safe

1 participant