Skip to main content

Vienna Graph Clustering -- VieClus

Project description

VieClus v1.3 License: MIT C++ CMake Build GitHub Release PyPI Homebrew Linux macOS GitHub Stars GitHub Issues Last Commit arXiv Heidelberg University

VieClus Logo

VieClus (Vienna Graph Clustering) is a memetic algorithm for high-quality graph clustering that optimizes modularity. It is the state-of-the-art solver for achieving the highest possible modularity values. Part of the KaHIP organization.

Python Interface: An easy-to-use Python interface for this software is available in CHSZLabLib.

What it solves Graph clustering: detecting tightly connected regions (communities) in a graph
Objective Maximize modularity
Key result Improves or reproduces all entries of the 10th DIMACS Implementation Challenge
Algorithm Memetic (evolutionary) algorithm with multilevel techniques and ensemble recombination. Optional Leiden mode guarantees connected communities.
Interfaces CLI, Python (pip install vieclus), C/C++ library
Parallel Optional MPI support for parallel evolutionary search

Quick Start

Install

Method Command
Homebrew (macOS/Linux) brew install KaHIP/kahip/vieclus
pip (Python) pip install vieclus
Build from source ./compile_withcmake.sh (with MPI) or ./compile_withcmake.sh NOMPI

Run

Command line:

# With MPI (better solution quality through parallel evolutionary search)
mpirun -n 4 ./deploy/vieclus examples/astro-ph.graph --time_limit=60

# Without MPI
./deploy/vieclus examples/astro-ph.graph --time_limit=60

Python (quickest way to get started):

import vieclus

g = vieclus.vieclus_graph()
g.set_num_nodes(6)
g.add_undirected_edge(0, 1, 5)
g.add_undirected_edge(1, 2, 5)
g.add_undirected_edge(0, 2, 5)
g.add_undirected_edge(3, 4, 5)
g.add_undirected_edge(4, 5, 5)
g.add_undirected_edge(3, 5, 5)
g.add_undirected_edge(2, 3, 1)  # weak bridge between two communities

vwgt, xadj, adjcwgt, adjncy = g.get_csr_arrays()
modularity, clustering = vieclus.cluster(vwgt, xadj, adjcwgt, adjncy, time_limit=1.0)

print(f"Modularity: {modularity}")   # e.g. 0.41
print(f"Clustering: {clustering}")   # e.g. [0, 0, 0, 1, 1, 1]

Command Line Usage

mpirun -n P vieclus <graph-file> [options]
Option Description Default
<graph-file> Path to graph in METIS format (see Graph Format) required
--time_limit=<double> Time limit in seconds. Must be > 0 to enable evolutionary recombination. 0
--seed=<int> Random seed 0
--output_filename=<string> Output file for the clustering tmpclustering
--leiden Use Leiden algorithm (guarantees connected communities) off
--leiden_theta=<double> Leiden refinement temperature parameter 0.01
--help Print help

Included tools:

Program Homebrew name Description
vieclus vieclus Main clustering algorithm
graphchecker vieclus_graphchecker Validate that a graph file is correctly formatted
evaluator vieclus_evaluator Compute modularity of a given clustering

Note: When installed via Homebrew, graphchecker and evaluator are prefixed with vieclus_ to avoid name collisions with other tools (e.g. KaHIP). When built from source, the original names are used in ./deploy/.

Example workflow:

# 1. Check your graph file
./deploy/graphchecker mygraph.graph          # from source
vieclus_graphchecker mygraph.graph           # via brew

# 2. Cluster it (4 MPI processes, 60 second time limit)
mpirun -n 4 ./deploy/vieclus mygraph.graph --time_limit=60 --output_filename=result.clustering

# 3. Evaluate the result
./deploy/evaluator mygraph.graph --input_partition=result.clustering          # from source
vieclus_evaluator mygraph.graph --input_partition=result.clustering           # via brew

