Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raphtory api #1621

Merged
merged 8 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/_release_rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ jobs:
with:
command: install
args: cargo-release --force
- name: "Publish raphtory-api to crates.io"
if: ${{ !inputs.dry_run }}
uses: actions-rs/cargo@v1
with:
command: publish
args: --token ${{ secrets.CRATES_TOKEN }} --package raphtory-api --allow-dirty
- name: "Publish raphtory-arrow to crates.io"
if: ${{ !inputs.dry_run }}
uses: actions-rs/cargo@v1
Expand Down
9 changes: 9 additions & 0 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ members = [
"examples/netflow",
"python",
"js-raphtory",
"raphtory-graphql",
"raphtory-graphql", "raphtory-api",
]
default-members = ["raphtory"]
resolver = "2"
Expand Down
18 changes: 18 additions & 0 deletions raphtory-api/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[package]
name = "raphtory-api"
version.workspace = true
documentation.workspace = true
repository.workspace = true
license.workspace = true
readme.workspace = true
homepage.workspace = true
keywords.workspace = true
authors.workspace = true
rust-version.workspace = true
edition.workspace = true

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
serde = { workspace = true, features = ["derive"] }
chrono.workspace = true
1 change: 1 addition & 0 deletions raphtory-api/src/core/entities/edges/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod edge_ref;
87 changes: 87 additions & 0 deletions raphtory-api/src/core/entities/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
use serde::{Deserialize, Serialize};

use self::edges::edge_ref::EdgeRef;

pub mod edges;

// the only reason this is public is because the physical ids of the nodes don't move
#[repr(transparent)]
#[derive(
Copy, Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Deserialize, Serialize, Default,
)]
pub struct VID(pub usize);

impl VID {
pub fn index(&self) -> usize {
self.0
}

pub fn as_u64(&self) -> u64 {
self.0 as u64
}
}

impl From<usize> for VID {
fn from(id: usize) -> Self {
VID(id)
}
}

impl From<VID> for usize {
fn from(id: VID) -> Self {
id.0
}
}

#[repr(transparent)]
#[derive(
Copy, Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Deserialize, Serialize, Default,
)]
pub struct EID(pub usize);

impl From<EID> for usize {
fn from(id: EID) -> Self {
id.0
}
}

impl From<usize> for EID {
fn from(id: usize) -> Self {
EID(id)
}
}

#[derive(
Copy, Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Deserialize, Serialize, Default,
)]
pub struct ELID {
edge: EID,
layer: Option<usize>,
}

impl ELID {
pub fn new(edge: EID, layer: Option<usize>) -> Self {
Self { edge, layer }
}
pub fn pid(&self) -> EID {
self.edge
}

pub fn layer(&self) -> Option<usize> {
self.layer
}
}

impl From<EdgeRef> for ELID {
fn from(value: EdgeRef) -> Self {
ELID {
edge: value.pid(),
layer: value.layer().copied(),
}
}
}
impl EID {
pub fn from_u64(id: u64) -> Self {
EID(id as usize)
}
}
22 changes: 22 additions & 0 deletions raphtory-api/src/core/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
pub mod entities;
pub mod storage;

/// Denotes the direction of an edge. Can be incoming, outgoing or both.
#[derive(
Clone,
Copy,
Hash,
Eq,
PartialEq,
PartialOrd,
Debug,
Default,
serde::Serialize,
serde::Deserialize,
)]
pub enum Direction {
OUT,
IN,
#[default]
BOTH,
}
1 change: 1 addition & 0 deletions raphtory-api/src/core/storage/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod timeindex;
78 changes: 78 additions & 0 deletions raphtory-api/src/core/storage/timeindex.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
use std::{fmt, ops::Range};

use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};

#[derive(Debug, Copy, Clone, Serialize, Deserialize, PartialEq, Ord, PartialOrd, Eq)]
pub struct TimeIndexEntry(pub i64, pub usize);

pub trait AsTime: fmt::Debug + Copy + Ord + Eq + Send + Sync + 'static {
fn t(&self) -> i64;

fn dt(&self) -> Option<DateTime<Utc>> {
let t = self.t();
DateTime::from_timestamp_millis(t)
}

fn range(w: Range<i64>) -> Range<Self>;

fn i(&self) -> usize {
0
}

fn new(t: i64, s: usize) -> Self;
}

impl From<i64> for TimeIndexEntry {
fn from(value: i64) -> Self {
Self::start(value)
}
}

impl TimeIndexEntry {
pub const MIN: TimeIndexEntry = TimeIndexEntry(i64::MIN, 0);

pub const MAX: TimeIndexEntry = TimeIndexEntry(i64::MAX, usize::MAX);
pub fn new(t: i64, s: usize) -> Self {
Self(t, s)
}

pub fn start(t: i64) -> Self {
Self(t, 0)
}

pub fn end(t: i64) -> Self {
Self(t.saturating_add(1), 0)
}
}

impl AsTime for i64 {
fn t(&self) -> i64 {
*self
}

fn range(w: Range<i64>) -> Range<Self> {
w
}

fn new(t: i64, _s: usize) -> Self {
t
}
}

