BUG: Make _max_abs_diff NaN-safe to prevent false convergence#96
Merged
Conversation
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a regression in the solver’s convergence criterion by making _max_abs_diff NaN-safe again, preventing false convergence when coefficient updates produce non-finite values (e.g., Inf - Inf = NaN). This restores the pre-#95 behavior where divergence propagates through the error metric and cannot be misreported as converged.
Changes:
- Update
_max_abs_diffto accumulate withmax(err, abs(x[i] - y[i])), ensuringNaNpropagates like the priormaximum(abs, x - y)approach. - Add unit tests covering
NaN/Infpropagation behavior in_max_abs_diff. - Add an end-to-end test ensuring
operator_iteration!does not declare convergence for an operator that drives coefficients toNaN.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/cdp.jl |
Updates _max_abs_diff to propagate NaN during convergence checking, preventing false convergence. |
test/test_workspace.jl |
Adds tests for _max_abs_diff non-finite propagation and an end-to-end divergence-to-NaN convergence check. |
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
Fix a regression introduced in #95:
_max_abs_diffaccumulated viad > err && (err = d), and sinceNaN > errisfalse, an iteration that diverged to non-finite coefficients (Inf - Inf = NaN) producederr = 0.0and was reported asconverged = true. The previous criterionmaximum(abs, C - C_old)propagatedNaN, so divergence correctly failed with amax_iterwarning.The accumulation now uses
max(err, abs(x[i] - y[i])), which propagatesNaNexactly likemaximum, restoring the pre-#95 semantics (still allocation-free).Discovered while investigating a VFI divergence: with the buggy criterion the solver returned
converged = trueon coefficients that were allNaN.Verification
_max_abs_diff(NaN/Infpropagation) and an end-to-end test thatoperator_iteration!does not declare convergence for an operator diverging toNaN.🤖 Generated with Claude Code (Claude Fable 5)