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

Fix compilation for different feature combinations #1416

Merged
merged 6 commits into from
Dec 15, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 23 additions & 5 deletions .github/workflows/test_rust_workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,31 @@ jobs:
uses: actions-rs/cargo@v1
with:
command: update
- name: Run Tests
uses: actions-rs/cargo@v1
- name: Run Tests (No features)
env:
RUSTFLAGS: -Awarnings
with:
command: test
args: --all --no-default-features --features "raphtory/io raphtory/python"
run: |
cargo test --all --no-default-features
- name: Run Tests (features=io)
env:
RUSTFLAGS: -Awarnings
run: |
cargo test -p raphtory --no-default-features --features "io"
- name: Run Tests (features=python)
env:
RUSTFLAGS: -Awarnings
run: |
cargo test -p raphtory --no-default-features --features "python"
- name: Run Tests (features=search)
env:
RUSTFLAGS: -Awarnings
run: |
cargo test -p raphtory --no-default-features --features "search"
- name: Run Tests (features=vectors)
env:
RUSTFLAGS: -Awarnings
run: |
cargo test -p raphtory --no-default-features --features "vectors"
- name: Print sccache stats
run: sccache --show-stats
- name: Stop sccache server
Expand Down
2 changes: 1 addition & 1 deletion python/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ crate-type = ["cdylib"]

[dependencies]
pyo3 = {version= "0.19.2", features=["multiple-pymethods", "chrono"]}
raphtory_core = {path = "../raphtory", version = "0.6.1", features=["python"], package="raphtory" }
raphtory_core = {path = "../raphtory", version = "0.6.1", features=["python", "search", "vectors"], package="raphtory" }
raphtory-graphql = {path = "../raphtory-graphql", version = "0.6.1" }
openssl = { version = "0.10", features = ["vendored"] } # DO NOT REMOVE IT BREAKS PYTHON RELEASE
serde_json = "1.0.108"
Expand Down
9 changes: 5 additions & 4 deletions raphtory/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ lock_api = { version = "0.4", features = ["arc_lock", "serde"] }
dashmap = {version ="5", features = ["serde"] }
serde_with = "3.3.0"
enum_dispatch = "0.3"
kdam = { version="0.5.0", features = ["notebook"] }
ordered-float = "3.7.0"

# io optional dependencies
csv = {version="1.1.6", optional=true}
Expand All @@ -69,7 +69,8 @@ pyo3-asyncio = { version = "0.19.0", features = ["tokio-runtime"], optional=true
num = {version="0.4.0", optional=true}
display-error-chain = {version= "0.2.0", optional=true}
arrow2 = {version="0.17", optional=true}
ordered-float = "3.7.0"
kdam = { version="0.5.0", features = ["notebook"], optional = true}


[dev-dependencies]
csv = "1"
Expand All @@ -81,11 +82,11 @@ tokio = { version = "1.27.0", features = ["full"]} # for vector testing
dotenv = "0.15.0" # for vector testing

[features]
default = ["search", "vectors"]
default = []
# Enables the graph loader io module
io = ["dep:zip", "dep:neo4rs", "dep:bzip2", "dep:flate2", "dep:csv", "dep:serde_json", "dep:reqwest", "dep:tokio"]
# Enables generating the pyo3 python bindings
python = ["io", "vectors", "dep:pyo3", "dep:pyo3-asyncio", "dep:num", "dep:display-error-chain", "dep:arrow2"]
python = ["io", "dep:pyo3", "dep:pyo3-asyncio", "dep:num", "dep:display-error-chain", "dep:arrow2", "dep:kdam"]
# search
search = ["dep:tantivy"]
# vectors
Expand Down
19 changes: 5 additions & 14 deletions raphtory/src/db/api/properties/dyn_props.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
use crate::{
db::api::{
properties::{
internal::{InheritPropertiesOps, PropertiesOps},
ConstProperties, Properties, TemporalProperties, TemporalPropertyView,
},
view::{internal::Static, DynamicGraph},
use crate::db::api::{
properties::{
internal::{InheritPropertiesOps, PropertiesOps},
ConstProperties, Properties, TemporalProperties, TemporalPropertyView,
},
search::IndexedGraph,
view::{internal::Static, DynamicGraph},
};
use std::sync::Arc;

Expand All @@ -29,12 +26,6 @@ impl From<Properties<DynamicGraph>> for DynProperties {
}
}

impl From<Properties<IndexedGraph<DynamicGraph>>> for DynProperties {
fn from(value: Properties<IndexedGraph<DynamicGraph>>) -> Self {
let props: DynProps = Arc::new(value.props);
Properties::new(props)
}
}
pub type DynConstProperties = ConstProperties<DynProps>;

impl<P: PropertiesOps + Send + Sync + Static + 'static> From<ConstProperties<P>>
Expand Down
15 changes: 14 additions & 1 deletion raphtory/src/python/graph/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,24 @@ use crate::{
api::view::internal::DynamicGraph,
graph::{edge::EdgeView, node::NodeView},
},
python::utils::errors::adapt_err_value,
python::{graph::views::graph_view::PyGraphView, utils::errors::adapt_err_value},
search::IndexedGraph,
};
use pyo3::prelude::*;

#[pymethods]
impl PyGraphView {
/// Indexes all node and edge properties.
/// Returns a GraphIndex which allows the user to search the edges and nodes of the graph via tantivity fuzzy matching queries.
/// Note this is currently immutable and will not update if the graph changes. This is to be improved in a future release.
///
/// Returns:
/// GraphIndex - Returns a GraphIndex
fn index(&self) -> GraphIndex {
GraphIndex::new(self.graph.clone())
}
}

/// A searchable Index for a `Graph`. This allows for fuzzy and exact searches of nodes and edges.
/// This makes use of Tantivity internally to provide the search functionality.
/// To create a graph index, call `graph.index()` on any `Graph` object in python.
Expand Down
2 changes: 2 additions & 0 deletions raphtory/src/python/graph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ pub mod algorithm_result;
pub mod edge;
pub mod graph;
pub mod graph_with_deletions;

#[cfg(feature = "search")]
pub mod index;
pub mod node;
pub mod pandas;
Expand Down
70 changes: 8 additions & 62 deletions raphtory/src/python/graph/views/graph_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,16 @@ use crate::{
},
prelude::*,
python::{
graph::{edge::PyEdges, index::GraphIndex, node::PyNodes},
packages::vectors::{DynamicVectorisedGraph, PyDocumentTemplate},
graph::{edge::PyEdges, node::PyNodes},
types::repr::Repr,
utils::{execute_async_task, PyInterval, PyTime},
utils::{PyInterval, PyTime},
},
vectors::vectorisable::Vectorisable,
*,
};
use chrono::prelude::*;
use itertools::Itertools;
use pyo3::{
prelude::*,
types::{PyBytes, PyFunction},
};
use std::{ops::Deref, path::PathBuf};
use pyo3::{prelude::*, types::PyBytes};
use std::ops::Deref;

