Guard CBE bond expansion against zero-content bonds#464
Open
lkdvos wants to merge 2 commits into
Open
Conversation
`OptimalExpand`/`RandExpand` `changebond!` (and the infinite/multiline `OptimalExpand` loops) computed `svd_trunc!(normalize!(g2))` on the two-site update projected onto the state's orthogonal complement. When a bond has no expansion content — e.g. a product-state region, or a symmetry sector the Hamiltonian does not couple into yet — `g2` is exactly zero, and `normalize!` divides by a zero norm, producing NaNs that crash the SVD (`ArgumentError: invalid argument #4 to LAPACK call`). This surfaced as a crash in single-site CBE-TDVP on a charged fermionic state, where interior bonds carry a single parity sector and the projected update there is structurally zero. Guard the finite `changebond!` methods to skip a bond with no expansion content (leaving the state untouched), and normalize only when nonzero in the infinite/multiline loops. `SketchedExpand` already handled this via its empty-complement guard and QR-based orthogonalization. Add a graded regression test in test/algorithms/changebonds.jl. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
... and 8 files with indirect coverage changes 🚀 New features to boost your workflow:
|
Address review: sparser comments, and normalize the projected update with an explicit `scale!(g2, inv(nrm))` reusing the norm already computed for the zero-content guard instead of a second pass through `normalize!`. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
lkdvos
marked this pull request as ready for review
July 16, 2026 20:01
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.
Problem
OptimalExpandandRandExpand(changebond!, and the infinite/multilineOptimalExpandloops) form the two-site update projected onto the state's orthogonal complement and then callsvd_trunc!(normalize!(g2)). When a bond has no expansion content — a product-state region, or a symmetry sector the Hamiltonian does not couple into yet —g2is exactly zero, sonormalize!divides by a zero norm and manufacturesNaNs. The subsequent SVD then throws:This is easy to hit with CBE on a low-entanglement or charged symmetric state. It surfaced in single-site CBE-TDVP (
TDVP(; alg_expand = OptimalExpand(...))) on a charged fermionic (fℤ₂-graded) single-particle state: interior bonds there carry a single parity sector, so the projected update on them is structurally zero. (A merely small-but-nonzerog2, e.g. from a random dense state, does not trigger it — the norm must be exactly0, which is why only structured/graded states hit it.)Fix
Guard the zero-content case: when the projected update has (near-)zero norm there is nothing to expand at that bond, so skip it and leave the state untouched.
changebond!(OptimalExpand/RandExpand, both sweep directions): early-return whennorm(g2) ≤ eps^(3/4).OptimalExpandloops: normalize only when the norm is above threshold.SketchedExpandalready handled this — it has an upfront empty-complement guard and orthogonalizes with QR/right_orth!rather thannormalize!-then-SVD — so it is unchanged.The guard only adds an early return on an exactly-zero-norm condition, so it cannot affect the normal (nonzero) expansion path.
Testing
test/algorithms/changebonds.jl→ "CBE zero-content bonds (graded)": a charged single-particle fℤ₂ state (interior bonds carry a single sector ⇒ structurally-zero expansion content) run throughOptimalExpandandRandExpand; both must complete without crashing and preserve the state. This reproduces the crash on the unpatched code.test/algorithms/changebonds.jlsuite is green (54/54).OptimalExpandCBE-TDVP, which previously crashed on the charged fermionic state, now runs and matchesTDVP2/RandExpand, while a full-rank sanity case confirms the guard does not suppress genuinely-needed expansion.🤖 Generated with Claude Code