Repository navigation
Description
Overview
autolens_workspace/scripts/interferometer/features/pixelization/delaunay.py intermittently hard-fails CI smoke: the same commit (dce04672) failed one py3.12 run (ValueError: Points cannot contain NaN from the Delaunay/qhull triangulation) and passed another ~1 min apart, with no library merge in between — a true nondeterministic flake. The masked underlying cause is a NaN/non-PD in the interferometer Delaunay path; analysis.py:175-182 wraps ANY numpy-path error as af.exc.FitException (PR#607 parity guard so the sampler resamples), but under PYAUTO_TEST_MODE=2 there is no sampler, so a single unlucky eval hard-fails the script. The entry is currently parked in autolens_workspace/config/build/no_run.yaml.
Plan
- Phase 1 — un-flake test-mode (PyAutoLens + autolens_workspace): make the
TEST_MODEbypass tolerate a single-evalFitExceptionthe way a real sampler does (resample / sentinel low FOM, logged so it stays visible) instead of hard-failing. This un-flakes all FitException-prone pixelization scripts in test-mode without masking real breakage in a real fit. Then un-park the interferometer Delaunayno_run.yamlentry and add the script tosmoke_tests.txt(imaging Delaunay was added in autolens_workspace#307). - Phase 2 — fix the numerical producer (PyAutoArray, separate PR): the smoking gun is
fnnls.py:134(alpha = np.min(d[q] / (d[q] - s_chol[q]))) — 45/250 local draws emit divide-by-zero/invalidRuntimeWarnings, usually benign but a candidate source of the fatal NaN/non-PD on CI. Guard/repair at the producer (no silent guards — fix the math) and/or the traced-mesh NaN conditioning.
Detailed implementation plan
Affected Repositories
- PyAutoLens (primary — Phase 1 test-mode tolerance,
interferometer/model/analysis.py) - autolens_workspace (Phase 1 — un-park marker + smoke)
- PyAutoArray (Phase 2 —
util/fnnls.pyproducer fix)
Branch Survey
| Repository | Current Branch | Dirty? |
|---|---|---|
| ./PyAutoLens | docs/citations-exhaustive (other session) | dirty |
| ./PyAutoArray | main | clean |
| ./autolens_workspace | main | clean |
Suggested branch: interferometer-delaunay-flaky-fitexception
Reproduction evidence (2026-07-21)
- True flake, not a library race: Feature/multi image visualization #307's two CI runs (same commit
dce04672) ~1 min apart, one failed (qhull NaN) one passed, no PyAutoArray/PyAutoLens main merge between them. - Local repro hard: 250/250 random prior-instance
fit_fromdraws clean on current main — CI-runner thread/BLAS-dependent. - Producer: 45/250 draws emit
RuntimeWarningdivide-by-zero atfnnls.py:134. Confirm which solver the script's modeling uses (use_positive_only_solver=Falsevs default positive/fnnls path).
Phase 1 steps
PyAutoLens/autolens/interferometer/model/analysis.py:175-182— in theTEST_MODEpath, catch the single-evalFitException, log it, return a sentinel low figure-of-merit instead of propagating (mirror the real-sampler resample semantics). Check for a shared base-analysis test-mode hook so imaging/pixelization scripts benefit too.autolens_workspace/config/build/no_run.yaml— remove the interferometer DelaunayNEEDS_FIXentry.autolens_workspace/smoke_tests.txt— addinterferometer/features/pixelization/delaunay.py.- Verify: run the script in the exact CI smoke env repeatedly; run library unit tests; smoke.
Key Files
PyAutoLens/autolens/interferometer/model/analysis.py— test-mode FitException tolerancePyAutoArray/autoarray/util/fnnls.py— Phase 2 divide-by-zero producerautolens_workspace/config/build/no_run.yaml,smoke_tests.txt— un-park + guard
Testing
Library unit tests (numpy-only) for the test-mode tolerance path; repeated CI-env script runs to confirm the flake is gone; PyAutoHeart vitals GREEN/YELLOW before ship. Library-first: PyAutoLens PR merges before the autolens_workspace un-park.
Original Prompt
Click to expand
Filed as PyAutoMind/draft/bug/autoarray/interferometer_delaunay_intermittent_qhull_nan.md. Surfaced 2026-07-21 while un-parking the Delaunay cluster (autolens_workspace#307, follow-up to #300/#301). Two masked signatures (qhull NaN vertices + non-PD inversion), both wrapped as FitException by analysis.py:175-182. Refs (all closed): autolens_workspace#300/#307/#308/#309.
Activity
Jammy2211 commentedon Jul 21, 2026
Phase 1 library PR created: PyAutoLabs/PyAutoFit#1408 (
pending-release).Re-scoped from PyAutoLens to PyAutoFit after the full CI traceback showed the failure runs through autofit's
_fit_bypass_test_mode(abstract_search.py), not PyAutoLens analysis —source_pix_2(Hilbert adaptive mesh) → bypass single-eval →log_likelihood_function→ Delaunay interpolator →scipy_delaunayNaN. The fix makes the TEST_MODE=2 bypass tolerate a single-evalFitException(keep the-1e99sentinel, log the cause) — central, fixes all analyses; onlyFitExceptionis caught so real errors still fail loudly. Complements PyAutoLens#639.Remaining (this task):
no_run.yamlentry + add tosmoke_tests.txt.fnnls.py:134divide-by-zero / degenerate Hilbert-mesh vertices) so the fit is correct, not merely tolerated.Jammy2211 commentedon Jul 21, 2026
Phase 1a MERGED (PyAutoFit#1408) and Phase 1b PR opened (autolens_workspace#311): un-park the interferometer Delaunay + add to smoke, now safe on the merged fix. Local
run_smoke.py= 11/11 passed (interferometer delaunay 25.5s). Library-first satisfied. Remaining: Phase 2 — fix the underlying NaN/non-PD producer (fnnls.py:134 / degenerate Hilbert-mesh vertices) so the fit is correct, not merely tolerated.Jammy2211 commentedon Jul 21, 2026
✅ Phase 1 complete (both PRs merged)
TEST_MODE=2bypass tolerates a single-evalFitException(keep-1.0e99sentinel + log), mirroringfitness.py:256's resample-to-reject. +2 tests; CI green 3.12/3.13.no_run.yamlentry + added tosmoke_tests.txt. CI green on 3.12 and 3.13 against the merged fix — the flake no longer hard-fails.User-facing problem resolved: the intermittent CI failure is fixed; any future FitException-raising instance in test-mode is now tolerated (all analyses benefit, not just this script).
Remaining — Phase 2 (open, non-urgent)
Fix the underlying producer in PyAutoArray so the fit is correct, not merely tolerated: the NaN Delaunay-mesh vertices in
source_pix_2(Hilbert adaptive mesh — the actual failing stage) and/or thefnnls.py:134divide-by-zero (45/250 local draws hit it). This is harder — the flake is CI-thread-dependent and not locally reproducible on the Overlay stage (250 draws clean), so it needs asource_pix_2Hilbert-stage reproduction first. Keeping this issue open for Phase 2.Jammy2211 commentedon Aug 7, 2026
Phase 2: root cause re-pointed, fix pushed
Phase 2 is implemented on
claude/interferometer-delaunay-phase-2-1p53vkin PyAutoArray (9e9a3360). No PR opened yet.fnnls.py:134is not the producerThe plan above names it as "the smoking gun". It isn't. I exercised it 599 times across 600 constraint-binding draws with zero degenerate denominators. The 45/250
RuntimeWarnings recorded in phase 1 are a downstream symptom, not the cause. Line 134 is unchanged by this fix.The producer is
cholesky_funcs.py→cholinsertlastTwo (near-)coincident source-mesh vertices give (near-)identical mapping-matrix columns, so the normal-equations matrix is singular to working precision and that Schur complement is zero to within rounding — measured at ±1.776e-15 (= 8·eps). Which side of zero it lands on is decided purely by floating-point summation order, i.e. by the BLAS thread count. That is the CI-vs-local thread dependence, and it is why 250 local draws came back clean.
The same degenerate matrix therefore failed three different ways (60 exactly-singular draws):
ValueError: math domain errorcho_solvedivides by itcho_solveWhy it surfaced in
source_pix_2, a stage away from the causeinversion_util.py:365guards the solver withexcept (RuntimeError, LinAlgError, ValueError)— a NaN raises none of those. So the NaN escaped as a valid-looking reconstruction → poisonedadapt_data→hilbert.py:275-284places mesh vertices fromadapt_datawith no NaN guard →scipy.spatial.Delaunay: "Points cannot contain NaN". That closes the loop from producer to failing stage.The fix
Reject a non-positive Schur complement (
np.linalg.LinAlgError), plus a finiteness assertion at thefnnlssolver boundary as a backstop.inversion_util.pyneeded no edit —LinAlgErrorsubclassesValueError, so its existing except-tuple already catches it.Likelihood evaluations are unchanged — verified, not assumed
The test is
schur > 0and nothing stricter. A relative-tolerance version was written first and discarded: it converted 7/300 finite reconstructions (max 0.26–0.46) into exceptions, which would have changed likelihoods.cleancounts identical pre/post: 115 / 82 / 71 / 71 / 120test_autoarray: 855 → 887 passed, same 16 pre-existing failures (env: py3.11 + missing optional deps) — +32 new tests, zero regressionsschur < 0already raised;schur == 0yields NaN with certainty so there is no finite result to preserve; any positive Schur complement passes through and returns a bitwise identical pivot.Limit worth stating
The repro is unit-level and deterministic (thread-independent) — stronger than the CI-only flake for regression purposes, and it is committed as tests. But I did not execute
source_pix_2end-to-end: this container has no autolens stack and runs Python 3.11 against a>=3.12requirement. Thesource_pix_2link is established by code reading, not by a run.Generated by Claude Code
Jammy2211 commentedon Aug 7, 2026
Closing — both phases merged
Phase 1 (already merged): PyAutoFit#1408 (TEST_MODE=2 bypass tolerates a single-eval
FitExceptionas a resample-to-reject sentinel) + autolens_workspace#311 (un-park the script, add it to smoke). Made the flake non-fatal.Phase 2 (merged today): PyAutoArray#436 →
efaf3041. CI green first run on both matrix legs (3.12 + 3.13). Fixes the producer, so the fit is correct rather than merely tolerated.Completion record:
PyAutoMind/complete/2026/08/interferometer-delaunay-flaky-fitexception.md.Two things to carry forward
The root cause named in this issue was wrong.
fnnls.py:134is not the producer — 599 executions across 600 constraint-binding draws, zero degenerate denominators. The real producer ischolesky_funcs.py→cholinsertlast, takingmath.sqrtof an unchecked Schur complement that, on a near-singular matrix, is zero to within rounding (±1.776e-15 = 8·eps) and lands on either side of zero by floating-point summation order — i.e. by BLAS thread count. That is the entire explanation for the CI-vs-local dependence.The first fix would have changed likelihood evaluations. A relative-tolerance guard converted 7/300 finite reconstructions (max 0.26–0.46) into exceptions. Discarded in favour of
schur > 0and nothing stricter, verified bitwise: 708/800 identical, 92 raise in both, 0 finite→raise, 0 numerically different.Residual limit
The repro is unit-level and deterministic (committed as 32 tests), but was never executed end-to-end through
source_pix_2— that link is established by code reading, not a run. Whether the workspace script still ever flakes is now only provable by CI over time; phase 1's tolerance means any residual occurrence would be non-fatal rather than a hard failure. Reopen if the smoke entry flakes again.Generated by Claude Code