feat(graph-algos): extract page_rank and god_nodes to cognicode-graph-algos (PR #2b)#22
Merged
Merged
Conversation
Add cognicode-graph-algos to workspace.dependencies in /Cargo.toml and as a direct dependency in cognicode-core/Cargo.toml with the petgraph-adapter feature enabled. This establishes the bridge from cognicode-core (which owns CallGraphProjection) to cognicode-graph-algos (which provides the WASM-compilable algorithm implementations).
Replace the stub implementation with documentation explaining that the actual impl GraphBuilder for CallGraphProjection lives in cognicode-core (where the type is defined). This module exists only to validate that the feature flag compiles correctly and to serve as a placeholder for future PETGRAPH-specific adapters.
Implement the GraphBuilder trait for CallGraphProjection in cognicode-core (where the type lives). The impl extracts adjacency structure from the underlying StableGraph using petgraph visitor traits (NodeIndexable, EdgeRef). This enables the delegation from GraphAnalytics::page_rank and GraphAnalytics::god_nodes to the pure algorithm functions in cognicode-graph-algos.
…lgos Replace the inline PageRank and god_nodes algorithm bodies in GraphAnalyticsService with delegation to cognicode-graph-algos. page_rank: - Uses CallGraphProjection::build_adjacency() to get (in_neighbors, out_degree) - Calls cognicode_graph_algos::page_rank() with the raw slices - Maps usize results back to SymbolId via projection.id_to_index() god_nodes: - Reuses the delegated page_rank (unchanged signature) - Translates SymbolId -> usize for cognicode_graph_algos::god_nodes() - Translates results back to SymbolId Public API of both methods is byte-identical (same signatures, same error behavior). All existing tests pass without modification. Per ADR-048, cognicode-graph-algos is the single source of truth for graph algorithms; cognicode-core delegates without reimplementing.
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.
Summary
Extract the inline PageRank and god_nodes algorithm bodies from into , delegating from core to the WASM-compilable algorithm crate.
Changes
Dependencies
Core Changes
GraphBuilder impl (): Implemented trait for using petgraph visitor traits (, )
Algorithm delegation ():
Adapter Stub
Updated to document that the actual lives in cognicode-core.
Validation
running 17 tests
test adapters::json_graph::tests::dangling_edge_ignored ... ok
test adapters::json_graph::tests::three_node_cycle ... ok
test adapters::json_graph::tests::empty_graph_yields_empty_adjacency ... ok
test algorithms::god_nodes::tests::percentile_0_returns_all ... ok
test algorithms::god_nodes::tests::empty_scores_returns_empty ... ok
test algorithms::god_nodes::tests::percentile_1_returns_top_only ... ok
test algorithms::god_nodes::tests::percentile_95_returns_top_5 ... ok
test algorithms::god_nodes::tests::percentile_clamped ... ok
test algorithms::god_nodes::tests::sort_descending_by_score ... ok
test algorithms::god_nodes::tests::tie_breaking_by_id_ascending ... ok
test algorithms::page_rank::tests::cycle_mass_conservation ... ok
test algorithms::page_rank::tests::disconnected_components ... ok
test algorithms::page_rank::tests::deterministic_across_runs ... ok
test algorithms::page_rank::tests::empty_graph_returns_empty_map ... ok
test algorithms::page_rank::tests::self_loop_only ... ok
test algorithms::page_rank::tests::single_node_returns_one ... ok
test algorithms::page_rank::tests::star_center_outranks_leaves ... ok
test result: ok. 17 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
running 1 test
test crates/cognicode-graph-algos/src/graph_builder.rs - graph_builder::GraphBuilder (line 22) ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
all doctests ran in 0.29s; merged doctests compilation took 0.29s — 17 tests pass
running 16 tests
test application::services::graph_analytics::tests::god_nodes_empty_graph_returns_empty_vec ... ok
test application::services::graph_analytics::tests::all_simple_paths_empty_when_symbols_missing ... ok
test application::services::graph_analytics::tests::condensation_dag_returns_n_singletons ... ok
test application::services::graph_analytics::tests::condensation_cycle_collapses_into_single_component ... ok
test application::services::graph_analytics::tests::god_nodes_single_node_returns_that_node ... ok
test application::services::graph_analytics::tests::all_simple_paths_finds_three_paths_in_diamond ... ok
test application::services::graph_analytics::tests::page_rank_empty_graph_returns_empty_map ... ok
test application::services::graph_analytics::tests::page_rank_dag_assigns_higher_score_to_root ... ok
test application::services::graph_analytics::tests::feedback_arc_set_acyclic_returns_empty ... ok
test application::services::graph_analytics::tests::all_simple_paths_respects_max_hops ... ok
test application::services::graph_analytics::tests::feedback_arc_set_cycle_returns_at_least_one_edge ... ok
test application::services::graph_analytics::tests::feedback_arc_set_three_cycle ... ok
test application::services::graph_analytics::tests::god_nodes_finds_highly_called_symbol ... ok
test application::services::graph_analytics::tests::transitive_reduction_cycle_keeps_all_edges ... ok
test application::services::graph_analytics::tests::transitive_reduction_acyclic_diamond ... ok
test application::services::graph_analytics::tests::transitive_reduction_dag_drops_implied_edges ... ok
test result: ok. 16 passed; 0 failed; 0 ignored; 0 measured; 1388 filtered out; finished in 0.00s — 16 tests pass
Public API Preservation
and have byte-identical signatures:
All existing tests pass without modification.
ADR-048 Compliance
Per ADR-048 (WASM graph transforms architecture), is the single source of truth for graph algorithms. cognicode-core delegates without reimplementing. The WASM-compilable crate compiles cleanly to (proven by spike per engram obs-2856).
Parent PRs: #20 (skeleton), #21 (CI removal)
Next: PR #3 — cognicode-graph-wasm bindgen shim