You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 5e969c9
Browse filesBrowse the repository at this point in the historyBrowse files
authored
fix: š validate chi_out, cutoff, and boundary rank in apply()/compress() (#38)
* fix: š validate chi_out, cutoff, and boundary rank in apply()/compress()
Both functions previously let malformed arguments reach deep into the sweep before failing, if they failed at all:
- chi_out=0: no error, returns a network with every bond dimension 0.
- chi_out=-3: raised, but a generic NumPy "negative dimensions are not allowed" ValueError that never names chi_out. A non-integer chi_out (e.g. 2.5) similarly raised an unnamed, opaque TypeError.
- cutoff=2.0: no error, every bond silently collapses to rank 1.
- cutoff=-1.0: no error, silently treated as "no truncation".
- infer_kind only inspects the first site tensor, so a train with inconsistent boundary ranks (which is valid-looking at the first site but not at the last) or a periodic-boundary train whose rank happens to match a valid one (e.g. a periodic MPS, indistinguishable from an open MPO by first-site rank alone) was accepted and only failed later, deep in the sweep.
Add _validation.py with validate_chi_out, validate_cutoff, and validate_boundary_rank, and call them at the top of apply() and compress(), before any array allocation or device transfer, so all three now raise a targeted ValueError immediately.
Update tests/test_package.py:
- test_compress_unsupported_type now uses a rank-1 array instead of rank-4, since rank-4 input is now caught by validate_boundary_rank with a more specific error rather than the generic TypeError this test checks for.
- Add coverage for chi_out, cutoff, and boundary-rank validation.
Known limitation: a periodic-boundary train of exactly two sites is not caught. Its boundary tensors have no interior tensor to compare against, and their rank alone (e.g. 3 for a periodic MPS) can be identical to a valid two-site MPO's, making it a genuine ambiguity rather than a missed check.
Closes#15
* fix: improve type checking in _validation.py
Apply batched suggestions from code review:
- validate_chi_out now rejects `bool`
- validate_cutoff now ensures cutoff is real
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Mats Horsdal <38429082+mhorsdal@users.noreply.github.com>
* fix: š raise TypeError for a non-integer chi_out
Assisted-by: pi:claude-sonnet-5.5
---------
Signed-off-by: Mats Horsdal <38429082+mhorsdal@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Roberto Di Remigio EikƄs <robertodr@users.noreply.github.com>
Co-authored-by: Panadestein <rpana92@gmail.com>
0 commit comments