impl IntoPy<PyObject> for MaterializedGraph {
fn into_py(self, py: Python<'_>) -> PyObject {
Expand Down Expand Up @@ -293,55 +288,6 @@ impl PyGraphView {
self.graph.materialize()
}

/// Indexes all node and edge properties.
/// Returns a GraphIndex which allows the user to search the edges and nodes of the graph via tantivity fuzzy matching queries.
/// Note this is currently immutable and will not update if the graph changes. This is to be improved in a future release.
///
/// Returns:
/// GraphIndex - Returns a GraphIndex
fn index(&self) -> GraphIndex {
GraphIndex::new(self.graph.clone())
}

/// Create a VectorisedGraph from the current graph
///
/// Args:
/// embedding (Callable[[list], list]): the embedding function to translate documents to embeddings
/// cache (str): the file to be used as a cache to avoid calling the embedding function (optional)
/// overwrite_cache (bool): whether or not to overwrite the cache if there are new embeddings (optional)
/// node_document (str): the property name to be used as document for nodes (optional)
/// edge_document (str): the property name to be used as document for edges (optional)
/// verbose (bool): whether or not to print logs reporting the progress
///
/// Returns:
/// A VectorisedGraph with all the documents/embeddings computed and with an initial empty selection
#[pyo3(signature = (embedding, cache = None, overwrite_cache = false, node_document = None, edge_document = None, verbose = false))]
fn vectorise(
&self,
embedding: &PyFunction,
cache: Option<String>,
overwrite_cache: bool,
node_document: Option<String>,
edge_document: Option<String>,
verbose: bool,
) -> DynamicVectorisedGraph {
let embedding: Py<PyFunction> = embedding.into();
let graph = self.graph.clone();
let cache = cache.map(PathBuf::from);
let template = PyDocumentTemplate::new(node_document, edge_document);
execute_async_task(move || async move {
graph
.vectorise_with_template(
Box::new(embedding.clone()),
cache,
overwrite_cache,
template,
verbose,
)
.await
})
}

/// Get bincode encoded graph
pub fn bincode<'py>(&'py self, py: Python<'py>) -> Result<&'py PyBytes, GraphError> {
let bytes = self.graph.materialize()?.bincode()?;
Expand Down Expand Up @@ -370,16 +316,16 @@ impl Repr for PyGraphView {
.map(|(k, v)| format!("{}: {}", k.deref(), v))
.join(", ");
if properties.is_empty() {
return format!(
format!(
"Graph(number_of_edges={:?}, number_of_nodes={:?}, number_of_temporal_edges={:?}, earliest_time={:?}, latest_time={:?})",
num_edges, num_nodes, num_temporal_edges, earliest_time, latest_time
);
)
} else {
let property_string: String = format!("{{{properties}}}");
return format!(
format!(
"Graph(number_of_edges={:?}, number_of_nodes={:?}, number_of_temporal_edges={:?}, earliest_time={:?}, latest_time={:?}, properties={})",
num_edges, num_nodes, num_temporal_edges, earliest_time, latest_time, property_string
);
)
}
}
}
2 changes: 2 additions & 0 deletions raphtory/src/python/packages/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
pub mod algorithms;
pub mod graph_gen;
pub mod graph_loader;

#[cfg(feature = "vectors")]
pub mod vectors;
47 changes: 45 additions & 2 deletions raphtory/src/python/packages/vectors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@
},
prelude::{EdgeViewOps, GraphViewOps, NodeViewOps},
python::{
graph::{edge::PyEdge, node::PyNode},
graph::{edge::PyEdge, node::PyNode, views::graph_view::PyGraphView},
utils::{execute_async_task, PyTime},
},
vectors::{
document_template::{DefaultTemplate, DocumentTemplate},
vectorisable::Vectorisable,
vectorised_graph::VectorisedGraph,
Document, DocumentInput, Embedding, EmbeddingFunction, Lifespan,
},
Expand All @@ -25,7 +26,7 @@
prelude::*,
types::{PyFunction, PyList},
};
use std::{future::Future, thread};
use std::{future::Future, path::PathBuf, thread};

