leidenalg 0.10.2


pip install leidenalg

  Latest version

Released: Jan 22, 2024

Project Links

Meta
Author: V.A. Traag
Requires Python: >=3.7

Classifiers

Development Status
  • 4 - Beta

Environment
  • Console

Intended Audience
  • End Users/Desktop
  • Developers
  • Science/Research

License
  • OSI Approved :: GNU General Public License v3 or later (GPLv3+)

Operating System
  • MacOS :: MacOS X
  • Microsoft :: Windows
  • POSIX

Programming Language
  • Python
  • C++

Topic
  • Scientific/Engineering :: Mathematics
  • Scientific/Engineering :: Information Analysis
  • Sociology

This package implements the Leiden algorithm in C++ and exposes it to python. It relies on (python-)igraph for it to function. Besides the relative flexibility of the implementation, it also scales well, and can be run on graphs of millions of nodes (as long as they can fit in memory). The core function is find_partition which finds the optimal partition using the Leiden algorithm [1], which is an extension of the Louvain algorithm [2] for a number of different methods. The methods currently implemented are (1) modularity [3], (2) Reichardt and Bornholdt’s model using the configuration null model and the Erdös-Rényi null model [4], (3) the Constant Potts model (CPM) [5], (4) Significance [6], and finally (5) Surprise [7]. In addition, it supports multiplex partition optimisation allowing community detection on for example negative links [8] or multiple time slices [9]. There is the possibility of only partially optimising a partition, so that some community assignments remain fixed [10]. It also provides some support for community detection on bipartite graphs. See the documentation for more information.

Leiden documentation status Leiden build status (GitHub Actions) DOI Anaconda (conda-forge)

Installation

In short: pip install leidenalg. All major platforms are supported on Python>=3.6, earlier versions of Python are no longer supported. Alternatively, you can install from Anaconda (channel conda-forge).

For Unix like systems it is possible to install from source. For Windows this is more complicated, and you are recommended to use the binary wheels. This Python interface depends on the C++ package libleidenalg which in turn depends on igraph. You will need to build these packages yourself before you are able to build this Python interface.

Make sure you have all necessary tools for compilation. In Ubuntu this can be installed using sudo apt-get install build-essential autoconf automake flex bison, please refer to the documentation for your specific system. Make sure that not only gcc is installed, but also g++, as the leidenalg package is programmed in C++. Note that there are build scripts included in the scripts/ directory. These are also used to build the binary wheels.

  1. Compile (and install) the C core of igraph (version >= 0.10). You can use the file build_igraph.sh (on Unix-like systems) or build_igraph.bat (on Windows) in the scripts/ directory to do this. For more details, see https://igraph.org/c/doc/igraph-Installation.html.

  2. Compile (and install) the C core of libleidenalg (version >= 0.10). You can use the file build_libleidenalg.sh (on Unix-like systems) or build_libleidenalg.bat (on Windows) in the scripts/ directory to do this. For more details, see https://github.com/vtraag/libleidenalg.

  3. Build the Python interface using python setup.py build and python setup.py install, or use pip install .

You can check if all went well by running a variety of tests using python -m unittest.

Troubleshooting

In case of any problems, best to start over with a clean environment. Make sure you remove the igraph and leidenalg package completely. Then, do a complete reinstall starting from pip install leidenalg. In case you installed from source, and built the C libraries of igraph and libleidenalg yourself, remove them completely and rebuild and reinstall them.

Usage

This is the Python interface for the C++ package libleidenalg. There are no plans at the moment for developing an R interface to the package. However, there have been various efforts to port the package to R. These typically do not offer all available functionality or have some other limitations, but nonetheless may be very useful. The available ports are:

Please refer to the documentation for more details on function calls and parameters.

This implementation is made for flexibility, but igraph nowadays also includes an implementation of the Leiden algorithm internally. That implementation is less flexible: the implementation only works on undirected graphs, and only CPM and modularity are supported. It is likely to be substantially faster though.

Just to get you started, below the essential parts. To start, make sure to import the packages:

>>> import leidenalg
>>> import igraph as ig

We’ll create a random graph for testing purposes:

>>> G = ig.Graph.Erdos_Renyi(100, 0.1);

