Skip to content

Handle conjugate pairs in either order (Accelerate, #68) - #75

Merged
Marius1311 merged 1 commit into
mainfrom
fix/conj-pair-order
Nov 13, 2026
Merged

Marius1311 merged 1 commit into
mainfrom
fix/conj-pair-order

Conversation

@Marius1311

Copy link
Copy Markdown
Collaborator

Fixes #68. Replaces #62. Part of #70.

Cause

On macOS with numpy/scipy from PyPI, LAPACK comes from Apple Accelerate. There, the Brandts sort can leave a 2x2 block whose conjugate pair comes out with the negative imaginary part first. For P_2 (LM, all 12 sorted) the pairs come out [+, +, −]; with OpenBLAS they are always [+, +, +]. At m = 9 the last eigenvalue is then −0.432 − 0.390i. _check_conj_split only looked at imag > EPS, so it missed the cut, and GPCCA went on with a basis that cuts a 2x2 block: subspace angle 0.70 rad.

The diagnostic run in #73 showed this: on Accelerate, schur() and every Brandts swap have residuals around 1e-15; only the pair order differs.

Change

  • _check_conj_split checks abs(imag). On Accelerate this alone fixes the four split tests: run.
  • sorted_brandts_schur reads eigenvalues off the Schur blocks, positive imaginary part first (as LAPACK orders them), instead of rsf2csf. This fixes the remaining two (test_P_2_LM/LR[brandts], which compare top_eigenvalues), with no test-side normalisation.
  • CI: macOS job on PyPI wheels (hatch-test.py3.12-stable (macOS, Accelerate)), so the Accelerate path stays covered.

Linux: no change in results (85 passed, 44 skipped locally). On Linux, sorted eigenvalues already came positive-first: 1044 Brandts and 530 SLEPc pairs checked.

🤖 Generated with Claude Code

@codecov

codecov Bot commented Nov 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

_check_conj_split only flagged a cut when the eigenvalue at the boundary had
a positive imaginary part. With Apple Accelerate, the Brandts sort can leave
a 2x2 block whose pair comes out negative-first, so a cut went unnoticed and
GPCCA used a non-invariant subspace. Check abs(imag), and read eigenvalues off
the Schur blocks with the positive imaginary part first instead of rsf2csf.
Test macOS on PyPI wheels (Accelerate).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Marius1311
Marius1311 merged commit 5364acb into main Nov 13, 2026
10 checks passed
@Marius1311
Marius1311 deleted the fix/conj-pair-order branch November 13, 2026 13:59
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.

brandts returns a non-invariant subspace on macOS arm64

1 participant