Skip to content

Zero-dependency mode: native betweenness/closeness and repo-topology metrics (follow-up to #3027) #3031

Closed as not planned

Description

@squid-protocol

Context

#3027 made zero-dependency mode compute PageRank natively. _pagerank() in network_risk_sensor.py matches nx.pagerank to below 1e-15 on the self-scan and language-crucible graphs. Every metric that is still not computed is now recorded as None rather than a 0.0 placeholder. Without networkx, that leaves:

Metric Why it was left out of #3027 Native feasibility
betweenness_score networkx samples k=100 nodes with seed=42 above 500 nodes. A native version would have to reproduce that exact random sample to match. Brandes is O(V·E) and exact for ≤500 nodes. Above 500 there's a choice: match nx's sampler, or use exact Brandes in both modes, which changes full precision.
closeness_score Straightforward BFS, but it is bypassed above 1,500 nodes in both modes today. Exact and cheap for ≤1,500 nodes (V BFS runs).
network_cyclic_density — Tarjan SCC: exact, O(V+E).
network_articulation_points — Tarjan/Hopcroft on the undirected view: exact, O(V+E).
network_assortativity — Closed-form over the degree pairs of edges; exact. It must match nx.degree_assortativity_coefficient's directed out→in convention.
network_avg_path_length — BFS over the largest undirected component; exact. nx skips it above 5,000 nodes.
network_modularity Louvain with seed=42; matching it natively means reproducing nx's Louvain. Hard to match exactly. Probably leave it None.

Ask

Implement the exact-and-cheap ones natively, following the #3027 pattern:

  1. a pure-Python function
  2. a parity test against networkx on random graphs
  3. the zero-dependency golden-master diff, scoped

That covers cyclic density, articulation points, assortativity, avg path length, and closeness ≤1,500. Decide betweenness separately, since matching nx's sampler vs. exact Brandes is a design call. Update docs/zero_dependency_mode.md as each one lands.

Filed as the follow-up agreed when #3027 was scoped.

Activity

  1. added
    enhancement
    metrics
    on Sep 14, 2026
  2. squid-protocol commented on Sep 14, 2026

    @squid-protocol
    OwnerAuthor

    Superseded by #3033: the decision is now to remove networkx from the runtime entirely (native implementations in both modes, networkx kept only as a test-time oracle). Its scope is covered by the epic's sub-issues.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementmetrics

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions