Repository navigation
Native graph engine: exact hop-count betweenness at every size (#3038) - #3048
Merged
Merged
Conversation
Contributor
- graph_engine.betweenness_centrality(): exact unweighted Brandes on the CSR index. It mirrors networkx step for step (BFS adjacency order, predecessor order, reverse-BFS accumulation, sources in node order, the directed 1/((N-1)(N-2)) rescale), so it is bit-identical to nx.betweenness_centrality(G). Sources with no outgoing import are skipped, and the run is gated by a WorkBudget (PATH_METRICS_WORK_BUDGET). - This replaces nx.betweenness_centrality(G, k=100, weight="weight", seed=42) per #3033's tailoring decisions. Above 500 files that call SAMPLED 100 sources, and it read weight as distance. On language-crucible the sample found 11 nonzero files vs 41 exact and read 14 of the exact top-20 choke points as 0. - Runs in BOTH modes via NetworkRiskSensor._betweenness, so zero-dependency mode gains betweenness, the "cascading state mutation" ranking and the "Cognitive Choke Point" insight. Modularity is now the only networkx metric left. - language-crucible: 1.95 ms vs 1,674 ms for networkx's exact call (and 72 ms for the sampled call it replaces). - Registered as tailored in tests/tools/graph_parity.py. The docs note the definition change for snapshot history. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Uncapped golden_diff scope: exactly 1 difference per mode -- systemic_bottlenecks/cascading_state_mutation, the betweenness x state-mutation ranking: re-ranked in full precision (sampled weighted -> exact hops) and [] -> populated in zero-dependency mode (identical lists). Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> Signed-off-by: Joe Esquibel <[email protected]>
squid-protocol
force-pushed
the
fix/3038-exact-betweenness
branch
from
September 15, 2026 00:05
0fd7a8e to
71da0ae
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #3038. Part of #3033 (the native graph engine). Stacked: #3044 (#3037) → #3046 (#3035) → the #3036 PR → this PR. The branch carries their commits until they merge. Only the last commit, plus its re-bless, is this PR's own.
What changed
graph_engine.betweenness_centrality(index, budget)computes exact, unweighted Brandes betweenness on the CSR index.Bit-identical to
nx.betweenness_centrality(G), the tailored oracle (exact, unweighted, normalized, directed), not merely equal at 6 dp. It mirrors networkx's Brandes pass step for step:1 / ((N-1)(N-2))rescaleA new test asserts
==on 25 seeded graphs. The prototype matched 300/300, plus the crucible graph.Other details:
WorkBudget(PATH_METRICS_WORK_BUDGET, counting edge scans). Past the budget, betweenness isNone, never0.0.NetworkRiskSensor._betweenness()runs it in both modes, replacingnx.betweenness_centrality(G, k=100, weight="weight", seed=42). The networkx builder's centralitytryblock is gone.After this PR, modularity (#3039) is the only metric networkx still computes.
weightread as distance, so an entity import (a stronger coupling) counted as a longer pathOn language-crucible, the sample found 11 files with nonzero betweenness against 41 exact. It read 14 of the exact top-20 choke points as 0: the top-20 lists overlap on only 6 of 20.
betweenness_scorevalues from before and after are not comparable above 500 files. Below 500, they differ only where an entity import changed a shortest path.docs/zero_dependency_mode.mdrecords this under "Older snapshots".Measured on language-crucible v1.2.0 (V=2,817, E=1,354; warm,
graph_parity.py --db)Golden masters
I diffed fresh scans of each mode against the committed fixtures with an uncapped
golden_diff.deep_compare. The scans usedGITGALAXY_DISABLE_GIT_HISTORY=1and the same flags astest_golden_crucible.py. Each mode has exactly 1 difference, and it is the intended one:systemic_bottlenecks/cascading_state_mutation, the betweenness × state-mutation ranking.python/twisted/http.pypython/fastapi/fastapi/routing.pypython/twisted/defer.pypython/twisted/http.pylua/freebsd-src/color.luadockerfile/moby/builder/dockerfile/copy.goabap/abapGit/zabapgit.prog.abaplua/cosmopolitan/all.luaabap/abapGit/zcl_abapgit_ajson.clas.abapabap/abapGit/zabapgit.prog.abap[], because betweenness was never computed there. It is now the same list as full precision.betweenness_scoredoes not appear in the audit JSON, so no other field moved. There is no coordinate ripple: betweenness feeds no mass.Verification
pytestpasses on the 10 affected suites, includingtest_supply_chain_firewall.py(460 passed), run as plainpytestfrom outside the repo.nx.betweenness_centrality, and both modes agreeNoneaudit_check.py: all clear.signal_processor,supply_chain_firewall). Docs updated:zero_dependency_mode.md(table, summary, heading, the rankings and insights that now work without networkx, the definition-change section, older snapshots), the 02-16 wiki (including the stale "k=50 sampling" tradeoff), README, CLAUDE.md, the console banner and the zero-dependency warning.🤖 Generated with Claude Code