Skip to main content

Module community

Module community 

Source
Expand description

Community detection over the call graph (Plan competitive-harvest t-009).

Partitions symbols into functional communities — groups that call each other more than they call outside the group. Used to power asd architecture’s “clusters” (a call-graph view, complementary to the path-based layer view).

§Why Louvain’s local-move phase, not Label Propagation

Label propagation is simpler but collapses on bridged cliques: a single edge between two otherwise-dense modules causes one to adopt the other’s label, merging them. Code call graphs are full of such thin bridges, so LPA would report one giant community. The modularity gain Louvain optimizes resists this — joining a dense community through one edge barely raises modularity, so dense modules stay separate. We run the local-moving phase (one Louvain level); the multi-level aggregation that further coarsens communities is a possible future refinement.

Deterministic: nodes are visited in input order and ties break to the lowest community id, so the same graph always yields the same partition.

Functions§

detect_communities
Detect communities over an undirected graph. nodes should be passed in a stable (e.g. sorted) order for reproducibility. edges are unordered pairs; self-loops and edges to unknown nodes are ignored, duplicates collapse. Returns a dense node → community_id map.