fix(mps): surface non-finite SRC apply state as ApplyError - #484
Merged
Conversation
The SRC apply path returned a poisoned MPS as a success when a contraction overflowed to inf or produced NaN downstream. Every growth round now scans its sketch panel for non-finite elements, and every assembled site tensor is scanned before the state is returned, so apply_with_method returns Err(ApplyError::NonFinite) instead of a poisoned success, in both adaptive and fixed mode. The detector is elementwise rather than a norm fold: a norm conflates genuine poison with a finite state whose Frobenius norm merely overflows the scalar's real type, and the latter must not be rejected. The scans run before the optional canonicalize + truncate finishing pass, which stays the truncation machinery's concern. apply_with_method now returns Result; apply stays infallible because the current default method has no failure path. The block-sparse SRC arm keeps its dense-only panic (a programmer error, not a runtime condition). Closes #481
There was a problem hiding this comment.
Pull request overview
This PR makes the successive randomized compression (SRC) MPO→MPS apply path fail fast when non-finite values (NaN/inf) reach defined result boundaries, returning a new ApplyError::NonFinite instead of silently producing a poisoned Mps. It updates apply_with_method to be fallible (Result) while keeping apply infallible since the default method remains non-failing.
Changes:
- Introduces
ApplyErrorand threadsResult<_, ApplyError>through the SRC dispatch andapply_with_method. - Adds shared boundary finiteness checking (
check_finite) and uses it within SRC per growth round and for assembled sites. - Updates tests and benches to unwrap “finite-input” apply calls via helper wrappers, and adds SRC-specific error-path tests.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| crates/ariadnetor-mps/src/types.rs | Adds public ApplyError with NonFinite diagnostics and documents error scope/semantics. |
| crates/ariadnetor-mps/src/lib.rs | Re-exports ApplyError from the crate root. |
| crates/ariadnetor-mps/src/dispatch.rs | Makes apply_with_method return Result and wires SRC dispatch to return ApplyError. |
| crates/ariadnetor-mps/src/apply/mod.rs | Adds shared check_finite boundary predicate for dense tensors. |
| crates/ariadnetor-mps/src/apply/successive_randomized.rs | Converts SRC dense apply to Result and adds per-round + assembled-site non-finite scans. |
| crates/ariadnetor-mps/tests/mps/helpers.rs | Adds apply_ok helper to unwrap apply_with_method for finite-input tests. |
| crates/ariadnetor-mps/tests/mps/apply.rs | Switches tests to apply_ok where inputs are finite; keeps default-vs-explicit contract as value equality. |
| crates/ariadnetor-mps/tests/mps/apply_variational.rs | Switches finite-input tests to apply_ok. |
| crates/ariadnetor-mps/tests/mps/apply_variational_block_sparse.rs | Switches finite-input tests to apply_ok. |
| crates/ariadnetor-mps/tests/mps/apply_block_sparse.rs | Switches finite-input tests to apply_ok. |
| crates/ariadnetor-mps/tests/mps/apply_successive_randomized.rs | Adds SRC non-finite surfacing tests; keeps validation panic tests. |
| crates/ariadnetor-mps/tests/authority.rs | Adds local apply_ok helper to keep dispatch-count tests focused while unwrapping fallible apply. |
| crates/ariadnetor-algorithms/benches/mpo_mps_apply.rs | Adds apply_ok helper and updates benches to unwrap fallible apply on finite inputs. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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
The SRC apply path (
ApplyMethod::SuccessiveRandomized) returned a compressed MPS as a success even when the computation had been poisoned by non-finite values — an overflowed contraction producinginf, orinf - inf/0 * infproducing NaN downstream. This PR surfaces that state as an error at the result boundary: every growth round scans its sketch panel for non-finite elements, and every assembled site tensor is scanned before the state is returned, soapply_with_methodreturnsErr(ApplyError::NonFinite)instead of a poisoned success, in both adaptive and fixed mode. Closes #481.Changes
crates/ariadnetor-mps/src/types.rs— new publicApplyErrorenum (thiserror,#[non_exhaustive]) with aNonFinite { site, norm }variant carrying lossyf64diagnostics;siteis documented as the detection locus, not the poison's origin.crates/ariadnetor-mps/src/apply/mod.rs— sharedcheck_finiteboundary predicate: an elementwise scan of each element's real and imaginary parts, rather than a norm fold, so a finite state whose Frobenius norm merely overflows the scalar's real type is not rejected.crates/ariadnetor-mps/src/apply/successive_randomized.rs—apply_successive_randomized_densereturnsResult; per-round sketch-panel scans (fail-fast, both modes), a single assembled-sites scan before the state is built, and the same check on then == 1path.crates/ariadnetor-mps/src/dispatch.rs— the SRC kernel-dispatch method andapply_with_methodreturnResult<_, ApplyError>; the other methods' arms wrap their result inOk; the block-sparse SRC arm keeps its dense-only panic.applystays infallible (the current default method has no failure path) with its doc contract made precise.Impact
Compile-breaking for
apply_with_methodcallers; all workspace consumers (the mps integration tests,crates/ariadnetor-mps/tests/authority.rs, and the algorithmsmpo_mps_applybench) are updated viaapply_okunwrap helpers. The other apply methods are behaviorally unchanged and still return a poisoned state asOk, as documented on the error variant.Test plan
infinjected into an MPO site (fixed mode), and a NaN single-site product (n == 1path) — each asserting theNonFinitediagnostics, including detection at the sweep's first processed site.Ok-path regression (now unwrapped).cargo make gate(fmt-check, clippy-D warningsover all targets, workspace tests including doctests): clean;cargo test -p ariadnetor-mps: 264 passed.Notes
canonicalize+truncatefinishing pass; non-finite values arising only inside that pass are the truncation machinery's concern.infacross rounds, and an overflowedR^-1can collapse the error estimate to zero — and degrades toward premature convergence with a finite result; tracked in SRC adaptive stopping rule degrades toward false convergence at extreme scale #483.@coderabbitai ignore