Skip to content

fix(mps): surface non-finite SRC apply state as ApplyError - #484

Merged
ultimatile merged 1 commit into
mainfrom
fix/481-src-nonfinite-error
Jul 17, 2026
Merged

fix(mps): surface non-finite SRC apply state as ApplyError#484
ultimatile merged 1 commit into
mainfrom
fix/481-src-nonfinite-error

Conversation

@ultimatile

Copy link
Copy Markdown
Owner

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 producing inf, or inf - inf / 0 * inf producing 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, so apply_with_method returns Err(ApplyError::NonFinite) instead of a poisoned success, in both adaptive and fixed mode. Closes #481.

Changes

  • crates/ariadnetor-mps/src/types.rs — new public ApplyError enum (thiserror, #[non_exhaustive]) with a NonFinite { site, norm } variant carrying lossy f64 diagnostics; site is documented as the detection locus, not the poison's origin.
  • crates/ariadnetor-mps/src/apply/mod.rs — shared check_finite boundary 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.rsapply_successive_randomized_dense returns Result; per-round sketch-panel scans (fail-fast, both modes), a single assembled-sites scan before the state is built, and the same check on the n == 1 path.
  • crates/ariadnetor-mps/src/dispatch.rs — the SRC kernel-dispatch method and apply_with_method return Result<_, ApplyError>; the other methods' arms wrap their result in Ok; the block-sparse SRC arm keeps its dense-only panic. apply stays infallible (the current default method has no failure path) with its doc contract made precise.

Impact

Compile-breaking for apply_with_method callers; all workspace consumers (the mps integration tests, crates/ariadnetor-mps/tests/authority.rs, and the algorithms mpo_mps_apply bench) are updated via apply_ok unwrap helpers. The other apply methods are behaviorally unchanged and still return a poisoned state as Ok, as documented on the error variant.

Test plan

  • New error-path tests: NaN injected into an MPS site (adaptive mode), inf injected into an MPO site (fixed mode), and a NaN single-site product (n == 1 path) — each asserting the NonFinite diagnostics, including detection at the sweep's first processed site.
  • Existing finite-input apply tests cover the Ok-path regression (now unwrapped).
  • The assembled-sites scan has no deterministic trigger with finite panels: the gap between a finite sketch panel and a non-finite assembled tensor depends on the random Gaussian sketch, so a triggering fixture would encode magnitudes tied to the RNG stream. Recorded as a deliberate omission in the test file.
  • cargo make gate (fmt-check, clippy -D warnings over all targets, workspace tests including doctests): clean; cargo test -p ariadnetor-mps: 264 passed.

Notes

  • The scans run before the optional canonicalize + truncate finishing pass; non-finite values arising only inside that pass are the truncation machinery's concern.
  • The adaptive stopping rule itself is not robust at numerical extremes — the running sketch norm can saturate to inf across rounds, and an overflowed R^-1 can 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.
  • Per-method apply entry points with method-specific error types were considered and deferred: no non-test consumer selects an apply method statically today.

@coderabbitai ignore

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

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ApplyError and threads Result<_, ApplyError> through the SRC dispatch and apply_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.

Comment thread crates/ariadnetor-mps/src/types.rs
@ultimatile
ultimatile merged commit fdb7383 into main Jul 17, 2026
2 checks passed
@ultimatile
ultimatile deleted the fix/481-src-nonfinite-error branch July 17, 2026 20:16
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.

Surface non-finite sketch state in SRC apply as an error

2 participants