Skip to content

Commit

Permalink
fixes as per PR review
Browse files Browse the repository at this point in the history
  • Loading branch information
fabianmurariu committed Jun 10, 2024
1 parent fa5c2ae commit 22e03b1
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 32 deletions.
10 changes: 5 additions & 5 deletions raphtory-benchmark/benches/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,11 +327,11 @@ pub fn run_analysis_benchmarks<F, G>(
.and_then(|(src, dst, t)| graph.edge(src, dst).map(|e| (e, *t)))
.expect("active edge");
b.iter(|| {
graph.edge_window_layers(
edge.edge,
active_t.saturating_sub(5)..active_t + 5,
&LayerIds::All,
)
edge
.window(active_t.saturating_sub(5), active_t + 5)
.explode_layers()
.iter()
.for_each(|e| { black_box(e); });
});
});

Expand Down
51 changes: 46 additions & 5 deletions raphtory-benchmark/benches/graph_ops.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
use common::run_analysis_benchmarks;
use criterion::{criterion_group, criterion_main, Criterion};
use rand::seq::*;
use raphtory::{db::api::view::*, graph_loader::example::sx_superuser_graph::sx_superuser_graph};
use rand::{seq::*, SeedableRng};
use raphtory::{
core::utils::hashing::calculate_hash,
db::api::view::*,
graph_loader::{
example::sx_superuser_graph::{sx_superuser_file, sx_superuser_graph, TEdge},
source::csv_loader::CsvLoader,
},
prelude::*,
};

mod common;

pub fn graph(c: &mut Criterion) {
let mut graph_group = c.benchmark_group("analysis_graph");
let graph = sx_superuser_graph(None).unwrap();
let graph = sx_superuser_graph().unwrap();
run_analysis_benchmarks(&mut graph_group, || graph.clone(), None);
graph_group.finish();
let mut graph_window_group_100 = c.benchmark_group("analysis_graph_window_100");
Expand All @@ -33,7 +41,7 @@ pub fn graph(c: &mut Criterion) {
graph_window_group_10.finish();

// subgraph
let mut rng = rand::thread_rng();
let mut rng = rand::rngs::StdRng::seed_from_u64(73);
let nodes = graph
.nodes()
.into_iter()
Expand All @@ -60,7 +68,7 @@ pub fn graph(c: &mut Criterion) {
subgraph_10_windowed.finish();

// layered graph windowed
let graph = sx_superuser_graph(Some(10)).unwrap();
let graph = layered_sx_super_user_graph(Some(10)).unwrap();
let mut graph_window_layered_group_50 = c.benchmark_group("analysis_graph_window_50_layered");
let latest = graph.latest_time().expect("non-empty graph");
let earliest = graph.earliest_time().expect("non-empty graph");
Expand Down Expand Up @@ -99,5 +107,38 @@ pub fn graph(c: &mut Criterion) {
graph_window_layered_group_50.finish();
}

/// Load the SX SuperUser dataset into a graph and return it
///
/// Returns:
///
/// - A Result containing the graph or an error, with edges randomly assigned to layers
fn layered_sx_super_user_graph(
num_layers: Option<usize>,
) -> Result<Graph, Box<dyn std::error::Error>> {
let graph = Graph::new();
CsvLoader::new(sx_superuser_file()?)
.set_delimiter(" ")
.load_into_graph(&graph, |edge: TEdge, g: &Graph| {
if let Some(layer) = num_layers
.map(|num_layers| calculate_hash(&(edge.src_id, edge.dst_id)) % num_layers as u64)
.map(|id| id.to_string())
{
g.add_edge(
edge.time,
edge.src_id,
edge.dst_id,
NO_PROPS,
Some(layer.as_str()),
)
.expect("Error: Unable to add edge");
} else {
g.add_edge(edge.time, edge.src_id, edge.dst_id, NO_PROPS, None)
.expect("Error: Unable to add edge");
}
})?;

Ok(graph)
}

criterion_group!(benches, graph);
criterion_main!(benches);
28 changes: 6 additions & 22 deletions raphtory/src/graph_loader/example/sx_superuser_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ use std::path::PathBuf;

#[derive(Deserialize, std::fmt::Debug)]
pub struct TEdge {
src_id: u64,
dst_id: u64,
time: i64,
pub src_id: u64,
pub dst_id: u64,
pub time: i64,
}

/// Download the SX SuperUser dataset
Expand All @@ -73,35 +73,19 @@ pub fn sx_superuser_file() -> Result<PathBuf, Box<dyn std::error::Error>> {
600,
)
}

/// Load the SX SuperUser dataset into a graph and return it
///
/// Returns:
///
/// - A Result containing the graph or an error
pub fn sx_superuser_graph(num_layers: Option<usize>) -> Result<Graph, Box<dyn std::error::Error>> {
pub fn sx_superuser_graph() -> Result<Graph, Box<dyn std::error::Error>> {
let graph = Graph::new();
CsvLoader::new(sx_superuser_file()?)
.set_delimiter(" ")
.load_into_graph(&graph, |edge: TEdge, g: &Graph| {
if let Some(layer) = num_layers
.map(|num_layers| calculate_hash(&(edge.src_id, edge.dst_id)) % num_layers as u64)
.map(|id| id.to_string())
{
g.add_edge(
edge.time,
edge.src_id,
edge.dst_id,
NO_PROPS,
Some(layer.as_str()),
)
g.add_edge(edge.time, edge.src_id, edge.dst_id, NO_PROPS, None)
.expect("Error: Unable to add edge");
} else {
g.add_edge(edge.time, edge.src_id, edge.dst_id, NO_PROPS, None)
.expect("Error: Unable to add edge");
}
})?;

Ok(graph)
}

Expand All @@ -119,6 +103,6 @@ mod sx_superuser_test {
#[test]
#[ignore] // don't hit SNAP by default FIXME: add a truncated test file for this one?
fn test_graph_loading_works() {
sx_superuser_graph(None).unwrap();
sx_superuser_graph().unwrap();
}
}

0 comments on commit 22e03b1

Please sign in to comment.