Skip to content

Consider switch to graspologic-native for faster Leiden implementation #4441

Description

@maltekuehl

What kind of feature would you like to request?

Additional function parameters / changed functionality / changed defaults?

Please describe your wishes

Hi,

I was working on speeding up my own clustering pipelines for multiplexed protein data and discovered https://github.com/graspologic-org/graspologic-native which has a performant Leiden implementation in Rust. It is also MIT-licensed and could thus avoid problems with igraph. While igraph does perform well, I would propose to replace leidenalg with a more performant default that most users would not need to switch and that is useful for pharma, biotech, etc.

Small benchmark I ran:

pbmc3k (2,638 cells) synthetic (40,000 cells)
time modularity ARI time modularity ARI
sc.tl.leiden(flavor="leidenalg") (current default) 476 ms 0.6558 0.97 58.3 s 0.7892 0.96
sc.tl.leiden(flavor="igraph", n_iterations=2) 32 ms 0.6558 – 598 ms 0.7889 –
graspologic-native leiden_csr(…, iterations=2) 36 ms 0.6556 0.98 576 ms 0.7889 0.96

Same neighbors graph from pp.neighbors, resolution 1, median of 5–7 seeds, on my M3 Max. ARI was calculated against igraph (igraph vs itself across seeds: 0.96–0.98). The 40k graph comes from sc.datasets.blobs. With graspologic-native, there is also the possibility of zero copy CSR input which could take adata.obsp["connectivities"] directly via leiden_csr.

Versions: scanpy 1.12.4, python-igraph 1.0.0, leidenalg 0.12.0, graspologic-native 1.3.1, Python 3.12.

Of course, this investigation could be widened before a PR but before doing so, would be great to know if you would be open to this switch.

Best,
Malte

Activity

  1. removed
    Triage 🩺This issue needs to be triaged by a maintainer
    on Nov 6, 2026
  2. ilan-gold commented on Nov 6, 2026

    @ilan-gold
    Contributor

    We are going to switch to igraph for scanpy 2.0 as the default and I think we even warn right now on using leidenalg for large-ish datasets. We can't change the default until 2.0 and graspologic looks to have the same speed as igraph. I think it would make sense to offer it, though, if it were to take a random seed and therefore be reproducible. There's definitely a need for that, but if not, I don't know of a reason not to just point people to #4170, which is also very very fast.

  3. flying-sheep commented on Nov 10, 2026

    @flying-sheep
    Member

    see also #4110

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions