-
Notifications
You must be signed in to change notification settings - Fork 5
bug(treetn): square_linsolve fails for standard MPO operators with distinct input/output indices #349
Description
Description
square_linsolve (the high-level linsolve entry point in tensor4all-treetn) fails with an index set mismatch error when the operator (MPO) has distinct input and output site indices — which is the standard MPO convention.
The function internally creates SquareLinsolveUpdater::new() without index mappings. When the operator's output indices have different IDs from the state's site indices, the local contraction produces tensors that cannot be matched, causing a "Index set mismatch: tensors must have the same indices" error during GMRES.
Steps to Reproduce
Create an identity MPO with distinct site indices s (output) and sP (input), a RHS vector, and attempt to solve:
let s = Index::<DynId>::new_dyn(2); // output index
let sp = Index::<DynId>::new_dyn(2); // input index (different ID)
// ... build operator TreeTN with [s, sp], rhs with [sp], init with [s]
square_linsolve(&operator, &rhs, &init, center, options)?;
// → Error: "Index set mismatch"Expected Behavior
square_linsolve handles standard MPOs with distinct input/output site indices.
Actual Behavior
Fails with index mismatch. Only the lower-level SquareLinsolveUpdater::with_index_mappings works, but requires ~20 lines of boilerplate (manual index mappings, canonicalization, sweep plan, loop).
Suggested Fix
Either:
- Add an
index_mappingsparameter tosquare_linsolve - Create a new convenience function
square_linsolve_with_mappings(operator, input_mapping, output_mapping, rhs, init, center, options) - Document clearly that
square_linsolveonly works with shared-index operators and provide a working example using the lower-level API
Related: #148 (linsolve enhancements)
Found by automated feature testing (test-feature-20260327-treetn).