Fix: canonical delaunay.py step 12 uses NNLS, not jnp.linalg.solve#59
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 ofjnp.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_evidencevalue is unchanged withinrtol=1e-4and the regression assertion still passed.But the per-step "Regularized reconstruction" timing was off by an order of magnitude:
jnp.linalg.solveThat 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.949071Regression assertion PASSED: log_evidence matches 29179.949071reconstruction_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.pyand 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.9490711974regression assertion passes (eager + inv-matrices + final)🤖 Generated with Claude Code