Skip to content

fix: schmidt_rank for unequal subsystem dimensions - #1981

Open
SANJANAKUMARI83 wants to merge 4 commits into
vprusso:masterfrom
SANJANAKUMARI83:fix/1980-schmidt-rank-unequal-dims
Open

SANJANAKUMARI83 wants to merge 4 commits into
vprusso:masterfrom
SANJANAKUMARI83:fix/1980-schmidt-rank-unequal-dims

Conversation

@SANJANAKUMARI83

Copy link
Copy Markdown

Description

Closes #1980

schmidt_rank reshaped state vectors with np.reshape(rho, dim[::-1]). The reversed shape is what MATLAB's column-major reshape needs, but NumPy is row-major, so whenever the two subsystems have different dimensions the coefficient matrix was scrambled. For square dimensions it only produced a transpose, which is why the existing tests passed. Since the operator Schmidt rank goes through the same code, is_separable was also reporting some product states on unequal dimensions as entangled.

While testing this I also noticed the pure-state branch of is_separable reports the operator Schmidt rank in its message (e.g. "Schmidt rank 4" for a Bell state, which is the square of the actual Schmidt rank). It now takes the state vector from the rank-1 density matrix and reports its Schmidt rank. The separable / entangled verdict in that branch doesn't change.

Changes

  • schmidt_rank: reshape with np.reshape(rho, dim) so the coefficient matrix matches np.kron ordering.
  • is_separable: in the pure-state branch, compute the Schmidt rank of the state vector (top eigenvector) instead of the density matrix.
  • Tests for schmidt_rank on unequal dimensions (product and entangled states, [2, 3], [3, 2], integer dim) and for the operator Schmidt rank on [2, 3].
  • Tests for the is_separable pure-state message on 2x2, 3x3 and 2x3, including a 2x3 product state that was previously reported as entangled.

The new tests fail on master (10 of 13) and pass with this change. I also checked schmidt_rank against the rank of v.reshape(dA, dB) (and of the realigned matrix for the operator version) on 80 random pure states over (2,2), (2,3), (3,2), (2,4), (4,2), (3,3) and (3,5): 40 disagreed on master, all with unequal dimensions, and 0 disagree with this change.

sk_norm also calls schmidt_rank on vectors, so it benefits from the fix for unequal dimensions too.

Checklist

  • Use ruff for errors related to code style and formatting.
  • Verify all previous and newly added unit tests pass in pytest. (Ran the CI command, pytest -m "not slow": 3767 passed.)
  • Check the documentation build does not lead to any failures. (I didn't run the docs build locally. No docstrings or docs pages changed, so I'm relying on the docs preview check here.)

@codecov

codecov Bot commented Oct 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

This branch has not been deployed

No deployments
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.

schmidt_rank returns wrong values for unequal subsystem dimensions

1 participant