Skip to content

fix(series): Reject directed graphs in cluster_leiden() again - #2

Closed
krlmlr wants to merge 1 commit into
claude/f2-lad-time-limitfrom
claude/f1-leiden-directed
Closed

krlmlr wants to merge 1 commit into
claude/f2-lad-time-limitfrom
claude/f1-leiden-directed

Conversation

@krlmlr

@krlmlr krlmlr commented Oct 18, 2026

Copy link
Copy Markdown
Owner

Draft, do not merge: review vehicle for a fix collected for the series rebuild on main-fwd-build. Merging would move main-green, which the series loop owns.

This is the second of three stacked review vehicles. It is based on claude/f2-lad-time-limit (#1) and was rebased onto it without conflicts, so its diff shows only this fix.

What it changes

Since igraph 1.0 the C core accepts directed graphs, so cluster_leiden() returned a membership for a directed graph without any warning. The wrapper passes no in-weights and scales the resolution for undirected modularity, so it effectively optimized undirected modularity at twice the resolution, and the reported $quality disagreed with modularity().

cluster_leiden() now raises the error that igraph 2.3.4 raises for directed graphs ("Leiden algorithm is only implemented for undirected graphs."). Proper directed support would need the in-weights exposed and the resolution scaled by the edge count, which is beyond a fix.

This reverses the last sentence of the corrected message proposed for series commit a7a553a (see the third PR, #3), which says that cluster_leiden() now runs on a directed graph. The rebuild must either adjust that message or fold this fix into that commit.

Tests

The branch adds three tests to tests/testthat/test-community.R: they pin the rejection of directed graphs and, on undirected graphs, the agreement of $quality with modularity(). The package was built and installed from the tip of the whole chain (head of the third PR, which includes this branch) into a scratch library, and test-community.R was run against the installed package with NOT_CRAN=true: 37 tests, 355 expectations, 0 failures, 0 errors, 0 skips. air format --check is clean on all changed R files.

Provenance

Made by a Claude subsession: https://claude.ai/code/session_015GouVEqbVWVYs6hH8zvrRc


Generated by Claude Code

Since the C core accepts directed graphs,
`cluster_leiden()` returned a membership for them without a warning.
It passed no in-weights and scaled the resolution for undirected modularity,
so it effectively optimized undirected modularity at twice the resolution,
and its `$quality` disagreed with `modularity()`.
It now raises the error that igraph 2.3.4 raises.
Proper directed support would need the in-weights exposed
and the resolution scaled by the edge count.

The tests pin the rejection and,
on undirected graphs, the agreement of `$quality` with `modularity()`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015GouVEqbVWVYs6hH8zvrRc

krlmlr commented Oct 18, 2026

Copy link
Copy Markdown
Owner Author

Moved to igraph#2991.


Generated by Claude Code

@krlmlr krlmlr closed this Oct 18, 2026
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