Skip to content

findings: correct two disproved claims about the Fitness NaN guard - #106

Merged
Jammy2211 merged 1 commit into
mainfrom
feature/fitness-nan-guard-contract
Jul 17, 2026
Merged

Jammy2211 merged 1 commit into
mainfrom
feature/fitness-nan-guard-contract

Conversation

@Jammy2211

Copy link
Copy Markdown
Contributor

Part of PyAutoFit#1391. Upstream PR: PyAutoLabs/PyAutoFit#1392 (must merge first — library-first gate).

Corrects two claims in searches_minimal/pix_nonfinite_findings.md that shipped in #105 and were disproved by the follow-up investigation. main currently carries advice that does not work.

What was wrong

The doc's site-2 section (the PyAutoFit where-guard) was written before the mechanism was tested. Two errors:

1. Overreach. It claimed the guard "does not protect gradient consumers at all". The trap actually fires only when the masked branch's derivative is non-finite — not merely its value:

primal at a bad point value derivative trap fires?
log(x), x<0 NaN 1/x = finite no — 0 * -1 = 0
sqrt(x), x<0 NaN NaN yes
cholesky(A), non-PD (site 1) NaN NaN yes

2. The prescribed remedy does not work. The doc called for "the standard double-where (safe-x) pattern". Applied to the output — which is all Fitness.call can do — it fixes nothing. Measured:

current (fitness.py:239-240)     x=-1.0  value=inf  grad=nan
output-side double-where         x=-1.0  value=inf  grad=nan   <-- prescribed remedy FAILS
input-side safe-x                x=-1.0  value=inf  grad=0.0   <-- works

By the time Fitness.call receives log_likelihood, the non-finite derivative is already on the autodiff tape. Only refusing to evaluate the offending op at the invalid input works, and that requires knowing which input is invalid — knowable at the NaN's source (site 1, autoarray's Cholesky), not at the Fitness boundary.

Consequence: Fitness.call is structurally incapable of fixing this, so PyAutoFit#1391 is scoped to pinning the contract (docstring + assertion script), not a code fix. Site 1 remains the real fix.

Also corrected: the reproduction note. This specific bug needs ~20 lines of CPU JAX, not the A100 — only the site-1 localisation does.

The site-1 localisation is unaffected — log_det_regularization_matrix_term, the exonerations, and the mechanism all stand.

Scripts Changed

Script Change
searches_minimal/pix_nonfinite_findings.md Site-2 section rewritten: CONTRACT, not a fix. Both corrections folded in with the measured disproof, marked with a dated correction note. Original wording preserved in git history.

Doc only — no code, no scripts, no notebooks.

Gate

  • Tests — n/a (no test dir).
  • Smoke — n/a: markdown only.
  • Heart — RED, acknowledged contemporaneously by the human on 5 pre-existing unrelated reasons; RED verbatim: PyAutoLens: 1 uncommitted source change(s).

…1391)

The doc shipped in #105 before the follow-up investigation. Two corrections:

1. "does not protect gradient consumers at all" was overreach -- the trap fires
   only when the masked branch's DERIVATIVE is non-finite. sqrt/cholesky yes;
   log(x<0) no (d/dx = 1/x stays finite).
2. the prescribed remedy ("the standard double-where / safe-x pattern") DOES NOT
   WORK applied to the output. Measured: output-side double-where still grads
   NaN; only input-side safe-x is finite. By the time Fitness.call sees the
   log_likelihood the non-finite derivative is already on the tape.

So Fitness.call is structurally incapable of fixing this and PyAutoFit#1391 is
scoped to pinning the contract, not a code fix. Also corrects the A100 note --
this specific bug reproduces in ~20 lines of CPU JAX.

The site-1 localisation is unaffected.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@Jammy2211 Jammy2211 added the pending-release Pending release build label Jul 17, 2026
@Jammy2211
Jammy2211 merged commit c61afd2 into main Jul 17, 2026
@Jammy2211
Jammy2211 deleted the feature/fitness-nan-guard-contract branch July 17, 2026 13:10
@Jammy2211 Jammy2211 removed the pending-release Pending release build label Oct 7, 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.

1 participant