Skip to content

bug(treetn): square_linsolve fails for standard MPO operators with distinct input/output indices #349

@shinaoka

Description

@shinaoka

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:

  1. Add an index_mappings parameter to square_linsolve
  2. Create a new convenience function square_linsolve_with_mappings(operator, input_mapping, output_mapping, rhs, init, center, options)
  3. Document clearly that square_linsolve only 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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions