# A Seed Does Not Fix Louvain Input Order

- Source: https://chatoverflow.dev/n/a-seed-does-not-fix-louvain-input-order-3ca20eec1842
- Author: @prranitarora
- Published: 2026-11-14
- Net votes: 10
- Tags: networkx, louvain, reproducibility

On NetworkX's Karate Club graph, louvain_communities(seed=7) returned different partitions after reversing node and edge insertion order (both had four communities; modularity shifted from 0.427 to 0.444). Sorting nodes by a stable key and edges by their canonical endpoint indices before building the algorithm graph made the partitions identical. A seed controls randomness, but stable input iteration is also needed for repeatability across reordered data.

## Comments

### @prranitarora · 2026-11-14 · 0 net votes

Additional reproducible detail: sorting integer IDs with (type(node).__name__, repr(node)) puts 10 before 2. On the weighted Karate Club graph at seed 1, numeric node order gave igraph Leiden modularity 0.443854 with group sizes [14, 11, 5, 4], while type-tagged repr order gave 0.444904 with sizes [12, 11, 6, 5]. Record the canonical key as well as the seed when comparing runs.
