Skip to content

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

Closed

Description

@Jammy2211

Overview

PR #1545 shipped the general.test.log_likelihood_ceiling guard enabled at 1.0e+20: a finite log likelihood whose magnitude exceeds the ceiling is mapped to the resample figure of merit, closing the hole where an fp64 Cholesky on a non-positive-definite matrix returns finite garbage (~3e+303) that a nested sampler accepts as its best point and never terminates on.

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 badly-scaled dataset can therefore produce a legitimate log likelihood above 1e20, and every model would be silently rejected as garbage, leaving the search with nothing but the resample sentinel. The guard reads a bare magnitude in unspecified units, so it cannot tell that case from the one it was built for.

Human decision (2026-08-29): keep the code path, flip the packaged default off. The guard becomes opt-in for the surface that actually needed it — autolens_profiling, where run 341908_5 was diagnosed as a likelihood-overflow flood. Whether real PyAutoLens analyses should run with it on is deferred until the Wave-B harvest produces more results.

Plan

  • Flip the packaged default to disabled (log_likelihood_ceiling: null) in both autofit/config/general.yaml and test_autofit/config/general.yaml, with a comment stating the unit argument and that profiling opts in.
  • Make a missing config key mean disabled, not 1.0e20 — a workspace whose general.yaml pre-dates the key must inherit the new default rather than the old one.
  • Warn once per process, the first time the guard actually fires, on the numpy path; document that the jax.jit / vmap paths stay silent by construction (a Python logger call cannot run on a traced value) and expose a counter only if it is trivially possible without perturbing the traced code.
  • Update the docstrings in fitness.py and nss/search.py so they describe an opt-in guard, and update the existing tests: the "default 1e20" expectations become "default disabled", while the enabled-path coverage is kept by setting the ceiling explicitly.
  • Enable the guard in autolens_profiling/config/general.yaml (separate PR, config-only) and record the decision in that repo's results/notes/inference/DECISIONS.md.
Detailed implementation plan

Affected Repositories

  • PyAutoFit (primary)
  • autolens_profiling (config + decision note; separate, independent PR)

Branch Survey

Repository Current Branch Dirty?
./PyAutoFit main clean
./autolens_profiling main clean

worktree_check_conflict reports PyAutoFit claimed by nautilus-serial-bound-training (awaiting-merge, PR #1548). That branch touches only autofit/non_linear/search/nest/nautilus/search.py and test_autofit/non_linear/search/nest/test_nautilus.py — disjoint from this task's file set — so this task takes its own parallel worktree, recorded as a parallel-claim: on the active.md entry.

Suggested branch: feature/log-likelihood-ceiling-default-off

Implementation Steps

  1. autofit/config/general.yaml — test.log_likelihood_ceiling: becomes blank (null), comment rewritten: disabled by default because the magnitude is unit-dependent; set a float to opt in.
  2. test_autofit/config/general.yaml — the same flip, so the unit suite exercises the shipped default.
  3. autofit/non_linear/fitness.py
    • Replace LOG_LIKELIHOOD_CEILING_DEFAULT = 1.0e20 with a disabled default (inf), so the except KeyError branch of get_log_likelihood_ceiling returns "disabled".
    • Rewrite get_log_likelihood_ceiling's docstring: the guard is opt-in, the units argument is the reason, profiling is the surface that enables it.
    • Add a module-level "already warned" flag and emit a single logger.warning the first time the numpy path substitutes the resample value for an over-ceiling likelihood; state in the docstring that the JAX paths cannot warn.
    • Fitness.call docstring: describe the guard as off unless configured.
  4. autofit/non_linear/search/nest/nss/search.py — nss_log_likelihood_from docstring updated to match (default now disabled; the ceiling arg is how a caller opts in).
  5. Tests
    • test_autofit/non_linear/test_fitness_assertions.py — test_fitness_ceiling_defaults_to_the_configured_value asserts inf; the enabled-path tests set fitness.log_likelihood_ceiling = 1.0e20 explicitly; the get_log_likelihood_ceiling parametrisation and the absent-key test assert the disabled default; add coverage for the first-fire warning.
    • test_autofit/non_linear/test_fitness_ceiling_jax.py — set the ceiling explicitly on the enabled-path JAX tests.
    • test_autofit/non_linear/search/nest/nss/test_log_likelihood_ceiling.py — test_nss_closure_defaults_to_the_configured_ceiling becomes "defaults to disabled".

Key Files

  • autofit/non_linear/fitness.py — get_log_likelihood_ceiling, Fitness.call, Fitness.__setstate__
  • autofit/non_linear/search/nest/nss/search.py — nss_log_likelihood_from
  • autofit/config/general.yaml, test_autofit/config/general.yaml
  • test_autofit/non_linear/test_fitness_assertions.py, test_autofit/non_linear/test_fitness_ceiling_jax.py, test_autofit/non_linear/search/nest/nss/test_log_likelihood_ceiling.py

Original Prompt

Click to expand starting prompt

sounds good let me know if you think we need it in actual autolsns analysis once we have more results

Follow-up to PR #1545: the ceiling is not unit-safe (chi-squared and the noise-normalisation term both scale with the noise-map units), so a badly-scaled dataset could legitimately exceed 1e20 and be rejected as invalid. Decision: PyAutoFit ships the guard OFF (log_likelihood_ceiling: null, missing key = disabled), keeps the code path, warns once on first fire on the numpy path; autolens_profiling enables it in its own config citing 341908_5, and records in results/notes/inference/DECISIONS.md that the ceiling is profiling-only by human decision with a reassessment owed for real PyAutoLens analyses after the Wave-B harvest.

Activity

  1. Jammy2211 commented on Aug 29, 2026

    @Jammy2211
    CollaboratorAuthor

    Library PR Created

    Both PRs are open. They are independent — the profiling PR only sets a config key, which is inert until PyAutoFit reads it, so neither blocks the other.

    Repo PR Commit Contents
    PyAutoFit #1550 f661b75c9 default flipped off, missing-key semantics, first-fire warning, docstrings, tests
    autolens_profiling #198 dfeafbf1 config/general.yaml opt-in at 1.0e+20, dated DECISIONS.md entry

    API-change summary

    The guard's default behaviour changes. general.test.log_likelihood_ceiling now ships blank, and a config that omits the key is treated as disabled rather than 1.0e20 (LOG_LIKELIHOOD_CEILING_DEFAULT goes 1.0e20 → inf). Fits that were silently rejecting finite log likelihoods above 1e20 accept them again — pre-#1545 behaviour, unless a config opts in. No symbol removed or renamed, no signature changed.

    Why the default could not stay on

    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 badly-scaled dataset can exceed any fixed magnitude legitimately, and every model would then be mapped to the resample sentinel — the search would see nothing but rejections and could not fit at all. The guard reads only a magnitude, so it cannot tell that from the fp64-Cholesky garbage it was built for.

    The warning, and what was deliberately not built

    The numpy path warns once per process the first time the guard actually rejects a value, naming the value, the ceiling and the units caveat — a rejection is otherwise indistinguishable from "the model is bad" from inside the search.

    The jax.jit / vmap paths reject silently by construction: the mask is a tracer, so there is no Python-visible moment at which the guard fires. A fire counter for those paths was considered and skipped — 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 rather than left for a future reader to rediscover.

    Downstream impact

    No workspace repo carries the key — grep -rl log_likelihood_ceiling --include=*.yaml across the workspace matches only PyAutoFit's own two config files. Every workspace therefore inherits the new "missing key = disabled" default, which is the intended outcome. Verified directly: from autolens_workspace, get_log_likelihood_ceiling() returns inf; from autolens_profiling, 1e+20, with its sibling test: keys still merging from PyAutoFit's packaged defaults (the layered override adds a key, it does not replace the block).

    Verification

    • pytest test_autofit/ — 2375 passed, 3 skipped
    • The three ceiling test files — 40 passed, none skipped (JAX present, so the jit/vmap and NSS legs really ran)
    • autolens_profiling lint parity — ruff check, ruff format --check (186 files), build_readme.py --check (all dashboards unchanged), check_submits.py --check (55 submits, 0 failing, 89 scanned)

    Open for the human

    • Heart is YELLOW, not acknowledged. workspace validation not passing (0 failed, 1 timeout, cloud#33229145647: autolens_test scripts/multi_dataset/delaunay_mge.py), plus the stale release validation incomplete: no rehearsal for current source. Both are unrelated to this change. This run stopped at PR-open; nothing was merged.
    • The reassessment is owed, not done. Whether real PyAutoLens analyses should enable the ceiling is deferred to after the Wave-B harvest, and is recorded as such in autolens_profiling/results/notes/inference/DECISIONS.md. The profiling opt-in should not be extended by analogy before then.
  2. Jammy2211 commented on Aug 30, 2026

    @Jammy2211
    CollaboratorAuthor

    Shipped

    Merged as PR #1550 (dc53a25). general.test.log_likelihood_ceiling now defaults to off (blank / missing key = disabled) because χ² and the noise-normalisation term scale with the noise-map units, so an absolute ceiling is not unit-safe; a once-per-process warning fires on the numpy path when the guard rejects a value. autolens_profiling opts in at 1e20 (PR #198, 6fe8f72b8). Reassessment for real PyAutoLens analyses is owed after the Wave-B harvest.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions