Skip to content

fix(cluster): honor --resolution on the community split passes - #2388

Open
keith-oak wants to merge 1 commit into
Graphify-Labs:v8from
keith-oak:fix/cluster-split-resolution
Open

keith-oak wants to merge 1 commit into
Graphify-Labs:v8from
keith-oak:fix/cluster-split-resolution

Conversation

@keith-oak

Copy link
Copy Markdown

_split_community() calls _partition() without forwarding resolution, so it always re-partitions at the default 1.0. cluster(resolution=...) (the --resolution flag added in 2d783e5) therefore applies to the top-level partition but is silently dropped by both split passes:

  • the oversized-community split (cluster.py:214)
  • the cohesion re-split (cluster.py:223)

So graphify build --resolution 0.5 partitions the graph at 0.5, then re-partitions its largest communities at 1.0 — the opposite granularity to the one requested.

Change

Thread cluster()'s resolution through to both call sites and give _split_community() a resolution: float = 1.0 parameter.

Default behaviour is unchanged — the default is 1.0 either way, which is what the split passes were already hardcoding. Only runs that pass an explicit --resolution change.

Tests

Two tests in tests/test_cluster.py, both verified to fail without the fix:

  • test_split_community_forwards_resolution_to_partition — asserts the kwarg reaches _partition
  • test_cluster_forwards_resolution_to_split_passes — end-to-end through cluster() on a graph that trips the oversized-split path

Full suite: 3904 passed, 36 skipped. Two failures on this branch are pre-existing on a clean v8 checkout and unrelated (test_ollama_retry_cap.py needs the openai extra; test_labeling.py::test_label_communities_batches_when_over_batch_size asserts a batch completion order).

@graphify-labs graphify-labs Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks safe to merge — no coupling regressions and no blocking issues, checked against the code graph (not a self-assessment).

Graphify reviewed this change.

Looks safe to merge — no coupling regressions and no blocking issues, checked against the code graph (not a self-assessment).


Graphify review — findings

This PR threads the resolution parameter through the community-splitting logic in graphify/cluster.py. Previously _split_community always ran its secondary Leiden partition with the default resolution of 1.0; now cluster() passes its own resolution value down to both the oversized-community and low-cohesion split passes, and _split_community forwards it to _partition. Two new tests verify that the resolution is forwarded from _split_community to _partition and from cluster into the split passes.

No blocking issues surfaced.

Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 363 functions depend on the 38 functions this change touches.

Health — this change adds coupling hotspots:

  • worse: cluster() — 61 callers, 3 callees

Verification — 363 functions in the blast radius were not formally verified this run (proofs are advisory here).

Gate & verification

graphify gate

PASS — objectively clean (no health regressions, tests not run — proofs not run this pass (advisory)). Grounded, not self-assessed.

Advisory (not blocking):

  • verification_scope: 210 function(s) in the blast radius were not formally verified this run

· 1 more finding(s) on lines outside this diff (see the check run).

@keith-oak
keith-oak force-pushed the fix/cluster-split-resolution branch from ccc840e to 14f8eb3 Compare September 2, 2026 22:58

@graphify-labs graphify-labs Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Graphify reviewed this change.

Looks safe to merge — no coupling regressions and no blocking issues, checked against the code graph (not a self-assessment).

Formal verification. 2 change(s) tested, no difference found (not proven).


Graphify review — findings

Propagates the caller's resolution into _split_community so the oversized- and low-cohesion-community split passes re-run Leiden at the same resolution cluster used for the whole graph, instead of hardcoding 1.0. Adds tests asserting _split_community forwards its resolution to _partition and that cluster passes --resolution through to both split passes.

No blocking issues surfaced.

Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 472 functions depend on the 49 functions this change touches.

Health — this change adds coupling hotspots:

  • new: _rebuild_code() — 113 callers, 50 callees
  • new: dispatch_command() — 2 callers, 123 callees
  • new: _make_graph() — 32 callers, 6 callees
  • new: cluster() — 62 callers, 3 callees
  • new: run_pipeline() — 8 callers, 13 callees
  • new: make_inputs() — 14 callers, 5 callees
  • new: suggest_questions() — 11 callers, 4 callees
  • new: watch() — 5 callers, 7 callees
  • …and 11 more — each is listed as a finding