Check warning on line 29 in raphtory/src/python/packages/vectors.rs

View workflow job for this annotation

GitHub Actions / Run Python tests / Python Tests (3.8, ubuntu-latest)

unused imports: `future::Future`, `thread`

Check warning on line 29 in raphtory/src/python/packages/vectors.rs

View workflow job for this annotation

GitHub Actions / Run Python tests / Python Tests (3.8, macos-latest)

unused imports: `future::Future`, `thread`

Check warning on line 29 in raphtory/src/python/packages/vectors.rs

View workflow job for this annotation

GitHub Actions / Run Python tests / Python Tests (3.8, windows-latest)

unused imports: `future::Future`, `thread`

#[derive(Clone)]
pub enum PyQuery {
Expand Down Expand Up @@ -141,6 +142,48 @@

pub(crate) type DynamicVectorisedGraph = VectorisedGraph<DynamicGraph, PyDocumentTemplate>;

#[pymethods]
impl PyGraphView {
/// Create a VectorisedGraph from the current graph
///
/// Args:
/// embedding (Callable[[list], list]): the embedding function to translate documents to embeddings
/// cache (str): the file to be used as a cache to avoid calling the embedding function (optional)
/// overwrite_cache (bool): whether or not to overwrite the cache if there are new embeddings (optional)
/// node_document (str): the property name to be used as document for nodes (optional)
/// edge_document (str): the property name to be used as document for edges (optional)
/// verbose (bool): whether or not to print logs reporting the progress
///
/// Returns:
/// A VectorisedGraph with all the documents/embeddings computed and with an initial empty selection
#[pyo3(signature = (embedding, cache = None, overwrite_cache = false, node_document = None, edge_document = None, verbose = false))]
fn vectorise(
&self,
embedding: &PyFunction,
cache: Option<String>,
overwrite_cache: bool,
node_document: Option<String>,
edge_document: Option<String>,
verbose: bool,
) -> DynamicVectorisedGraph {
let embedding: Py<PyFunction> = embedding.into();
let graph = self.graph.clone();
let cache = cache.map(PathBuf::from);
let template = PyDocumentTemplate::new(node_document, edge_document);
execute_async_task(move || async move {
graph
.vectorise_with_template(
Box::new(embedding.clone()),
cache,
overwrite_cache,
template,
verbose,
)
.await
})
}
}

#[pyclass(name = "VectorisedGraph", frozen)]
pub struct PyVectorisedGraph(DynamicVectorisedGraph);

Expand Down
20 changes: 17 additions & 3 deletions raphtory/src/search/into_indexed.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
use crate::{
db::{
api::view::{
internal::{DynamicGraph, IntoDynamic, OneHopFilter},
StaticGraphViewOps,
api::{
properties::{
dyn_props::{DynProperties, DynProps},
Properties,
},
view::{
internal::{DynamicGraph, IntoDynamic, OneHopFilter},
StaticGraphViewOps,
},
},
graph::views::{
layer_graph::LayeredGraph, node_subgraph::NodeSubgraph, window_graph::WindowedGraph,
Expand All @@ -11,6 +17,7 @@ use crate::{
prelude::{GraphViewOps, TimeOps},
search::IndexedGraph,
};
use std::sync::Arc;

pub trait DynamicIndexedGraph {
fn into_dynamic_indexed(self) -> IndexedGraph<DynamicGraph>;
Expand Down Expand Up @@ -67,3 +74,10 @@ impl<G: StaticGraphViewOps + IntoDynamic> DynamicIndexedGraph for IndexedGraph<G
}
}
}

impl From<Properties<IndexedGraph<DynamicGraph>>> for DynProperties {
fn from(value: Properties<IndexedGraph<DynamicGraph>>) -> Self {
let props: DynProps = Arc::new(value.props);
Properties::new(props)
}
}