fix: real-valued high BC anisotropy on NumPy >= 2 - #133
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
NumPy >= 2 returns complex128 eigenvalues from np.linalg.eigvals even for real symmetric covariance matrices. This leaked complex scalars into the metrics, crashing ruamel.yaml key figure dumps with a RepresenterError and yielding inf+nanj instead of inf for degenerate covariances. Use eigvalsh (always real for symmetric input) and clip numerical-noise negative eigenvalues; additionally make _make_yaml_compatible collapse zero-imaginary complex scalars to float as a fallback.
cbueth
force-pushed
the
fix/numpy-complex-anisotropy
branch
from
August 24, 2026 17:01
5d8039f to
132bfa7
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Scheduled CI on main failed in the Partitioning and Metrics jobs: raised
RepresenterErroron values like(5.73+0j), and the anisotropy special-case tests gotinf+nanjinstead ofinf.There was a upstream change for NumPy >= 2, where
np.linalg.eigvalsreturnscomplex128eigenvalues even for real symmetric covariance matrices. This leaked complex scalars into the metrics and key figures.This PR switches the calculation to
np.linalg.eigvalsh(always real for symmetric input), clips numerical-noise negative eigenvalues, and returns a plain float. As a fallback,_make_yaml_compatiblenow collapses zero-imaginary complex scalars to float, so YAML dumps can't crash on a stray complex value again.Type of Change
How Has This Been Tested?
Test configuration:
pytest "tests/metrics/test_metric.py::TestMetric::test_saving_and_loading" -k "ResidentialPart or BetweennessPart"pytest tests/partitioning/test_base.py -k "save_key_figures and Adliswil"Checklist