Python Interface

Install via pip:

pip install vieclus

Or build from source:

pip install .

Using the vieclus_graph helper class

import vieclus

g = vieclus.vieclus_graph()
g.set_num_nodes(6)

# Add edges (undirected, with weights)
g.add_undirected_edge(0, 1, 5)
g.add_undirected_edge(1, 2, 5)
g.add_undirected_edge(0, 2, 5)
g.add_undirected_edge(3, 4, 5)
g.add_undirected_edge(4, 5, 5)
g.add_undirected_edge(3, 5, 5)
g.add_undirected_edge(2, 3, 1)  # weak bridge between two communities

vwgt, xadj, adjcwgt, adjncy = g.get_csr_arrays()
modularity, clustering = vieclus.cluster(vwgt, xadj, adjcwgt, adjncy, time_limit=1.0)

print(f"Modularity: {modularity}")
print(f"Clustering: {clustering}")

Using raw CSR arrays

import vieclus

# Graph in METIS CSR format (same as KaHIP)
xadj    = [0, 2, 5, 7, 9, 12]
adjncy  = [1, 4, 0, 2, 4, 1, 3, 2, 4, 0, 1, 3]
vwgt    = [1, 1, 1, 1, 1]
adjcwgt = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]

modularity, clustering = vieclus.cluster(vwgt, xadj, adjcwgt, adjncy,
                                         suppress_output=True,
                                         seed=0,
                                         time_limit=2.0)

print(f"Modularity: {modularity}")
print(f"Clustering: {clustering}")

API Reference

vieclus.cluster(vwgt, xadj, adjcwgt, adjncy, **kwargs)

Parameter Type Default Description
vwgt list[int] required Node weights (length n)
xadj list[int] required CSR index array (length n+1)
adjcwgt list[int] required Edge weights (length m)
adjncy list[int] required CSR adjacency array (length m)
suppress_output bool True Suppress console output
seed int 0 Random seed
time_limit float 1.0 Time limit in seconds
cluster_upperbound int 0 Max cluster size (0 = no limit)
leiden bool False Use Leiden algorithm (guarantees connected communities)
leiden_theta float 0.01 Leiden refinement temperature parameter

Returns: (modularity: float, clustering: list[int]) where modularity is in [-1, 1] and clustering maps each node to a cluster ID.

vieclus.vieclus_graph -- helper class for building graphs (same interface as kahip.kahip_graph):

Method Description
set_num_nodes(n) Set the number of nodes
add_undirected_edge(u, v, weight) Add an undirected edge with weight
get_csr_arrays() Returns (vwgt, xadj, adjcwgt, adjncy) ready for vieclus.cluster()

C/C++ Library

Link against libvieclus_static.a and include vieclus_interface.h:

#include "vieclus_interface.h"

int n = 5;
int xadj[]   = {0, 2, 5, 7, 9, 12};
int adjncy[] = {1, 4, 0, 2, 4, 1, 3, 2, 4, 0, 1, 3};

int clustering[5];
double modularity;
int num_clusters;

vieclus_clustering(&n, NULL, xadj, NULL, adjncy,
                   true,   // suppress_output
                   0,      // seed
                   10.0,   // time_limit
                   0,      // cluster_upperbound (0 = no limit)
                   &modularity, &num_clusters, &clustering[0]);

Build with:

./compile_withcmake.sh NOMPI
g++ -std=c++11 my_program.cpp -I interface/ -L build/ -lvieclus_static -lpthread -fopenmp -o my_program

Graph Format

VieClus uses the METIS graph format, the same format used by KaHIP, Metis, Chaco, and the 10th DIMACS Implementation Challenge.

Input format

A plain text file with n + 1 lines (excluding comments). Lines starting with % are comments and are skipped.

Header line:

n m [f]
  • n = number of vertices, m = number of undirected edges
  • f = format flag (optional): 0 = unweighted, 1 = edge weights, 10 = node weights, 11 = both

Vertex lines (one per vertex): Each of the following n lines describes one vertex's adjacency list. For f=1 (edge weights):

v1 w1 v2 w2 ...

where v_i are neighbor IDs (1-indexed) and w_i are edge weights.

Example (4 vertices, 5 edges, unweighted):

4 5
2 3
1 3 4
1 2 4
2 3

Output format

The clustering output file contains n lines. Line i contains the cluster ID of vertex i (0-indexed). Cluster IDs are numbered consecutively from 0.

Validating your graph

./deploy/graphchecker mygraph.graph

How It Works

VieClus is a memetic algorithm that combines evolutionary search with multilevel graph clustering techniques:

  1. Multilevel approach: The graph is recursively coarsened, an initial clustering is computed on the smallest graph, and local search improves the clustering at each level during uncoarsening.
  2. Evolutionary recombination: A population of clusterings is maintained. Two parent clusterings are combined using an ensemble clustering overlay, where two vertices end up in the same cluster only if they agree in both parents.
  3. Parallel search (with MPI): Multiple processes explore the solution space independently and exchange high-quality individuals, improving diversity and convergence.

More time and more MPI processes generally yield better modularity values. For details, see the paper.

Leiden Mode (--leiden)

When --leiden is passed, VieClus uses the Leiden algorithm (Traag, Waltman, van Eck, 2019) instead of Louvain as its core clustering method. This guarantees that all output communities are connected subgraphs. The implementation uses three phases per multilevel iteration:

  1. Fast local moving (queue-based): only revisits nodes whose neighbors changed, making it faster than Louvain's full sweeps.
  2. Refinement: within each community, restarts from singletons and stochastically merges nodes into adjacent sub-communities. Since only singleton nodes can move, connectivity is guaranteed by construction.
  3. Dual-partition aggregation: aggregates based on the refined partition, but initializes the next level with the coarser partition from phase 1.

All evolutionary operators additionally enforce connectivity via BFS-based splitting when --leiden is active.

Example:

mpirun -n 4 ./deploy/vieclus mygraph.graph --leiden --time_limit=60

Related Projects

Project Description
KaHIP Karlsruhe High Quality Graph Partitioning (flagship framework)
CluStRE Fast streaming graph clustering
KaMinPar Shared-memory parallel graph partitioner
KaHyPar Karlsruhe Hypergraph Partitioning

Release Notes

v1.3

  • Added --leiden flag: Leiden algorithm guaranteeing connected communities
  • Added --leiden_theta parameter for refinement temperature control
  • Leiden uses queue-based local moving, stochastic refinement, and dual-partition aggregation
  • All evolutionary operators enforce connectivity when --leiden is active
  • Fixed include directory ordering in CMakeLists.txt

v1.2

  • Added Python interface (pip install vieclus) with pybind11 bindings
  • Added vieclus_graph helper class for easy graph construction (same interface as KaHIP)
  • Added vieclus.cluster() function
  • Added PyPI packaging with scikit-build-core
  • Added GitHub Actions CI and automated PyPI publishing
  • Added NOMPI compilation support

v1.1

  • Added cmake build system
  • Added option to compile without MPI support

v1.0

  • Initial release of the memetic graph clustering algorithm

Building from Source

With MPI (recommended for best solution quality)

MPI enables the parallel evolutionary algorithm which typically yields better solutions.

Prerequisites: OpenMPI or Intel MPI

git clone https://github.com/KaHIP/VieClus.git
cd VieClus
./compile_withcmake.sh

Binaries are placed in ./deploy/.

Without MPI

./compile_withcmake.sh NOMPI

No additional dependencies beyond a C++11 compiler and CMake 3.10+.


Licence

The program is licenced under MIT licence. If you publish results using our algorithms, please acknowledge our work by quoting the following paper:

@inproceedings{BiedermannHSS18,
  author    = {Biedermann, Sonja and Henzinger, Monika and Schulz, Christian and Schuster, Bernhard},
  title     = {{Memetic Graph Clustering}},
  booktitle = {17th International Symposium on Experimental Algorithms (SEA 2018)},
  series    = {LIPIcs},
  volume    = {103},
  pages     = {3:1--3:15},
  publisher = {Schloss Dagstuhl -- Leibniz-Zentrum f{\"{u}}r Informatik},
  year      = {2018},
  doi       = {10.4230/LIPIcs.SEA.2018.3}
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

vieclus-1.3.1.tar.gz (4.1 MB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

vieclus-1.3.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (728.0 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

vieclus-1.3.1-cp312-cp312-macosx_11_0_arm64.whl (285.3 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

vieclus-1.3.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (727.1 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

vieclus-1.3.1-cp311-cp311-macosx_11_0_arm64.whl (285.1 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

vieclus-1.3.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (724.7 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

vieclus-1.3.1-cp310-cp310-macosx_11_0_arm64.whl (283.9 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

vieclus-1.3.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (724.8 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

vieclus-1.3.1-cp39-cp39-macosx_11_0_arm64.whl (283.9 kB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

vieclus-1.3.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (724.5 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

vieclus-1.3.1-cp38-cp38-macosx_11_0_arm64.whl (283.6 kB view details)

Uploaded CPython 3.8macOS 11.0+ ARM64

File details

Details for the file vieclus-1.3.1.tar.gz.

File metadata

  • Download URL: vieclus-1.3.1.tar.gz
  • Upload date:
  • Size: 4.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for vieclus-1.3.1.tar.gz
Algorithm Hash digest
SHA256 f761358aac3710aad952c8f98f942254ab5dfdeb14bff79ecd6085da19fd4ce5
MD5 8c6f9b8c4bb0e99fbb6df3eeb556623d
BLAKE2b-256 f8ad3b6fd5421faa8c73e167bda2f39410000520857619f7bd77f51960bb5f0f

See more details on using hashes here.

Provenance

The following attestation bundles were made for vieclus-1.3.1.tar.gz:

Publisher: publish-to-pypi.yml on KaHIP/VieClus

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file vieclus-1.3.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for vieclus-1.3.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 13327f92d218666881eb7bd9a367606c10c3acac9121fcd873144f889dc521d9
MD5 e8b6b673b81da0ee8dce04503f0d52b5
BLAKE2b-256 62ba1fb7ffc80811c824cdd62c5656b39bd69622772059d0a053a75b16050617

See more details on using hashes here.

Provenance

The following attestation bundles were made for vieclus-1.3.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: publish-to-pypi.yml on KaHIP/VieClus

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file vieclus-1.3.1-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for vieclus-1.3.1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 44b891ff6aff21677db0410de03ce58ca35b8ab96b50dc851847d8d6230fc8e2
MD5 ec6db72983b2712eeaf39f9db8da0e18
BLAKE2b-256 27edf2e427bb9c26086b945f8611defb4b23f58d198be1d9e3dcabcbd8266ff9

See more details on using hashes here.

Provenance

The following attestation bundles were made for vieclus-1.3.1-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: publish-to-pypi.yml on KaHIP/VieClus

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file vieclus-1.3.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for vieclus-1.3.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8ab683b15de61166fdf5d1e56e3c8f77adb749caeaa91943aba0d4ba581ca2a6
MD5 78bc6382197a5af770f22b87bd0af530
BLAKE2b-256 da85bac1252d3dbd205835bc1b96f0373c2675bebe7f3dfe9ae25fde56e5c9b6

See more details on using hashes here.

Provenance

The following attestation bundles were made for vieclus-1.3.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: publish-to-pypi.yml on KaHIP/VieClus

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file vieclus-1.3.1-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for vieclus-1.3.1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9d5a163553824eac6e9ac5af21d139159187c660c173969e17843c909a36713f
MD5 e734d98eeeca6cd69d04fd14b77ba64e
BLAKE2b-256 e12623ed6c55d70cf58231090c9e1bef0b9804bbb51be18b6a022c7641aa3abe

See more details on using hashes here.

Provenance

The following attestation bundles were made for vieclus-1.3.1-cp311-cp311-macosx_11_0_arm64.whl:

Publisher: publish-to-pypi.yml on KaHIP/VieClus

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file vieclus-1.3.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for vieclus-1.3.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 781dccb2980c83cec0f42bf089ff7c35e45fc2ae9bcb65561cb5b2353ec4a992
MD5 5e44b32937343cea205af4c578d240a4
BLAKE2b-256 14424dfa1d97322e494303dd487e6c120be0d16d3f0daa8bf38dd90e9a35ea21

See more details on using hashes here.

Provenance

The following attestation bundles were made for vieclus-1.3.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: publish-to-pypi.yml on KaHIP/VieClus

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file vieclus-1.3.1-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for vieclus-1.3.1-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 36bcb729a15b6992764ffbcd3febb3f32cb97cfad700ca12ff14cc9b65e651e5
MD5 41ee7dd99fc02532278048136ccf7380
BLAKE2b-256 1b15aa06eae331d8e164bab3114dc8a7a22ee2a1c8a90c606a5a655bfeacaaf6

See more details on using hashes here.

Provenance

The following attestation bundles were made for vieclus-1.3.1-cp310-cp310-macosx_11_0_arm64.whl:

Publisher: publish-to-pypi.yml on KaHIP/VieClus

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file vieclus-1.3.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for vieclus-1.3.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b19ec3af2260e500383d2275ed70ec9a06f388353c792c2a111ec8195e8e5aef
MD5 b345f1dec69359f79d29cd5d108a5809
BLAKE2b-256 fb79d84c06d86c986d2ff997d6619e6b81d9cf9b6895fc85f9f6bfa8dcabd1b8

See more details on using hashes here.

Provenance

The following attestation bundles were made for vieclus-1.3.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: publish-to-pypi.yml on KaHIP/VieClus

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file vieclus-1.3.1-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for vieclus-1.3.1-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 26da940bf89d53c496b42662aaec2573240f302113a814b97895574fae713408
MD5 2c51e7a13818e4eaf1d2a25384a92dda
BLAKE2b-256 6b7709c13b45d2274da2006e5158110db501207754265318b6d5800d20aa23ac

See more details on using hashes here.

Provenance

The following attestation bundles were made for vieclus-1.3.1-cp39-cp39-macosx_11_0_arm64.whl:

Publisher: publish-to-pypi.yml on KaHIP/VieClus

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file vieclus-1.3.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for vieclus-1.3.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 fd9ff9f9992b5bbbaf8e19266cee5a3104702850d9069e0b4062e75338674e18
MD5 3434ba370284128327fc60e2397569d2
BLAKE2b-256 9c46993583e668e2ce70ce4936ef2ed435eeec7a8d187b5ba4fb829aeb8c29a6

See more details on using hashes here.

Provenance

The following attestation bundles were made for vieclus-1.3.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: publish-to-pypi.yml on KaHIP/VieClus

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file vieclus-1.3.1-cp38-cp38-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for vieclus-1.3.1-cp38-cp38-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 468afb6522f2f05e5ec442ffea8719a631b029a989f00f9c479c88cb8f832cc7
MD5 75c092d86ac30df127d4a691e3ca25c6
BLAKE2b-256 47386e9b1df7a4b9ab3deee7e060a45cc07e946f13063503561e1988ad6c959e

See more details on using hashes here.

Provenance

The following attestation bundles were made for vieclus-1.3.1-cp38-cp38-macosx_11_0_arm64.whl:

Publisher: publish-to-pypi.yml on KaHIP/VieClus

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page