Verification — 472 functions in the blast radius were not formally verified this run (proofs are advisory here).

Gate & verification

graphify gate

PASS — objectively clean (no health regressions, tests not run — proofs not run this pass (advisory)). Grounded, not self-assessed.

Advisory (not blocking):

  • verification_scope: 278 function(s) in the blast radius were not formally verified this run

Formal verification

No difference found (not proven): No behavior difference found in cluster (not a proof).

The verifier ran both versions of cluster on many inputs and saw identical behavior every time. Strong evidence the change is safe, but evidence, not a proof.

Guarantee: Empirical: differential testing (both versions run on many generated inputs). A divergence on an untested input remains possible, so this is 'no counterexample found', not 'proven equivalent'.

Note: An input the sampler did not try could still differ.

No difference found (not proven): No behavior difference found in \_split\_community (not a proof).

The verifier ran both versions of \_split\_community on many inputs and saw identical behavior every time. Strong evidence the change is safe, but evidence, not a proof.

Guarantee: Empirical: differential testing (both versions run on many generated inputs). A divergence on an untested input remains possible, so this is 'no counterexample found', not 'proven equivalent'.

Note: An input the sampler did not try could still differ.

· 19 more finding(s) on lines outside this diff (see the check run).

_split_community() called _partition() with the default resolution of 1.0,
so --resolution applied to the top-level partition but was silently dropped
by both split passes (the oversized-community split and the cohesion
re-split). A run with --resolution 0.5 could therefore have its large
communities re-partitioned at 1.0, contradicting the flag.

Thread cluster()'s resolution through to both call sites. Default behaviour
is unchanged (1.0 either way); only explicit --resolution runs differ.
@neo1777

neo1777 commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

I measured this PR's effect on two real graphs, in case it helps the review.

Setup

Mean number of communities (full cluster() output, 12 seeds), graphify's package:

resolution 0.25 0.5 1.0 2.0 4.0 8.0
v8, Leiden 181.1 159.8 151.7 182.7 209.1 193.8
this PR, Leiden 45.3 92.5 151.7 315.5 509.8 473.0
v8, Louvain 182.9 164.7 151.2 181.6 202.5 186.5
this PR, Louvain 49.0 96.8 151.2 311.6 496.1 439.3

(Leiden = graspologic-native 1.3.1; Louvain = the networkx fallback, i.e. an install without the leiden extra.)

On v8 the result barely follows --resolution, and 0.25 gives more communities than 1.0. The first pass responds as expected (11.6 communities at 0.25 with Leiden), but the split passes then re-partition those coarse, low-cohesion communities at 1.0. With this PR the count rises with the resolution up to about 4, then stops rising: at 8 it is 7% (Leiden, within the seed noise) and 11% (Louvain) below the value at 4. I haven't isolated why. At 1.0 the two versions are identical, as the description says.

On the smaller graph the two versions are identical at resolution 2.8 and above, where no split pass runs. Below 1.0 this PR makes the output coarser in a specific way: the number of communities changes little (21–24 between 0.5 and 1.0, 17 at 0.25), while the largest community grows, from 77 to 97 to 298 nodes at 1.0, 0.5 and 0.25 (Leiden, 12-seed means; 312 with Louvain at 0.25).

One point for the review: the 25% bound. The cluster() docstring says "Oversized communities (> 25% of graph nodes, min 10) are split by running a second Leiden pass on the subgraph". With this PR that pass runs at the low resolution too, and can leave a community above 25%. In a single run with graphify's seed (42), at 0.25:

  • on the smaller graph the oversize pass splits a 264-node community into 3 pieces, and the cohesion pass then returns the largest, 230 of 626 nodes, in one piece (Louvain: 362 into 3, then 348 in one piece); the bound is 156;
  • on graphify's package the largest community is 959 of 3,182 with Leiden (bound 795); with Louvain it stays under, at 591.

On v8 the largest community stays under 25% on both graphs at every resolution I ran (at 0.25, Leiden: 39 and 76). Either the oversize pass keeps the default resolution, as on v8, or the docstring says the bound may not hold at an explicit low resolution. Your and keith-oak's call.

Scripts, graphs and results, with a run.sh that regenerates these numbers: https://gist.github.com/neo1777/9b68c8c24b553af37396781fe1f81da4

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants