ModularityPruning
ModularityPruning is a pruning tool to identify small subsets of network partitions that are significant from the perspective of stochastic block model inference. It:
- Works for single-layer and multi-layer networks
- Supports both directed and undirected networks
- Supports weighted networks via the
weightedge attribute - Restricts focus to a fixed number of communities when desired
- Contains a faster and more robust implementation of the CHAMP (Convex Hull of
Admissible Modularity Partitions) algorithm (see
CHAMP_2DandCHAMP_3D)
See the documentation or the journal article at https://doi.org/10.1038/s41598-022-20142-6 for more information.
Significantly more details can be found in the article's Supplementary Information.
Note: support for weighted and directed networks is an extension beyond the original publication.
Installation
This project is on PyPI and can be installed with
pip install modularitypruning
# OR
pip3 install modularitypruning
Alternatively, you can install it from this repository directly:
git clone https://github.com/ragibson/ModularityPruning
cd ModularityPruning
pip install .
For modularitypruning development, it is best to use a strict editable install
so that pytest and mypy can pick up changes immediately.
pip install --editable . --config-settings editable_mode=strict
Basic Usage
This package interfaces directly with python-igraph. A simple example of its usage is
import igraph as ig
from modularitypruning import prune_to_stable_partitions
from modularitypruning.leiden_utilities import repeated_leiden_from_gammas
import numpy as np
# get Karate Club graph in igraph
G = ig.Graph.Famous("Zachary")
# run leiden 1000 times on this graph from gamma=0 to gamma=2
partitions = repeated_leiden_from_gammas(G, np.linspace(0, 2, 1000))
# prune to the stable partitions from gamma=0 to gamma=2
stable_partitions = prune_to_stable_partitions(G, partitions, 0, 2)
print(stable_partitions)
This prints
[(0, 0, 0, 0, 1, 1, 1, 0, 2, 2, 1, 0, 0, 0, 2, 2, 1, 0, 2, 0, 2, 0, 2, 3, 3, 3, 2, 3, 3, 2, 2, 3, 2, 2)]
which is the stable 4-community split of the Karate Club network.
More Information
The issues and figure generation runtimes README may also be of interest.
Metadata
Release files for modularitypruning 2.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| modularitypruning-2.0.2.tar.gz | 36.9 kB | With provenance | Details for modularitypruning-2.0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| modularitypruning-2.0.2-py3-none-any.whl | Python 3 | none | any | Details for modularitypruning-2.0.2-py3-none-any.whl |
Total release size: 65.5 kB
Release files / modularitypruning-2.0.2.tar.gz
| Download URL | modularitypruning-2.0.2.tar.gz |
|---|---|
| Size | 36.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fc680ae9713f5d4c91edf1a2d22c6125b306a964b0abb11affacf44dcf9fbae4
|
|
BLAKE2b-256 checksum How to use checksums |
c7730c2f7111200922ffb907b48fce657024164a146b1d976a331bcd6b610d32
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 15, 2026.
Transparency logRelease files / modularitypruning-2.0.2-py3-none-any.whl
| Download URL | modularitypruning-2.0.2-py3-none-any.whl |
|---|---|
| Size | 28.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f03cfb13b87b608a159f2d3d50ba9f1dd21c428ed97cff3ba744a863ac102ae8
|
|
BLAKE2b-256 checksum How to use checksums |
29e98b17046ccf104f2ff5dabe9a9d5bc687d4ff863432b066fb5f503c2d9027
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 15, 2026.
Transparency logSecurity for modularitypruning 2.0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for modularitypruning-2.0.2.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 15, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.