Skip to content

Guard CBE bond expansion against zero-content bonds#464

Open
lkdvos wants to merge 2 commits into
mainfrom
ld-cbe-zero-guard
Open

Guard CBE bond expansion against zero-content bonds#464
lkdvos wants to merge 2 commits into
mainfrom
ld-cbe-zero-guard

Conversation

@lkdvos

@lkdvos lkdvos commented Jul 16, 2026

Copy link
Copy Markdown
Member

Problem

OptimalExpand and RandExpand (changebond!, and the infinite/multiline OptimalExpand loops) form the two-site update projected onto the state's orthogonal complement and then call svd_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 — g2 is exactly zero, so normalize! divides by a zero norm and manufactures NaNs. The subsequent SVD then throws:

ArgumentError: invalid argument #4 to LAPACK call

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-nonzero g2, e.g. from a random dense state, does not trigger it — the norm must be exactly 0, 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.

  • Finite changebond! (OptimalExpand/RandExpand, both sweep directions): early-return when norm(g2) ≤ eps^(3/4).
  • Infinite / multiline OptimalExpand loops: normalize only when the norm is above threshold.

SketchedExpand already handled this — it has an upfront empty-complement guard and orthogonalizes with QR/right_orth! rather than normalize!-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

  • New regression test 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 through OptimalExpand and RandExpand; both must complete without crashing and preserve the state. This reproduces the crash on the unpatched code.
  • Full test/algorithms/changebonds.jl suite is green (54/54).
  • Verified end-to-end that OptimalExpand CBE-TDVP, which previously crashed on the charged fermionic state, now runs and matches TDVP2/RandExpand, while a full-rank sanity case confirms the guard does not suppress genuinely-needed expansion.

🤖 Generated with Claude Code

`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

codecov Bot commented Jul 16, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 83.33333% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/algorithms/changebonds/randexpand.jl 50.00% 3 Missing ⚠️
Files with missing lines Coverage Δ
src/algorithms/changebonds/optimalexpand.jl 98.85% <100.00%> (+0.11%) ⬆️
src/algorithms/changebonds/randexpand.jl 63.63% <50.00%> (-0.75%) ⬇️

... and 8 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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
lkdvos marked this pull request as ready for review July 16, 2026 20:01
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