For simply finding a partition use:

>>> part = leidenalg.find_partition(G, leidenalg.ModularityVertexPartition);

Contribute

Source code: https://github.com/vtraag/leidenalg

Issue tracking: https://github.com/vtraag/leidenalg/issues

See the documentation on Implementation for more details on how to contribute new methods.

References

Please cite the references appropriately in case they are used.

Licence

Copyright (C) 2020 V.A. Traag

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Wheel compatibility matrix

Platform CPython 3.7 CPython >=3.8 (abi3) PyPy 3.7 (pp73) PyPy 3.8 (pp73) PyPy 3.9 (pp73) PyPy 3.10 (pp73)
macosx_10_9_x86_64
macosx_11_0_arm64
manylinux2014_aarch64
manylinux2014_i686
manylinux2014_x86_64
manylinux_2_17_aarch64
manylinux_2_17_i686
manylinux_2_17_x86_64
musllinux_1_1_i686
musllinux_1_1_x86_64
win32
win_amd64

Files in release

leidenalg-0.10.2-cp37-cp37m-macosx_10_9_x86_64.whl (1.6MiB)
leidenalg-0.10.2-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.8MiB)
leidenalg-0.10.2-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl (2.0MiB)
leidenalg-0.10.2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.9MiB)
leidenalg-0.10.2-cp37-cp37m-musllinux_1_1_i686.whl (2.5MiB)
leidenalg-0.10.2-cp37-cp37m-musllinux_1_1_x86_64.whl (2.4MiB)
leidenalg-0.10.2-cp37-cp37m-win32.whl (1.2MiB)
leidenalg-0.10.2-cp37-cp37m-win_amd64.whl (1.5MiB)
leidenalg-0.10.2-cp38-abi3-macosx_10_9_x86_64.whl (1.6MiB)
leidenalg-0.10.2-cp38-abi3-macosx_11_0_arm64.whl (1.4MiB)
leidenalg-0.10.2-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.8MiB)
leidenalg-0.10.2-cp38-abi3-manylinux_2_17_i686.manylinux2014_i686.whl (2.0MiB)
leidenalg-0.10.2-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.9MiB)
leidenalg-0.10.2-cp38-abi3-musllinux_1_1_i686.whl (2.4MiB)
leidenalg-0.10.2-cp38-abi3-musllinux_1_1_x86_64.whl (2.4MiB)
leidenalg-0.10.2-cp38-abi3-win32.whl (1.2MiB)
leidenalg-0.10.2-cp38-abi3-win_amd64.whl (1.5MiB)
leidenalg-0.10.2-pp310-pypy310_pp73-macosx_10_9_x86_64.whl (1.6MiB)
leidenalg-0.10.2-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.6MiB)
leidenalg-0.10.2-pp310-pypy310_pp73-manylinux_2_17_i686.manylinux2014_i686.whl (1.8MiB)
leidenalg-0.10.2-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.7MiB)
leidenalg-0.10.2-pp37-pypy37_pp73-macosx_10_9_x86_64.whl (1.6MiB)
leidenalg-0.10.2-pp37-pypy37_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.6MiB)
leidenalg-0.10.2-pp37-pypy37_pp73-manylinux_2_17_i686.manylinux2014_i686.whl (1.8MiB)
leidenalg-0.10.2-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.7MiB)
leidenalg-0.10.2-pp38-pypy38_pp73-macosx_10_9_x86_64.whl (1.6MiB)
leidenalg-0.10.2-pp38-pypy38_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.6MiB)
leidenalg-0.10.2-pp38-pypy38_pp73-manylinux_2_17_i686.manylinux2014_i686.whl (1.8MiB)
leidenalg-0.10.2-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.7MiB)
leidenalg-0.10.2-pp39-pypy39_pp73-macosx_10_9_x86_64.whl (1.6MiB)
leidenalg-0.10.2-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.6MiB)
leidenalg-0.10.2-pp39-pypy39_pp73-manylinux_2_17_i686.manylinux2014_i686.whl (1.8MiB)
leidenalg-0.10.2-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.7MiB)
leidenalg-0.10.2.tar.gz (442.0KiB)
Extras: None
Dependencies:
igraph (<0.12,>=0.10.0)