Skip to content

Fix: canonical delaunay.py step 12 uses NNLS, not jnp.linalg.solve#59

Merged
Jammy2211 merged 1 commit into
mainfrom
feature/canonical-delaunay-nnls
May 10, 2026
Merged

Fix: canonical delaunay.py step 12 uses NNLS, not jnp.linalg.solve#59
Jammy2211 merged 1 commit into
mainfrom
feature/canonical-delaunay-nnls

Conversation

@Jammy2211
Copy link
Copy Markdown
Contributor

Summary

One-line fix to align the canonical Delaunay step-by-step profiler with what production AnalysisImaging actually does — NNLS (reconstruction_positive_only_from) instead of jnp.linalg.solve(F+H, D) for the source reconstruction.

Why

The two solvers happen to produce identical reconstructions at the canonical's prior-medians instance — ConstantSplit is well-conditioned enough that no source pixels go negative, so NNLS reduces to the linear solve. That's why this bug hid: the downstream log_evidence value is unchanged within rtol=1e-4 and the regression assertion still passed.

But the per-step "Regularized reconstruction" timing was off by an order of magnitude:

Solver RTX 2060 fp64 (per call)
Old: jnp.linalg.solve ~5 ms
New: NNLS ~47 ms

That under-reporting matters for any downstream optimisation work — anyone reading the canonical's bar chart would conclude the reconstruction step is essentially free, when in fact it's the third-largest contributor on consumer hardware.

Verification

Ran the canonical end-to-end on RTX 2060 (fp64) with the change applied:

  • figure_of_merit (log_evidence) = 29179.9490711974 (eager NumPy, unchanged)
  • log_evidence (inv matrices) = 29179.94907119931 (eager-vs-inversion match assertion: PASSED)
  • Eager regression assertion PASSED: log_evidence matches 29179.949071
  • Regression assertion PASSED: log_evidence matches 29179.949071
  • reconstruction_jit_steady_x10 = 0.4749 s → 47.5 ms per call (was ~5 ms)

Followup to

#58 (Delaunay profiling sweep), which already uses NNLS in z_projects/profiling/scripts/delaunay_profile.py and called this discrepancy out in its caveats. With this fix landed, the canonical and per-config profilers agree on what step 12 measures.

Test plan

  • EXPECTED_LOG_EVIDENCE_HST = 29179.9490711974 regression assertion passes (eager + inv-matrices + final)
  • No other behaviour change — only step 12's solver swap
  • Comment block above step 12 explains the rationale and confirms the rtol=1e-4 numerical equivalence

🤖 Generated with Claude Code

Production AnalysisImaging uses NNLS (reconstruction_positive_only_from)
for the source reconstruction; the canonical step-by-step profiler
inadvertently used the cheaper jnp.linalg.solve, under-reporting the
per-step "Regularized reconstruction" cost by roughly an order of
magnitude (5 ms vs 47 ms on a consumer RTX 2060).

The downstream log-evidence value is unchanged within rtol=1e-4 — at
prior medians the well-conditioned ConstantSplit problem yields no
negative source pixels, so NNLS reduces to the linear solve.

Verified end-to-end against EXPECTED_LOG_EVIDENCE_HST = 29179.9490711974.

Followup to #58 (Delaunay profiling sweep), which already uses NNLS
in the per-config delaunay_profile.py and called this discrepancy out
in its caveats.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@Jammy2211 Jammy2211 merged commit b0f4342 into main May 10, 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