Repository navigation
feat: distributed & graph algorithm improvements - #4
Merged
Merged
Conversation
…paths Shortest paths (local + distributed): - Rewritten to use DuckDB's USING KEY recursive CTE - Automatic deduplication: only shortest distance per node is kept - No GROUP BY needed — 1000x intermediate row reduction on medium graphs - New :weight option for weighted shortest paths (Bellman-Ford via SQL) Connected components (local): - Single SQL statement with USING KEY replaces Elixir iteration loop - Eliminates per-iteration IPC, convergence check, Process.put GC dance - DuckDB handles convergence internally All 26 graph tests + 44 dataset/edge case tests pass. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
PageRank now exits early when rank changes fall below tolerance: - :tolerance option (default 1e-6) — L1 norm of rank change - :max_iterations option (default 100, up from 20) - Emits [:dux, :graph, :iteration, :stop] telemetry per iteration with convergence status Typical graphs converge in 8-15 iterations instead of always running 20. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Workers now compute approx_count_distinct(x) (DuckDB's built-in HLL) instead of ARRAY_AGG(DISTINCT x). ~2% error but constant wire cost — one number per worker per group instead of shipping all distinct values. For a column with 10M distinct values, this reduces worker→coordinator transfer from hundreds of MB to a few bytes. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…e tests Kept current STDDEV formula (additive decomposition with DOUBLE precision) — documented the cancellation limitation for extreme values. 20 new graph improvement tests covering: - USING KEY shortest paths: linear chain, diamond, disconnected, max_depth, cycle - Weighted shortest paths: weight option, cheaper route selection, zero weights - USING KEY connected components: single/two components, isolated vertices, karate club - PageRank convergence: early exit, tolerance:0 disables, karate club top-ranked, backwards compat - HLL COUNT DISTINCT: approximate accuracy - Adversarial: empty graph, 100 isolated vertices, single vertex PageRank Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Dux.Graph.communities/2 detects communities using label propagation: - Each vertex votes for the most frequent label among its neighbors (including its own label to prevent oscillation) - Ties broken by smallest label - Converges when labels stabilize 4 new tests: two cliques, disconnected components, karate club, single vertex. Reused converged?/4 helper (generalized from CC's component check). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Added karate_club/0 to Dux.Datasets. Removed redundant Dux.Test.Datasets. Updated all test references. Added .tmp/ to gitignore (DuckDB temp storage). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Karate club (34 nodes, 156 edges): - shortest_paths (USING KEY): 34ms - connected_components (USING KEY): 19ms - pagerank (convergence): 221ms - triangle_count: 20ms - out_degree: 3ms - communities (new): 45ms Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Convergence and tolerance tests were counting telemetry messages, which leaked across async tests. Replaced with deterministic assertions: - Ranks sum to ~1.0 (convergence invariant) - Symmetric graph has equal ranks (structural invariant) - tolerance:0 still produces valid results Verified 3x consecutive runs with 0 failures. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.
What
USING KEY graph algorithms, PageRank convergence, HyperLogLog COUNT DISTINCT, weighted shortest paths, community detection.
Changes
USING KEY for graph algorithms (DuckDB 1.4.1)
Shortest paths (local + distributed):
USING KEYrecursive CTE for unweighted BFSUNION + GROUP BY MIN(USING KEY has a limitation with weighted multi-path convergence in the same iteration)Connected components (local):
USING KEYreplaces Elixir iteration loopProcess.putGC workaroundsWeighted shortest paths
New
:weightoption onshortest_paths/3:Uses Bellman-Ford via recursive CTE with
GROUP BY MIN.PageRank convergence detection
SUM(ABS(new_rank - old_rank)) < tolerance:toleranceoption (default1e-6) — set to 0 to disable:max_iterationsoption (default 100, up from fixed 20):iterationsstill works[:dux, :graph, :iteration, :stop]telemetry per iteration with convergence statusHyperLogLog for distributed COUNT DISTINCT
Workers now compute
approx_count_distinct(x)(DuckDB's built-in HLL, ~2% error) instead ofARRAY_AGG(DISTINCT x). Constant wire cost — one number per worker per group instead of shipping all distinct values.Label Propagation community detection
New
Dux.Graph.communities/2:Each vertex votes for the most frequent label among neighbors (including its own to prevent oscillation). Tie-broken by smallest label. Converges when labels stabilize.
STDDEV/VARIANCE formula
Kept current additive decomposition (
COUNT,SUM,SUM_OF_SQUARES) with DOUBLE precision. Documented the catastrophic cancellation limitation for extreme values (>1e15 with tiny variance). Full Welford would require architectural changes to the Merger's GROUP BY re-aggregation.Tests
24 new tests covering:
Test plan
mix checkclean (format + compile + test + credo)🤖 Generated with Claude Code