Repository navigation
Native graph engine: degree assortativity without numpy (#3036) - #3047
Merged
Merged
Conversation
- graph_engine.degree_assortativity(): single pass over the CSR out-runs
computing the Pearson correlation of (out-degree of source, in-degree of
target) per edge.
- Strict parity with nx.degree_assortativity_coefficient(G).
- Every sum is exact integer arithmetic, so the only rounding is the final
sqrt and division.
- NaN when undefined (no edges, or a degree that never varies), as
networkx returns.
- NetworkRiskSensor._topology_metrics (was _cycle_metrics) runs it in BOTH
modes, keeping the sensor's NaN -> 0.0 storage.
- This also fixes the silent None when networkx is installed without numpy:
networkx's routine imports numpy, which networkx does not install.
- language-crucible: -0.3052 either way; 0.90 ms vs 11.07 ms (nx).
- Registered as strict in tests/tools/graph_parity.py. modularity is now
the only macro metric networkx still computes. Docs updated.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
… now native) Uncapped golden_diff scope: full precision 0 differences (crucible_check --update: no drift); zero dependency exactly 1 -- network_macro/ assortativity None -> -0.3033, the value full precision reports. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
squid-protocol
force-pushed
the
fix/3036-native-assortativity
branch
from
September 14, 2026 22:57
8144d09 to
0644049
Compare
Contributor
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 #3036. Part of #3033 (the native graph engine). Stacked on #3035's PR, which is stacked on #3044 (#3037): this branch carries their commits until they merge. Only the last commit (plus its bless, if any) is this PR's own.
What changed
graph_engine.degree_assortativity(index): one pass over the CSR out-runs, computing the Pearson correlation of (out-degree of source, in-degree of target) per edge.nx.degree_assortativity_coefficient(G)(x="out", y="in", unweighted).sqrtand division.NetworkRiskSensor._topology_metrics()(renamed from Native graph engine: cyclic density (SCC) and articulation points in O(V+E) #3035's_cycle_metrics) runs it in both modes. It keeps the sensor's existing storage: NaN is stored as 0.0, and values are rounded to 4 dp. This replacesnx.degree_assortativity_coefficient.Nonewith networkx but no numpy. networkx's assortativity imports numpy, which networkx does not install, so such a scan lost the metric while believing it ran at full precision. The native one needs neither. A new test runs the sensor withnumpyblocked insys.modules.After this PR, modularity is the only macro metric networkx still computes (#3039).
Measured on language-crucible v1.2.0 (V=2,817, E=1,354; warm, best of 10,
graph_parity.py --db)The prototype matched networkx at the stored 4 dp on all 300 seeded random graphs, including every edgeless graph (NaN in both, so 0.0 stored).
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.network_macro/assortativitywent fromNoneto −0.3033, the same value full precision reports.The zero-dependency fixture is re-blessed in the second commit.
Observation, not changed here
Storing an undefined correlation as
0.0is the pre-existing convention, and #3036 asks to keep it. It reads as "neutral mixing" rather than "not measurable", which is the same shape #3027 fixed for other metrics by usingNone. Changing it would change the definition and both fixtures, so it belongs in a follow-up if wanted.Verification
pytestpasses on the 9 affected suites (387 passed), run as plainpytestfrom outside the repo.nx.degree_assortativity_coefficient, and both modes agreeaudit_check.py: all clear.zero_dependency_mode.md(table, summary and heading; the "assortativity needs numpy" caveat is removed; older-snapshots note), the 02-16 wiki, README, CLAUDE.md, the console banner and the zero-dependency warning.🤖 Generated with Claude Code