Skip to content

Commit

Permalink
first take for wasm (Pometry#883)
Browse files Browse the repository at this point in the history
* first take for wasm

* rename raphtory::graph_loader to raphtory_io::graph_loader

* fix python module compilation issue

* fix various tests that depend on csv add Graph is JS land

* managed to add edges and vertices into raphtory from Javascript

* actually push the wasm layer for graph

* fix addVertex and addEdge to take either String or numbers

* some sanity is revealed

* attempt to return Vertex from rust when calling neighbours

* neighbours finally works

* break appart the various bits needed for wasm

* added edges support and window

* added a bit of extra logging to check why in_degree fails

* added support for showing stack traces

* add stuff back missed from the rebase

* wasm POC works fine, next stop properties

* remove the www submodule

* add www as a folder not submodule

* rename www to example

* added properties for vertices and edges

* move the benches into a separate project

* setup benchmark workflor for raphtory-benchmark subproject

* changes as per review

* fix the docs for raphtory-io

* fix the docs running the CsvLoader

* Hello Raphtory in index.html
  • Loading branch information
fabianmurariu authored May 16, 2023
1 parent 834a42c commit c013a96
Show file tree
Hide file tree
Showing 55 changed files with 5,334 additions and 401 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
- name: Run benchmark (Unix)
run: |
set -o pipefail
cargo +nightly bench --bench base -- --output-format=bencher | tee benchmark-result.txt
cargo +nightly bench --bench base -p raphtory-benchmark -- --output-format=bencher | tee benchmark-result.txt
- name: Store benchmark result if repo is master
if: github.ref == 'refs/heads/master'
uses: benchmark-action/github-action-benchmark@v1
Expand Down
69 changes: 42 additions & 27 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
[workspace]
members = [
"raphtory",
"raphtory-io",
"raphtory-benchmark",
"examples/rust",
"python"
]
Expand All @@ -10,7 +12,7 @@ default-members = ["raphtory"]
version = "0.3.1"
documentation = "https://raphtory.readthedocs.io/en/latest/"
repository = "https://github.com/Raphtory/raphtory/"
license = "AGPL-3.0-only"
license = "GPL-3.0"
readme = "README.md"
homepage = "https://github.com/Raphtory/raphtory/"
keywords = ["graph", "temporal-graph", "temporal"]
Expand Down
1 change: 1 addition & 0 deletions examples/rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ keywords = ["graph", "temporal-graph", "temporal", "examples"]

[dependencies]
raphtory = {path = "../../raphtory"}
raphtory-io = {path = "../../raphtory-io"}
chrono = "0.4"
regex = "1"
serde = { version = "1", features = ["derive", "rc"] }
Expand Down
2 changes: 1 addition & 1 deletion examples/rust/src/bin/btc/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use chrono::{DateTime, Utc};
use raphtory::core::tgraph::TemporalGraph;
use raphtory::core::utils;
use raphtory::core::{Direction, Prop};
use raphtory::graph_loader::source::csv_loader::CsvLoader;
use raphtory_io::graph_loader::source::csv_loader::CsvLoader;
use regex::Regex;
use serde::Deserialize;
use std::fs::File;
Expand Down
2 changes: 1 addition & 1 deletion examples/rust/src/bin/crypto/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use raphtory::algorithms::generic_taint::generic_taint;
use raphtory::algorithms::pagerank::unweighted_page_rank;
use raphtory::db::view_api::layer::LayerOps;
use raphtory::db::view_api::*;
use raphtory::graph_loader::example::stable_coins::stable_coin_graph;
use raphtory_io::graph_loader::example::stable_coins::stable_coin_graph;
use serde::Deserialize;
use std::env;
use std::time::Instant;
Expand Down
2 changes: 1 addition & 1 deletion examples/rust/src/bin/healthcheck/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ mod test {
view_api::*,
view_api::{internal::GraphViewInternalOps, GraphViewOps},
};
use raphtory::graph_loader::source::csv_loader::CsvLoader;
use raphtory_io::graph_loader::source::csv_loader::CsvLoader;
use serde::de::DeserializeOwned;

trait TestEdge {
Expand Down
2 changes: 1 addition & 1 deletion examples/rust/src/bin/hulongbay/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use raphtory::algorithms::triangle_count::triangle_counting_fast;
use raphtory::core::{Direction, Prop};
use raphtory::db::graph::Graph;
use raphtory::db::view_api::*;
use raphtory::graph_loader::source::csv_loader::CsvLoader;
use raphtory_io::graph_loader::source::csv_loader::CsvLoader;
use regex::Regex;
use serde::Deserialize;
use std::time::Instant;
Expand Down
2 changes: 1 addition & 1 deletion examples/rust/src/bin/lotr/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use raphtory::core::utils;
use raphtory::core::Prop;
use raphtory::db::graph::Graph;
use raphtory::db::view_api::*;
use raphtory::graph_loader::source::csv_loader::CsvLoader;
use raphtory_io::graph_loader::source::csv_loader::CsvLoader;
use serde::Deserialize;
use std::path::PathBuf;
use std::{env, path::Path, time::Instant};
Expand Down
6 changes: 6 additions & 0 deletions js-raphtory/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/target
**/*.rs.bk
Cargo.lock
bin/
pkg/
wasm-pack.log
37 changes: 37 additions & 0 deletions js-raphtory/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[package]
name = "js-raphtory"
version = "0.1.0"
authors = ["Fabian Murariu <[email protected]>"]
edition = "2018"

[lib]
crate-type = ["cdylib", "rlib"]

[features]
default = ["console_error_panic_hook"]

[dependencies]
wasm-bindgen = "0.2.63"
js-sys = "0.3"
chrono = "0.4"
raphtory = { path = "../raphtory" }

# The `console_error_panic_hook` crate provides better debugging of panics by
# logging them with `console.error`. This is great for development, but requires
# all the `std::fmt` and `std::panicking` infrastructure, so isn't great for
# code size when deploying.
console_error_panic_hook = { version = "0.1.7", optional = true }

# `wee_alloc` is a tiny allocator for wasm that is only ~1K in code size
# compared to the default allocator's ~10K. It is slower than the default
# allocator, however.
wee_alloc = { version = "0.4.5", optional = true }

[dev-dependencies]
wasm-bindgen-test = "0.3.35"

[profile.release]
# Tell `rustc` to optimize for small code size.
opt-level = "s"

[workspace]
3 changes: 3 additions & 0 deletions js-raphtory/example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
dist
./bin
5 changes: 5 additions & 0 deletions js-raphtory/example/.travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
language: node_js
node_js: "10"

script:
- ./node_modules/.bin/webpack
5 changes: 5 additions & 0 deletions js-raphtory/example/bootstrap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// A dependency graph that contains any wasm must all be imported
// asynchronously. This `bootstrap.js` file does the single async import, so
// that no one else needs to worry about it again.
import("./index.js")
.catch(e => console.error("Error importing `index.js`:", e));
11 changes: 11 additions & 0 deletions js-raphtory/example/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Hello Raphtory!</title>
</head>
<body>
<noscript>This page contains webassembly and javascript content, please enable javascript in your browser.</noscript>
<script src="./bootstrap.js"></script>
</body>
</html>
39 changes: 39 additions & 0 deletions js-raphtory/example/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { Graph } from "js-raphtory";

const g = new Graph();

g.addVertex(2n, "Bob");
g.addVertex(3n, "Alice");
g.addVertex(12n, "Charlie");

// both src and dst must be the same type
g.addEdge(9n, "Bob", "Alice", { relation: "knows" });

const bob = g.getVertex("Bob");
const alice = g.getVertex("Alice");

function printVertex(v) {

console.log(
{
id: v.id(),
name: v.name(),
neighbours_out: v.outNeighbours(),
neighbours_in: v.inNeighbours(),
neighbours: v.neighbours(),
inDegree: v.inDegree(),
outDegree: v.outDegree(),
props: v.properties(),
edges: v.edges(),
}
);
}

const wg = g.window(3n, 9n);

const charlie = g.getVertex("Charlie");
console.log(charlie);

printVertex(charlie);
printVertex(bob);
printVertex(alice);
Loading

0 comments on commit c013a96

Please sign in to comment.