Skip to content

Native graph engine: shared CSR graph index + parity/benchmark harness (#3034) - #3042

Merged
squid-protocol merged 2 commits into
mainfrom
feat/3034-csr-graph-index
Sep 14, 2026
Merged

squid-protocol merged 2 commits into
mainfrom
feat/3034-csr-graph-index

Conversation

@squid-protocol

Copy link
Copy Markdown
Owner

Closes #3034. Part of #3033 (the native graph engine). This sub-issue lands first, and the others build on it.

What changed

PageRank is bit-identical, so neither golden master moves

The new version performs the same float operations in the same order:

  • each incoming share is x[u] * w / out_weight[u], summed per node in edge order
  • then alpha * inflow + dangling_share + teleport
  • the same builtin sum is used for the dangling mass and the L1 error

A node nothing imports still gets dangling_share + teleport. That is exactly what the old alpha * sum([]) + … produced, since 0.0 + x == x.

test_pagerank_is_bit_identical_to_the_implementation_it_replaced keeps the old dict-of-lists implementation as a reference and asserts == (not approx) on 25 seeded graphs. crucible_check.py --mode both confirms both fixtures are unchanged.

Benchmark: language-crucible v1.2.0 import graph (V=2,817, E=1,354; warm, best of 15)

time
index build 1.2 ms (once per scan; shared by every later metric)
native PageRank, before (#3027, dict-of-str) 7.0 ms
native PageRank, now 1.85 ms
nx.pagerank (scipy) 2.99 ms (#3033 recorded 4.3 ms on another run)

Parity with nx.pagerank: max |diff| 2.6e-18, identical at the stored 6 dp.

The speed comes from running each per-edge and per-node pass as a C-level map over flat lists, with a scatter over only the nodes that have incoming edges.

Verification

  • pytest passes on test_graph_engine.py, test_uncomputed_graph_metrics.py, test_network_risk_sensor.py, test_edge_data.py and test_api_network_map.py (133 passed). I ran it as plain pytest from outside the repo, which is how CI invokes it and matters for the tests/tools import.
  • audit_check.py: all clear (ruff, format, mypy, dead-key, ast-accuracy).
  • crucible_check.py --mode both against language-crucible v1.2.0: full_precision PASS, zero_dependency PASS. Both golden masters are unchanged, so no bless is needed.

For the follow-up sub-issues

🤖 Generated with Claude Code

#3034)

- gitgalaxy/core/graph_engine.py: GraphIndex, an integer-indexed CSR
  adjacency built once per scan from _resolve_edges(); WorkBudget, the
  deterministic (work-counting, never wall-clock) replacement for
  node-count cutoffs; and PageRank moved onto the index.
- PageRank keeps every float operation and its order, so it is
  bit-identical to the #3027 version (proved on 25 seeded graphs against
  a kept reference copy) and neither golden master moves. It is now
  C-level map passes over flat lists: 1.85 ms on the language-crucible
  graph (V=2,817, E=1,354) vs 7.0 ms before and 2.99 ms for nx.pagerank.
- tests/tools/graph_parity.py: networkx as a test-time oracle, with
  "strict" and "tailored" oracle modes per #3033's tailoring decisions;
  seeded random graphs for pytest, and a CLI that checks parity and
  benchmarks on a real scan's graph (a galaxyscope DB's edge_data).

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@squid-protocol squid-protocol added enhancement New feature, sensor, or structural signature metrics Heuristics, risk exposures, and topological math updates core-engine Modifications to the central physics and parsing engine labels Sep 14, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🐦‍⬛ Muninn Security Scan

✅ No security issues found.

🐦‍⬛ Powered by Muninn · Skald Lab

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@squid-protocol
squid-protocol merged commit db34c9a into main Sep 14, 2026
27 checks passed
@squid-protocol
squid-protocol deleted the feat/3034-csr-graph-index branch September 14, 2026 22:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core-engine Modifications to the central physics and parsing engine enhancement New feature, sensor, or structural signature metrics Heuristics, risk exposures, and topological math updates

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Native graph engine: shared CSR graph index + parity/benchmark harness

1 participant