Skip to content

use rustworkx instead of networkx except the plotting - #1252

Open
selmanozleyen wants to merge 3 commits into
mainfrom
refactor/rustworkx-instead-of-networkx
Open

use rustworkx instead of networkx except the plotting#1252
selmanozleyen wants to merge 3 commits into
mainfrom
refactor/rustworkx-instead-of-networkx

Conversation

@selmanozleyen

Copy link
Copy Markdown
Member

This is part of my larger goal to replace process based parallelization. I found rustworkx easy to install and fast. That's why I made a PR long ago.

This pull request migrates the group centrality computation in centrality_scores from NetworkX to the high-performance rustworkx library, and introduces a custom, Numba-accelerated clustering coefficient kernel. It also ensures that the results remain numerically consistent with the previous implementation by adding parity tests. The main changes are as follows:

Dependency and Documentation Updates:

  • Added rustworkx>=0.18.0 as a dependency in pyproject.toml and included a corresponding citation in references.bib. [1] [2]
  • Updated docstrings to reference rustworkx for group centrality measures and clarified citations for both rustworkx and networkx. [1] [2]

Core Implementation Changes:

  • Replaced NetworkX-based group centrality calculations in centrality_scores with rustworkx equivalents, and replaced the clustering coefficient computation with a custom, parallelized Numba kernel for improved performance. [1] [2]
  • Added a new _build_graph utility to convert connectivity matrices into both rustworkx.PyGraph and a CSR matrix for use in centrality and clustering calculations.

Testing:

  • Introduced a test to verify numerical parity between the new rustworkx/Numba implementation and the original NetworkX-based results for all group centrality measures.

@codecov

codecov Bot commented Aug 4, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 50.00000% with 23 lines in your changes missing coverage. Please review.
✅ Project coverage is 77.11%. Comparing base (ca07e64) to head (74f6c34).

Files with missing lines Patch % Lines
src/squidpy/gr/_nhood.py 50.00% 23 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1252      +/-   ##
==========================================
- Coverage   77.24%   77.11%   -0.13%     
==========================================
  Files          63       63              
  Lines        9378     9418      +40     
  Branches     1579     1585       +6     
==========================================
+ Hits         7244     7263      +19     
- Misses       1532     1554      +22     
+ Partials      602      601       -1     
Files with missing lines Coverage Δ
src/squidpy/_docs.py 94.80% <ø> (ø)
src/squidpy/gr/_nhood.py 75.00% <50.00%> (-6.71%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

1 participant