Repository navigation
Native graph engine: shared CSR graph index + parity/benchmark harness (#3034) - #3042
Merged
Merged
Conversation
#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]>
Contributor
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
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 #3034. Part of #3033 (the native graph engine). This sub-issue lands first, and the others build on it.
What changed
gitgalaxy/core/graph_engine.py(new, stdlib only):GraphIndexis an integer-indexed CSR adjacency. Out-runs and in-runs are kept in input edge order, alongside weight arrays and each node's total out-weight.NetworkRiskSensor._graph_index()builds it once per scan from_resolve_edges(), in both modes.WorkBudget/WorkBudgetExceededreplace node-count cutoffs with a deterministic budget, which the Native graph engine: shared CSR graph index + parity/benchmark harness #3034 revision on Native graph engine: replace networkx with a stdlib-only implementation (zero-dependency, exact parity, faster) #3033 asked for. An algorithm charges the work it actually does, or an upper bound such as V×(V+E). It never uses wall-clock time, which would make the golden masters flaky. A metric past its budget isNone, never0.0. Nothing uses it yet; Native graph engine: closeness at every size + directed average path length #3037 is its first consumer.pagerank(index)is the Zero-dependency mode: networkx metrics that were never computed read as 0.0 outside the DB (false 'Containment' insight, 0.0 macro table, HITL never fires) #3027 PageRank moved onto the index.network_risk_sensor.py:_pagerankis removed._native_pagerank(index)now reads the shared index.tests/tools/graph_parity.py(new): the parity and benchmark harness.strict: networkx's own call, for metrics whose definition GitGalaxy keepstailored: networkx computing the new definition chosen on Native graph engine: replace networkx with a stdlib-only implementation (zero-dependency, exact parity, faster) #3033python tests/tools/graph_parity.py --db <scan>_galaxy_master.dbchecks parity on a real scan's graph (itsedge_datatable, Persist the dependency graph edge list (enables neighborhood/interaction-level risk hypotheses) #2992) and benchmarks native against networkx, warm and best-of-N. It exits 1 on any disagreement.PageRank is bit-identical, so neither golden master moves
The new version performs the same float operations in the same order:
x[u] * w / out_weight[u], summed per node in edge orderalpha * inflow + dangling_share + teleportsumis used for the dangling mass and the L1 errorA node nothing imports still gets
dangling_share + teleport. That is exactly what the oldalpha * sum([]) + …produced, since0.0 + x == x.test_pagerank_is_bit_identical_to_the_implementation_it_replacedkeeps the old dict-of-lists implementation as a reference and asserts==(not approx) on 25 seeded graphs.crucible_check.py --mode bothconfirms both fixtures are unchanged.Benchmark: language-crucible v1.2.0 import graph (V=2,817, E=1,354; warm, best of 15)
nx.pagerank(scipy)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
mapover flat lists, with a scatter over only the nodes that have incoming edges.Verification
pytestpasses ontest_graph_engine.py,test_uncomputed_graph_metrics.py,test_network_risk_sensor.py,test_edge_data.pyandtest_api_network_map.py(133 passed). I ran it as plainpytestfrom outside the repo, which is how CI invokes it and matters for thetests/toolsimport.audit_check.py: all clear (ruff, format, mypy, dead-key, ast-accuracy).crucible_check.py --mode bothagainst 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
graph_parity.METRICS, usingtailoredwhere Native graph engine: replace networkx with a stdlib-only implementation (zero-dependency, exact parity, faster) #3033 changed the definition. They readGraphIndexand useWorkBudgetin place of the V>1500 and V>5000 cutoffs.🤖 Generated with Claude Code