You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Non-deterministic community assignments across identical-corpus runs (0.9.6) #1667
Second of the two 0.9.6 follow-ups (see the zero-nodes-in-batch issue filed alongside — they may share a parallel-processing root cause).
Symptom
Two consecutive graphify update . runs on an unchanged corpus produce graph.json files that differ only in community assignments:
node-id set: identical
link multiset (all fields): identical
community: differs on 196 of 11,819 nodes
So the semantic graph is deterministic, but the artifact is not byte-reproducible.
It appears intermittent: one other consecutive pair of runs produced byte-identical output. That pattern is consistent with an unseeded RNG or parallel-ordering dependence in the community-detection step (Louvain/Leiden-style methods are tie-break sensitive).
On 0.9.5 we never observed this — we actually used file-hash equality of double runs as an acceptance test for our own append pipeline, and it held.
Ask
A fixed seed and/or deterministic tie-breaking in community detection, so identical input produces byte-identical graph.json. Reproducible output is useful for caching, CI artifact diffing, and downstream tools that append to the graph (our case).
Looked into this closely. The clustering path already has the determinism guards you would want, and I could not reproduce the nondeterminism with synthetic graphs, so I do not want to ship a speculative fix that might not address your case. Findings:
Community detection runs on a rebuilt stable graph with sorted node and edge insertion, and the partitioner is seeded (graspologic leiden random_seed=42, trials=1; verified the installed 3.4.4 signature accepts and receives both). The final community IDs are assigned by a total order (size desc, then tuple(sorted(node_ids))), so an identical grouping always maps to identical IDs.
On a synthetic 600-node/1700-edge graph I ran cluster() twice in-process and across two processes with different PYTHONHASHSEED: zero differing community assignments both ways. So the Python-side path is deterministic here.
That leaves the grouping itself coming out of graspologic's native leiden differing run-to-run on your larger graph (11.8k nodes), which is a known class of behavior for leiden implementations at scale (threading / floating-point non-associativity in modularity optimization), and would be exposed more once 0.9.6 made your Ruby graph denser.
To pin it, could you share (or privately send) the graph.json from two runs that differ, or the node/edge export, so I can feed the exact graph to cluster() and confirm whether the nondeterminism is in graspologic on that input? If it is graspologic, options are pinning to the louvain fallback for reproducibility-critical use, or a deterministic post-pass. Keeping this open.
Re-tested on 0.9.6 (uv, macOS). First, an environment note that changes the diagnosis: graspologic is NOT installed in our env, so _partition takes the networkx Louvain fallback (nx.community.louvain_communities(stable, seed=42), networkx 3.4.2). This is the default path, not a misconfiguration: graspologic is an optional extra (graphifyy[leiden] / [all]) gated to python_version < "3.13", so a plain uv/pip install uses Louvain, and every install on Python 3.13+ uses it regardless. So our graph.json communities are Louvain, not graspologic leiden, and the leiden determinism guards you verified are not on this path.
I localized it with an anonymized integer-topology probe (no proprietary data), running three levels in SEPARATE processes under default vs fixed PYTHONHASHSEED:
louvain_raw (nx.community.louvain_communities on the sorted stable graph): identical cross-process (0/12229), both hashseeds.
cluster() (oversized/cohesion splitting + size-desc reindex):
default PYTHONHASHSEED -> differs on 5110/12229 nodes, community COUNT flaps 1302 vs 1304
PYTHONHASHSEED=0 -> byte-identical (0/12229)
So the base partition is deterministic. The nondeterminism is entirely in cluster()'s post-Louvain split/reindex passes, and it is PYTHONHASHSEED driven: set and dict iteration order over string node ids (louvain_communities returns a list of sets; iterating those and the split subgraphs is hash-order dependent). The tuple(sorted(map(str, nodes))) reindex tiebreak stabilizes IDs given a fixed grouping, but the grouping and count vary because the split decisions depend on iteration order.
A fixed seed cannot fix this on its own (the seed controls the RNG, not string-hash set order). Deterministic options: sort node ids before iterating in the split passes, or relabel nodes to ints for clustering, or set PYTHONHASHSEED. As a user workaround we can run graphify under PYTHONHASHSEED=0 and get byte-identical graph.json.
This is on the Louvain fallback, so it is independent of graspologic. I can re-run the same three-level probe with graspologic installed if you want to know whether the leiden path also flaps, but the fallback path (the default for a plain install, and the only path on Python 3.13+) is clearly nondeterministic today. Happy to share the short probe script (it only calls networkx and your cluster module).
Dug into this deeply again and want to share what I found, because the honest answer is "real bug, no clean in-code fix yet" rather than a quick patch.
Reproduced and localized. Using a synthetic gaussian_random_partition_graph (fixed structure, only PYTHONHASHSEED varying), cluster() flaps community count 28/31/30/28/30 across seeds. Stage-by-stage fingerprinting shows the top-level partition (raw) and the oversized-split pass are deterministic; the flap is entirely in the cohesion-split pass — _split_community() → _partition() on a community subgraph. Splitting the same community (verified same node set) yields different sub-groupings for some communities (a size-106 one flapped 9/7/9 splits) but not others (size-84/98/80 were stable). Same PYTHONHASHSEED always gives the same result, so it's genuinely hashseed-driven, not thread scheduling.
Your relabel-to-int suggestion: I implemented it and it's insufficient. Integer node labels make the top-level 900-node partition byte-stable, but networkx.louvain_communities (and graspologic Leiden) still flap on certain denser subgraphs even with int nodes and a fixed seed — the internal tie-breaking depends on iteration order that PYTHONHASHSEED perturbs beyond just node-id hashing. So it reduces the churn but doesn't deliver the byte-reproducibility you're after. I reverted it rather than ship a partial fix that looks like a real one. (The split passes already sort where they iterate, and cohesion_score is order-independent, so those aren't the lever either.)
The reliable lever is the one you already found:PYTHONHASHSEED=0 graphify ... produces byte-identical graph.json. If that works for your CI/append pipeline, it's the recommended path today.
Keeping this open. The candidate real fixes are (a) have the CLI re-exec itself with PYTHONHASHSEED=0 when unset — reliable but a global behavior change, so I want to be deliberate about it — or (b) a deterministic partitioner that doesn't inherit the backend's hashseed sensitivity. Thanks for the rigorous localization in your earlier comment; it matched exactly what I re-measured.
@safishamsi Checking in on this one. We're stable on the workaround: PYTHONHASHSEED=0 is pinned in our refresh pipeline and double-runs on 0.9.12 remain byte-identical. So there's no urgency from our side, just planning visibility: do either of the candidate fixes you named (the CLI re-exec'ing itself with PYTHONHASHSEED=0 when unset, or a deterministic partitioner) have traction for an upcoming release? Even knowing which direction you're leaning helps us decide whether to keep the seed pin permanently or treat it as temporary.
Standing offer: happy to re-run the three-level probe (louvain_raw / _partition / cluster(), separate processes, varied hashseeds) on any candidate branch before you ship it.
Corroborating data point that isolates this to the clustering stage alone, eliminating extraction as a variable:
Holding the graph byte-identical (same graph.json input, no re-extraction), three cluster(G) invocations in separate processes produced 278, 277, and 276 communities on 0.9.17. After upgrading to 0.9.29 and repeating the experiment: 295, 296, 295. Still non-deterministic on the current release. Windows 11, Python 3.11.
Two upstream statements led us to expect otherwise: the cluster() docstring ("Community IDs are stable across runs") and the reproducibility comment near cluster.py:229 (the #1090 follow-up). The internal seed evidently does not guarantee cross-process reproducibility on this platform.
Practical consequence we hit: anything persisted per community id (labels, incremental tooling) breaks between runs. Our workaround is to keep G and communities in one process and pass the membership mapping, not the ids, to downstream tooling. If cross-process reproducibility is not achievable, documenting that (and making report tooling id-agnostic) would save others the same detour.
Independent reproduction on 0.9.29/0.9.31, plus the graspologic-installed measurement offered earlier in this thread but not yet posted, and a mechanism for the residual flap that survives the PYTHONHASHSEED pin.
Real repository (~5.4k AST nodes / ~7.4k edges), Windows 11, Python 3.12/3.14. cluster.py is byte-identical between 0.9.29 and 0.9.31, so this applies to the current release.
1. Louvain fallback — confirms the earlier localization
Same graph, cluster() called once per process, fingerprint = sha256 of the sorted (node_id, community_id) list:
arm
trials
distinct partitions
unpinned
8
4
PYTHONHASHSEED=0
8
1
Matches the three-level probe already in this thread. The pin is a complete fix on this path, and it holds end-to-end: two consecutive full refreshes of our pipeline now produce byte-identical graph.json where they previously did not.
2. Leiden — the pin is not sufficient
Taking up the standing offer to test with graspologic installed. Deliberately in a throwaway virtualenv, since adding graspologic to the working environment silently switches the partitioner and changes what every subsequent refresh produces. graspologic 3.4.4, networkx 3.6.1:
arm
trials
distinct partitions
community count
unpinned
8
8
490–495
PYTHONHASHSEED=0
8
2
490 / 491
So Leiden is both worse unpinned than Louvain and still non-deterministic pinned. This corroborates the 0.9.17→0.9.29 data point posted above (278/277/276 → 295/296/295) and extends it: the recommended workaround does not rescue the Leiden path.
3. The residual is leiden's dict iteration order, not its partition
Isolating with the input fingerprinted to prove it never varies between trials:
Raw leiden(stable, random_seed=42, trials=1) on identical sorted input: identical output in 12/12 trials, pinned and unpinned alike. Leiden's assignment is deterministic. Seeding works.
Repeated calls inside one process — where PYTHONHASHSEED is fixed by construction and therefore cannot be the variable — _partition() returns 4/4 identical while cluster() returns 490, 491, 491, 491.
The distinguishing measurement: fingerprinting leiden's returned dict by content versus by key order across 5 in-process calls on identical input:
Same partition every time, different iteration order every time. cluster() then consumes that order at raw.setdefault(cid, []).append(node), so the grouping handed to the split passes differs per call even though the partition did not.
This explains why the earlier relabel-to-int experiment reduced but did not eliminate the flap: int labels fix node-id hashing, but the ordering that varies here is the partitioner's own returned mapping, which no node relabeling touches.
4. What the divergence actually looks like
Diffing two in-process cluster() runs: the node sets are identical on both sides (68 vs 68 nodes), and the difference is a single split boundary — run 1 keeps one 68-node community whole, runs 2–3 split it 52+16. Calling _split_community() directly on that exact node set returns 1 distinct result across 5 calls, so the split routine itself is deterministic. It is the grouping fed into it that varies.
To be explicit about the limit of this: leiden's unstable key order and cluster()'s order-sensitive consumption of it are both measured. The propagation from that key order to this specific split decision I have not traced end to end, so treat the causal link as strongly supported rather than proven.
5. On the candidate fixes
Given the above, option (a) — CLI re-exec with PYTHONHASHSEED=0 — is necessary but not sufficient: it fixes Louvain fully and leaves Leiden non-deterministic, which is arguably worse than today because the failure becomes silent for anyone who has the [leiden] extra installed. If it ships alone, it may be worth having it also warn when graspologic is present.
A cheap, targeted alternative that does not depend on the hash seed at all: sort the partitioner's output before consuming it in cluster() — i.e. iterate sorted(partition.items()) rather than partition.items() — so downstream grouping cannot inherit the backend's iteration order. That would not fix modularity-tie sensitivity inside the partitioners, but it removes the specific mechanism measured here, and it is order-of-magnitude smaller than a deterministic partitioner.
Happy to re-run any of these probes on a candidate branch. The scripts are short — they only import networkx, graspologic, and graphify.cluster.
Two things: a small-scale corroboration where the PYTHONHASHSEED pin fully holds (no residual flap), and a consumer-side workaround that addresses a related problem the seed pin does not.
Corroboration — Louvain fallback, ~1k nodes
graphifyy 0.9.17, Python 3.13.12, networkx 3.6.1, Linux. graspologic not installed and not installable here — the [leiden] extra is gated to python_version < "3.13" — so this is the nx.community.louvain_communities fallback path, matching @krishnateja7's environment note.
Byte-identical graph.json (976 nodes / 1956 edges), cluster(G) once per process, fingerprint = sha256 of the sorted (node_id, community_id) list:
arm
run 1
run 2
run 3
run 4
PYTHONHASHSEED unset
64 a3235bfa
65 de122618
64 b4d55c27
65 965f6aac
PYTHONHASHSEED=0
65 de122618
65 de122618
65 de122618
65 de122618
Four distinct partitions in four unset runs; four identical ones when pinned. So at this scale the pin is a complete fix — I did not see the residual flap @luipa446-cloud reported at ~5.4k nodes. If that residual is size- or structure-dependent, the gap between ~1k and ~5.4k nodes might be a useful place to bisect.
Worth noting the flap here is small in node terms but not harmless: it moves whole communities in and out of existence (64 ↔ 65), and the two counts are stable attractors rather than noise.
Complementary workaround: cache the partition against a graph fingerprint
PYTHONHASHSEED=0 makes a run reproducible, but it does not give community identity across rebuilds. Anyone who attaches meaning to a community — human-written labels, a wiki page per community, review notes — loses that mapping whenever the graph changes at all, because the partition is recomputed from scratch and communities renumber.
What worked for us was to stop re-clustering an unchanged graph entirely:
Unchanged graph reuses its exact partition; a changed graph reclusters and says so. Independent of PYTHONHASHSEED, so it also covers callers whose environment you do not control.
For the labels themselves, keying them by community id does not survive renumbering and keying them by a representative node silently mislabels a community that kept its hub while its membership changed. Matching each rebuilt community to the saved one with the highest membership overlap (Jaccard ≥ 0.5, else treat as new and report it) was the first approach that neither drifted nor mislabeled. Communities of ≤ 2 nodes were excluded from matching — peripheral pairs get reattached differently on every run and would otherwise flap forever.
Both together gave fully stable rebuilds across repeated runs.
This is a consumer-side patch on top of cluster(), so it is not a fix — it just makes the nondeterminism invisible downstream. It is roughly the poor-man's version of #2452 (seed cluster() with a previous partition), and if that lands with an optional previous= argument it would replace this entirely and do a better job, since it could reuse the prior partition as a starting point rather than only as a cache hit.
This looks fixed on the v8 branch by 27096817 (fix(cluster): canonicalise edge endpoints before sorting in _partition). Could a maintainer confirm and close?
Activity
safishamsi commentedon Jul 5, 2026
Looked into this closely. The clustering path already has the determinism guards you would want, and I could not reproduce the nondeterminism with synthetic graphs, so I do not want to ship a speculative fix that might not address your case. Findings:
stablegraph with sorted node and edge insertion, and the partitioner is seeded (graspologic leidenrandom_seed=42,trials=1; verified the installed 3.4.4 signature accepts and receives both). The final community IDs are assigned by a total order (size desc, thentuple(sorted(node_ids))), so an identical grouping always maps to identical IDs.cluster()twice in-process and across two processes with differentPYTHONHASHSEED: zero differing community assignments both ways. So the Python-side path is deterministic here.That leaves the grouping itself coming out of graspologic's native leiden differing run-to-run on your larger graph (11.8k nodes), which is a known class of behavior for leiden implementations at scale (threading / floating-point non-associativity in modularity optimization), and would be exposed more once 0.9.6 made your Ruby graph denser.
To pin it, could you share (or privately send) the
graph.jsonfrom two runs that differ, or the node/edge export, so I can feed the exact graph tocluster()and confirm whether the nondeterminism is in graspologic on that input? If it is graspologic, options are pinning to the louvain fallback for reproducibility-critical use, or a deterministic post-pass. Keeping this open.krishnateja7 commentedon Jul 5, 2026
Re-tested on 0.9.6 (uv, macOS). First, an environment note that changes the diagnosis: graspologic is NOT installed in our env, so
_partitiontakes the networkx Louvain fallback (nx.community.louvain_communities(stable, seed=42), networkx 3.4.2). This is the default path, not a misconfiguration: graspologic is an optional extra (graphifyy[leiden]/[all]) gated topython_version < "3.13", so a plain uv/pip install uses Louvain, and every install on Python 3.13+ uses it regardless. So our graph.json communities are Louvain, not graspologic leiden, and the leiden determinism guards you verified are not on this path.I localized it with an anonymized integer-topology probe (no proprietary data), running three levels in SEPARATE processes under default vs fixed PYTHONHASHSEED:
_partition(your wrapper): identical cross-process (0/12229).cluster()(oversized/cohesion splitting + size-desc reindex):default PYTHONHASHSEED -> differs on 5110/12229 nodes, community COUNT flaps 1302 vs 1304
PYTHONHASHSEED=0 -> byte-identical (0/12229)
So the base partition is deterministic. The nondeterminism is entirely in
cluster()'s post-Louvain split/reindex passes, and it is PYTHONHASHSEED driven: set and dict iteration order over string node ids (louvain_communities returns a list of sets; iterating those and the split subgraphs is hash-order dependent). Thetuple(sorted(map(str, nodes)))reindex tiebreak stabilizes IDs given a fixed grouping, but the grouping and count vary because the split decisions depend on iteration order.A fixed seed cannot fix this on its own (the seed controls the RNG, not string-hash set order). Deterministic options: sort node ids before iterating in the split passes, or relabel nodes to ints for clustering, or set PYTHONHASHSEED. As a user workaround we can run graphify under PYTHONHASHSEED=0 and get byte-identical graph.json.
This is on the Louvain fallback, so it is independent of graspologic. I can re-run the same three-level probe with graspologic installed if you want to know whether the leiden path also flaps, but the fallback path (the default for a plain install, and the only path on Python 3.13+) is clearly nondeterministic today. Happy to share the short probe script (it only calls networkx and your cluster module).
safishamsi commentedon Jul 10, 2026
Dug into this deeply again and want to share what I found, because the honest answer is "real bug, no clean in-code fix yet" rather than a quick patch.
Reproduced and localized. Using a synthetic
gaussian_random_partition_graph(fixed structure, onlyPYTHONHASHSEEDvarying),cluster()flaps community count 28/31/30/28/30 across seeds. Stage-by-stage fingerprinting shows the top-level partition (raw) and the oversized-split pass are deterministic; the flap is entirely in the cohesion-split pass —_split_community()→_partition()on a community subgraph. Splitting the same community (verified same node set) yields different sub-groupings for some communities (a size-106 one flapped 9/7/9 splits) but not others (size-84/98/80 were stable). SamePYTHONHASHSEEDalways gives the same result, so it's genuinely hashseed-driven, not thread scheduling.Your
relabel-to-intsuggestion: I implemented it and it's insufficient. Integer node labels make the top-level 900-node partition byte-stable, butnetworkx.louvain_communities(and graspologic Leiden) still flap on certain denser subgraphs even with int nodes and a fixed seed — the internal tie-breaking depends on iteration order thatPYTHONHASHSEEDperturbs beyond just node-id hashing. So it reduces the churn but doesn't deliver the byte-reproducibility you're after. I reverted it rather than ship a partial fix that looks like a real one. (The split passes already sort where they iterate, andcohesion_scoreis order-independent, so those aren't the lever either.)The reliable lever is the one you already found:
PYTHONHASHSEED=0 graphify ...produces byte-identicalgraph.json. If that works for your CI/append pipeline, it's the recommended path today.Keeping this open. The candidate real fixes are (a) have the CLI re-exec itself with
PYTHONHASHSEED=0when unset — reliable but a global behavior change, so I want to be deliberate about it — or (b) a deterministic partitioner that doesn't inherit the backend's hashseed sensitivity. Thanks for the rigorous localization in your earlier comment; it matched exactly what I re-measured.krishnateja7 commentedon Jul 10, 2026
@safishamsi Checking in on this one. We're stable on the workaround:
PYTHONHASHSEED=0is pinned in our refresh pipeline and double-runs on 0.9.12 remain byte-identical. So there's no urgency from our side, just planning visibility: do either of the candidate fixes you named (the CLI re-exec'ing itself withPYTHONHASHSEED=0when unset, or a deterministic partitioner) have traction for an upcoming release? Even knowing which direction you're leaning helps us decide whether to keep the seed pin permanently or treat it as temporary.Standing offer: happy to re-run the three-level probe (louvain_raw /
_partition/cluster(), separate processes, varied hashseeds) on any candidate branch before you ship it.ThomasB-Github commentedon Jul 29, 2026
Corroborating data point that isolates this to the clustering stage alone, eliminating extraction as a variable:
Holding the graph byte-identical (same
graph.jsoninput, no re-extraction), threecluster(G)invocations in separate processes produced 278, 277, and 276 communities on 0.9.17. After upgrading to 0.9.29 and repeating the experiment: 295, 296, 295. Still non-deterministic on the current release. Windows 11, Python 3.11.Two upstream statements led us to expect otherwise: the
cluster()docstring ("Community IDs are stable across runs") and the reproducibility comment near cluster.py:229 (the #1090 follow-up). The internal seed evidently does not guarantee cross-process reproducibility on this platform.Practical consequence we hit: anything persisted per community id (labels, incremental tooling) breaks between runs. Our workaround is to keep
Gandcommunitiesin one process and pass the membership mapping, not the ids, to downstream tooling. If cross-process reproducibility is not achievable, documenting that (and making report tooling id-agnostic) would save others the same detour.luipa446-cloud commentedon Aug 1, 2026
Independent reproduction on 0.9.29/0.9.31, plus the graspologic-installed measurement offered earlier in this thread but not yet posted, and a mechanism for the residual flap that survives the
PYTHONHASHSEEDpin.Real repository (~5.4k AST nodes / ~7.4k edges), Windows 11, Python 3.12/3.14.
cluster.pyis byte-identical between 0.9.29 and 0.9.31, so this applies to the current release.1. Louvain fallback — confirms the earlier localization
Same graph,
cluster()called once per process, fingerprint = sha256 of the sorted(node_id, community_id)list:PYTHONHASHSEED=0Matches the three-level probe already in this thread. The pin is a complete fix on this path, and it holds end-to-end: two consecutive full refreshes of our pipeline now produce byte-identical
graph.jsonwhere they previously did not.2. Leiden — the pin is not sufficient
Taking up the standing offer to test with graspologic installed. Deliberately in a throwaway virtualenv, since adding graspologic to the working environment silently switches the partitioner and changes what every subsequent refresh produces. graspologic 3.4.4, networkx 3.6.1:
PYTHONHASHSEED=0So Leiden is both worse unpinned than Louvain and still non-deterministic pinned. This corroborates the 0.9.17→0.9.29 data point posted above (278/277/276 → 295/296/295) and extends it: the recommended workaround does not rescue the Leiden path.
3. The residual is leiden's dict iteration order, not its partition
Isolating with the input fingerprinted to prove it never varies between trials:
leiden(stable, random_seed=42, trials=1)on identical sorted input: identical output in 12/12 trials, pinned and unpinned alike. Leiden's assignment is deterministic. Seeding works.PYTHONHASHSEEDis fixed by construction and therefore cannot be the variable —_partition()returns 4/4 identical whilecluster()returns 490, 491, 491, 491.The distinguishing measurement: fingerprinting leiden's returned dict by content versus by key order across 5 in-process calls on identical input:
Same partition every time, different iteration order every time.
cluster()then consumes that order atraw.setdefault(cid, []).append(node), so the grouping handed to the split passes differs per call even though the partition did not.This explains why the earlier relabel-to-int experiment reduced but did not eliminate the flap: int labels fix node-id hashing, but the ordering that varies here is the partitioner's own returned mapping, which no node relabeling touches.
4. What the divergence actually looks like
Diffing two in-process
cluster()runs: the node sets are identical on both sides (68 vs 68 nodes), and the difference is a single split boundary — run 1 keeps one 68-node community whole, runs 2–3 split it 52+16. Calling_split_community()directly on that exact node set returns 1 distinct result across 5 calls, so the split routine itself is deterministic. It is the grouping fed into it that varies.To be explicit about the limit of this: leiden's unstable key order and
cluster()'s order-sensitive consumption of it are both measured. The propagation from that key order to this specific split decision I have not traced end to end, so treat the causal link as strongly supported rather than proven.5. On the candidate fixes
Given the above, option (a) — CLI re-exec with
PYTHONHASHSEED=0— is necessary but not sufficient: it fixes Louvain fully and leaves Leiden non-deterministic, which is arguably worse than today because the failure becomes silent for anyone who has the[leiden]extra installed. If it ships alone, it may be worth having it also warn when graspologic is present.A cheap, targeted alternative that does not depend on the hash seed at all: sort the partitioner's output before consuming it in
cluster()— i.e. iteratesorted(partition.items())rather thanpartition.items()— so downstream grouping cannot inherit the backend's iteration order. That would not fix modularity-tie sensitivity inside the partitioners, but it removes the specific mechanism measured here, and it is order-of-magnitude smaller than a deterministic partitioner.Happy to re-run any of these probes on a candidate branch. The scripts are short — they only import networkx, graspologic, and
graphify.cluster.larya-dot-eu commentedon Aug 11, 2026
Two things: a small-scale corroboration where the
PYTHONHASHSEEDpin fully holds (no residual flap), and a consumer-side workaround that addresses a related problem the seed pin does not.Corroboration — Louvain fallback, ~1k nodes
graphifyy 0.9.17, Python 3.13.12, networkx 3.6.1, Linux. graspologic not installed and not installable here — the
[leiden]extra is gated topython_version < "3.13"— so this is thenx.community.louvain_communitiesfallback path, matching @krishnateja7's environment note.Byte-identical
graph.json(976 nodes / 1956 edges),cluster(G)once per process, fingerprint = sha256 of the sorted(node_id, community_id)list:PYTHONHASHSEEDunseta3235bfade122618b4d55c27965f6aacPYTHONHASHSEED=0de122618de122618de122618de122618Four distinct partitions in four unset runs; four identical ones when pinned. So at this scale the pin is a complete fix — I did not see the residual flap @luipa446-cloud reported at ~5.4k nodes. If that residual is size- or structure-dependent, the gap between ~1k and ~5.4k nodes might be a useful place to bisect.
Worth noting the flap here is small in node terms but not harmless: it moves whole communities in and out of existence (64 ↔ 65), and the two counts are stable attractors rather than noise.
Complementary workaround: cache the partition against a graph fingerprint
PYTHONHASHSEED=0makes a run reproducible, but it does not give community identity across rebuilds. Anyone who attaches meaning to a community — human-written labels, a wiki page per community, review notes — loses that mapping whenever the graph changes at all, because the partition is recomputed from scratch and communities renumber.What worked for us was to stop re-clustering an unchanged graph entirely:
Unchanged graph reuses its exact partition; a changed graph reclusters and says so. Independent of
PYTHONHASHSEED, so it also covers callers whose environment you do not control.For the labels themselves, keying them by community id does not survive renumbering and keying them by a representative node silently mislabels a community that kept its hub while its membership changed. Matching each rebuilt community to the saved one with the highest membership overlap (Jaccard ≥ 0.5, else treat as new and report it) was the first approach that neither drifted nor mislabeled. Communities of ≤ 2 nodes were excluded from matching — peripheral pairs get reattached differently on every run and would otherwise flap forever.
Both together gave fully stable rebuilds across repeated runs.
This is a consumer-side patch on top of
cluster(), so it is not a fix — it just makes the nondeterminism invisible downstream. It is roughly the poor-man's version of #2452 (seedcluster()with a previous partition), and if that lands with an optionalprevious=argument it would replace this entirely and do a better job, since it could reuse the prior partition as a starting point rather than only as a cache hit.proto(cluster): make rustworkx-vendored Leiden the primary clustering…
Compare partition structure, not just the node id set, for staleness
Compare partition structure, not just the node id set, for staleness
omsenjalia commentedon Oct 18, 2026
This looks fixed on the
v8branch by 27096817 (fix(cluster): canonicalise edge endpoints before sorting in _partition). Could a maintainer confirm and close?