Skip to content

Commit eaaf2ea

Browse files
authored
Upgrade Graphina to version 0.4.0-alpha.5 (#24)
1 parent 4139e0b commit eaaf2ea

20 files changed

Lines changed: 1245 additions & 52 deletions

File tree

.github/workflows/web.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,24 @@ jobs:
4242
pattern: onager-${{ env.DUCKDB_VERSION }}-extension-wasm_*
4343
path: wasm-extensions
4444

45+
- name: Vendor DuckDB-Wasm
46+
working-directory: web/vendor-src
47+
run: |
48+
set -euo pipefail
49+
npm ci
50+
npm run bundle
51+
4552
- name: Assemble playground tree
4653
run: |
4754
set -euo pipefail
4855
mkdir -p playground
4956
cp -R web/. playground/
57+
rm -rf playground/vendor-src
58+
mkdir -p playground/vendor/duckdb-wasm
59+
cp web/vendor-src/out/duckdb-browser.mjs \
60+
web/vendor-src/node_modules/@duckdb/duckdb-wasm/dist/duckdb-browser-mvp.worker.js \
61+
web/vendor-src/node_modules/@duckdb/duckdb-wasm/dist/duckdb-mvp.wasm \
62+
playground/vendor/duckdb-wasm/
5063
printf '{"branch": "%s", "commit": "%s"}\n' \
5164
"${GITHUB_REF_NAME}" "${GITHUB_SHA:0:5}" > playground/build-info.json
5265
for platform in wasm_eh wasm_mvp; do

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,7 @@ bug*.md
101101
.codex
102102
.antigravitycli/
103103
.agents/
104+
105+
# Playground vendor build (web/vendor-src)
106+
web/vendor-src/node_modules/
107+
web/vendor-src/out/

docs/guide/community.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,8 @@ order by label, node_id;
112112
```
113113

114114
!!! note "Determinism"
115-
The seed controls the order in which nodes update their labels, but the underlying
116-
implementation currently breaks label ties nondeterministically, so seeded runs can
117-
still differ between sessions.
115+
The seed controls the order in which nodes update their labels, and label ties break
116+
deterministically, so runs with the same seed produce the same partition.
118117

119118
---
120119

@@ -173,9 +172,8 @@ Optional parameters:
173172
- `seed`: Random seed for the node visit order
174173

175174
!!! note "Determinism"
176-
As with label propagation, the seed controls the node visit order, but the underlying
177-
implementation currently breaks ties nondeterministically, so seeded runs can still
178-
differ between sessions.
175+
As with label propagation, the seed controls the node visit order, and ties break
176+
deterministically, so runs with the same seed produce the same partition.
179177

180178
---
181179

docs/guide/parallel.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,14 @@ Optional parameters:
5151
- `tolerance` (default 1e-6): Convergence threshold for early termination
5252
- `directed` (default false): Treat each edge as one-way instead of undirected
5353

54-
The parallel implementation treats every edge as having weight 1.0.
55-
For weighted PageRank, use `onager_ctr_pagerank` with a third `double` column.
54+
Like `onager_ctr_pagerank`, the parallel version accepts an optional third `double` column with edge weights.
55+
When the column is absent, every edge gets weight 1.0.
56+
57+
```sql
58+
select node_id, round(rank, 4) as rank
59+
from onager_par_pagerank((select src, dst, (src + dst)::double as weight from edges))
60+
order by rank desc;
61+
```
5662

5763
---
5864

docs/reference/input-formats.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ select onager_node_in_degree('social', 1);
4747
- `onager_apx_tsp`: Traveling salesman approximation
4848
- `onager_pth_dijkstra`: Shortest paths with nonnegative weights (the weights column is optional)
4949

50-
`onager_ctr_pagerank` also uses a third `double` column as edge weights when it is present, and falls back to weight 1.0 for every edge when it is absent. `onager_par_pagerank` is unweighted. Weight values must not be NULL or NaN, and PageRank additionally rejects negative weights.
50+
`onager_ctr_pagerank` and `onager_par_pagerank` also use a third `double` column as edge weights when it is present, and fall back to weight 1.0 for every edge when it is absent. Weight values must not be NULL or NaN, and PageRank additionally rejects negative weights.
5151

5252
Pass weights like this:
5353
```sql

docs/reference/sql-functions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ The default is `false` for every function, which treats the input edge list as u
126126

127127
| Function | Returns | Description |
128128
|--------------------------------------------|------------------------|----------------------------------|
129-
| `onager_par_pagerank(edges [, damping, iterations, tolerance, directed])` | `node_id, rank` | Parallel PageRank |
129+
| `onager_par_pagerank(edges [+ weights] [, damping, iterations, tolerance, directed])` | `node_id, rank` | Parallel PageRank |
130130
| `onager_par_bfs(edges [, source or sources, directed])` | `[source,] node_id` | Parallel BFS traversal |
131131
| `onager_par_shortest_paths(edges [, source or sources, directed])` | `[source,] node_id, distance` | Parallel shortest paths |
132132
| `onager_par_components(edges)` | `node_id, component` | Parallel connected components |

external/graphina

mkdocs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,4 +176,4 @@ markdown_extensions:
176176

177177
extra_javascript:
178178
- assets/js/mathjax.js
179-
- https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js
179+
- https://cdn.jsdelivr.net/npm/mathjax@3.2.2/es5/tex-mml-chtml.js

onager/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

onager/bindings/functions/parallel.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,20 @@ struct ParallelPageRankBindData : public TableFunctionData {
2020
int64_t iterations = 100;
2121
double tolerance = 1e-6;
2222
bool directed = false;
23+
bool weighted = false;
2324
};
2425
struct ParallelPageRankGlobalState : public GlobalTableFunctionState {
2526
std::mutex input_mutex;
2627
std::vector<int64_t> src_nodes, dst_nodes, result_nodes;
27-
std::vector<double> result_ranks;
28+
std::vector<double> weights, result_ranks;
2829
idx_t output_idx = 0; bool computed = false;
2930
idx_t MaxThreads() const override { return 1; }
3031
};
3132

3233
static unique_ptr<FunctionData> ParallelPageRankBind(ClientContext &ctx, TableFunctionBindInput &input, vector<LogicalType> &rt, vector<string> &nm) {
3334
auto bd = make_uniq<ParallelPageRankBindData>();
3435
CheckInt64Input(input, "onager_par_pagerank");
36+
bd->weighted = input.input_table_types.size() >= 3 && input.input_table_types[2] == LogicalType::DOUBLE;
3537
for (auto &kv : input.named_parameters) {
3638
if (kv.first == "damping") bd->damping = GetRequiredParam<double>("onager_par_pagerank", "damping", kv.second);
3739
if (kv.first == "iterations") bd->iterations = GetNonNegativeParam("onager_par_pagerank", "iterations", kv.second);
@@ -44,22 +46,26 @@ static unique_ptr<FunctionData> ParallelPageRankBind(ClientContext &ctx, TableFu
4446
}
4547
static unique_ptr<GlobalTableFunctionState> ParallelPageRankInitGlobal(ClientContext &ctx, TableFunctionInitInput &input) { return make_uniq<ParallelPageRankGlobalState>(); }
4648
static OperatorResultType ParallelPageRankInOut(ExecutionContext &ctx, TableFunctionInput &data, DataChunk &input, DataChunk &output) {
49+
auto &bd = data.bind_data->Cast<ParallelPageRankBindData>();
4750
auto &gs = data.global_state->Cast<ParallelPageRankGlobalState>();
4851
std::lock_guard<std::mutex> lock(gs.input_mutex);
49-
AppendInt64Edges(input, gs.src_nodes, gs.dst_nodes, "onager_par_pagerank");
52+
if (bd.weighted) {
53+
AppendWeightedEdges(input, gs.src_nodes, gs.dst_nodes, gs.weights, "onager_par_pagerank");
54+
} else {
55+
AppendInt64Edges(input, gs.src_nodes, gs.dst_nodes, "onager_par_pagerank");
56+
}
5057
ONAGER_SET_CARDINALITY(output, 0); return OperatorResultType::NEED_MORE_INPUT;
5158
}
5259
static OperatorFinalizeResultType ParallelPageRankFinal(ExecutionContext &ctx, TableFunctionInput &data, DataChunk &output) {
5360
auto &bd = data.bind_data->Cast<ParallelPageRankBindData>(); auto &gs = data.global_state->Cast<ParallelPageRankGlobalState>();
5461
std::lock_guard<std::mutex> lock(gs.input_mutex);
5562
if (!gs.computed) {
5663
if (gs.src_nodes.empty()) { gs.computed = true; ONAGER_SET_CARDINALITY(output, 0); return OperatorFinalizeResultType::FINISHED; }
57-
// graphina's pagerank_parallel ignores edge weights, so no weights are passed here.
58-
// Weighted PageRank is available through onager_ctr_pagerank.
59-
int64_t nc = ::onager::onager_compute_pagerank_parallel(gs.src_nodes.data(), gs.dst_nodes.data(), gs.src_nodes.size(), nullptr, 0, bd.damping, bd.iterations, bd.tolerance, bd.directed, nullptr, nullptr);
64+
const double *w = gs.weights.empty() ? nullptr : gs.weights.data();
65+
int64_t nc = ::onager::onager_compute_pagerank_parallel(gs.src_nodes.data(), gs.dst_nodes.data(), gs.src_nodes.size(), w, gs.weights.size(), bd.damping, bd.iterations, bd.tolerance, bd.directed, nullptr, nullptr);
6066
if (nc < 0) throw InvalidInputException("Parallel PageRank failed: " + GetOnagerError());
6167
gs.result_nodes.resize(nc); gs.result_ranks.resize(nc);
62-
int64_t rc = ::onager::onager_compute_pagerank_parallel(gs.src_nodes.data(), gs.dst_nodes.data(), gs.src_nodes.size(), nullptr, 0, bd.damping, bd.iterations, bd.tolerance, bd.directed, gs.result_nodes.data(), gs.result_ranks.data());
68+
int64_t rc = ::onager::onager_compute_pagerank_parallel(gs.src_nodes.data(), gs.dst_nodes.data(), gs.src_nodes.size(), w, gs.weights.size(), bd.damping, bd.iterations, bd.tolerance, bd.directed, gs.result_nodes.data(), gs.result_ranks.data());
6369
if (rc != nc) throw InvalidInputException("Parallel PageRank failed: " + GetOnagerError());
6470
gs.computed = true;
6571
}

0 commit comments

Comments
 (0)