impl AsTime for TimeIndexEntry {
fn t(&self) -> i64 {
self.0
}
fn range(w: Range<i64>) -> Range<Self> {
Self::start(w.start)..Self::start(w.end)
}

fn i(&self) -> usize {
self.1
}

fn new(t: i64, s: usize) -> Self {
Self(t, s)
}
}
1 change: 1 addition & 0 deletions raphtory-api/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod core;
3 changes: 1 addition & 2 deletions raphtory-arrow/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
[package]
name = "raphtory-arrow"
version = "0.8.1"
[dependencies]
version = "0.8.1"
7 changes: 5 additions & 2 deletions raphtory-cypher/src/executor/table_provider/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ use datafusion::{
use futures::Stream;
use raphtory_arrow::properties::Properties;

use raphtory::arrow::{graph_impl::ArrowGraph, prelude::*};
use raphtory::{
arrow::{graph_impl::ArrowGraph, prelude::*},
core::entities::VID,
};

use crate::{
arrow2::{self, array::to_data, datatypes::ArrowDataType},
Expand Down Expand Up @@ -64,7 +67,7 @@ impl NodeTableProvider {

pub fn lift_arrow_schema(
gid_dt: ArrowDataType,
properties: Option<&Properties<raphtory_arrow::interop::VID>>,
properties: Option<&Properties<VID>>,
) -> Result<SchemaRef, ExecError> {
let mut fields = vec![];

Expand Down
1 change: 1 addition & 0 deletions raphtory/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ homepage.workspace = true
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
raphtory-api = { path = "../raphtory-api", version="0.8.1" }
bincode = { workspace = true }
chrono = { workspace = true }
itertools = { workspace = true }
Expand Down
4 changes: 2 additions & 2 deletions raphtory/src/algorithms/algorithm_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ mod algorithm_result_test {
let algo_result = create_algo_result_tuple();
assert_eq!(algo_result.get(node_c.clone()).unwrap().0, 30.0f32);
let algo_result = create_algo_result_hashmap_vec();
let answer = algo_result.get(node_c.clone()).unwrap().get(0).unwrap().0;
let answer = algo_result.get(node_c.clone()).unwrap().first().unwrap().0;
assert_eq!(answer, 22i32);
}

Expand Down Expand Up @@ -617,7 +617,7 @@ mod algorithm_result_test {
let algo_result = create_algo_result_hashmap_vec();
let algo_results_hashmap = algo_result.get_all_with_names();
let tuple_result = algo_results_hashmap.get("A").unwrap();
assert_eq!(tuple_result.clone().get(0).unwrap().0, 11);
assert_eq!(tuple_result.clone().first().unwrap().0, 11);
assert_eq!(algo_result.get_all_values().len(), 3);
}

Expand Down
6 changes: 2 additions & 4 deletions raphtory/src/algorithms/components/lcc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,8 @@ mod largest_connected_component_test {

let expected_nodes = vec![1, 2, 3];
for node in expected_nodes {
assert_eq!(
assert!(
subgraph.has_node(node),
true,
"Node {} should be in the largest connected component.",
node
);
Expand All @@ -113,9 +112,8 @@ mod largest_connected_component_test {
let subgraph = graph.largest_connected_component();
let expected_nodes = vec![1, 2, 3];
for node in expected_nodes {
assert_eq!(
assert!(
subgraph.has_node(node),
true,
"Node {} should be in the largest connected component.",
node
);
Expand Down
10 changes: 1 addition & 9 deletions raphtory/src/algorithms/components/scc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,7 @@ fn tarjan<'graph, G>(

for neighbor in node.out_neighbours() {
if !indices.contains_key(&neighbor.node) {
tarjan(
neighbor.clone(),
index,
stack,
indices,
lowlink,
on_stack,
result,
);
tarjan(neighbor, index, stack, indices, lowlink, on_stack, result);
lowlink.insert(node.node, lowlink[&node.node].min(lowlink[&neighbor.node]));
} else if on_stack.contains(&neighbor.node) {
lowlink.insert(node.node, lowlink[&node.node].min(indices[&neighbor.node]));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,6 @@ mod motifs_test {
let actual = binding
.iter()
.map(|(k, v)| (k, v[0].clone()))
.into_iter()
.collect::<HashMap<&String, Vec<usize>>>();

let expected: HashMap<String, Vec<usize>> = HashMap::from([
Expand Down
2 changes: 1 addition & 1 deletion raphtory/src/algorithms/motifs/three_node_motifs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ mod three_node_motifs_test {

#[test]
fn triad_test() {
let events = vec![(true, 0, 1, 1, 1), (false, 1, 0, 1, 2), (false, 0, 0, 0, 3)]
let events = [(true, 0, 1, 1, 1), (false, 1, 0, 1, 2), (false, 0, 0, 0, 3)]
.iter()
.map(|x| TriangleEdge {
uv_edge: x.0,
Expand Down
Loading
Loading