Skip to content

Commit

Permalink
replace AlgorithmResult with NodeState in rust (#1930)
Browse files Browse the repository at this point in the history
* replace AlgorithmResult with NodeState in rust

* fix python, graphql, and examples

* tidy up python module

* add to_df and get methods

* add PartialEq for nodes and fix bug with get

* start tidying up python tests

* remove the self-import in the stubs

* equality support for all the node states

* more test tidyup

* improve equality checks on Nodes and NodeState

* update all the python tests for new api

* tidy

* update minimum rust version

* fix example notebook

* cleanup debugging code

* tidy up algorithm docstrings

* change the compatible view handling
  • Loading branch information
ljeub-pometry authored Jan 24, 2025
1 parent 82925e7 commit 3771175
Show file tree
Hide file tree
Showing 55 changed files with 3,270 additions and 2,712 deletions.
132 changes: 68 additions & 64 deletions examples/python/socio-patterns/example.ipynb

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion examples/rust/src/bin/hulongbay/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ fn try_main() -> Result<(), Box<dyn Error>> {
let components = weakly_connected_components(&graph, 5, Some(16));

components
.result
.into_iter()
.counts_by(|(_, cc)| cc)
.iter()
Expand Down
3 changes: 1 addition & 2 deletions examples/rust/src/bin/lotr/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,7 @@ fn main() {
assert_eq!(graph.node(gandalf).unwrap().name(), "Gandalf");

let r: Vec<String> = temporally_reachable_nodes(&graph, None, 20, 31930, vec!["Gandalf"], None)
.get_all_values()
.into_iter()
.into_iter_values()
.flatten()
.map(|(_, s)| s)
.collect();
Expand Down
138 changes: 0 additions & 138 deletions python/python/raphtory/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
###############################################################################

from typing import *
from raphtory import *
from raphtory.algorithms import *
from raphtory.vectors import *
from raphtory.node_state import *
Expand Down Expand Up @@ -6070,143 +6069,6 @@ class WindowSet(object):
Iterable: the time index"
"""

class AlgorithmResult(object):
def __len__(self):
"""Return len(self)."""

def __repr__(self):
"""Return repr(self)."""

def get(self, key: NodeInput) -> Optional[Any]:
"""
Returns the value corresponding to the provided key
Arguments:
key (NodeInput): The node for which the value is to be retrieved.
Returns:
Optional[Any]: The value for the node or `None` if the value does not exist.
"""

def get_all(self) -> dict[Node, Any]:
"""
Returns a Dict containing all the nodes (as keys) and their corresponding values (values) or none.
Returns:
dict[Node, Any]: A dict of nodes and their values
"""

def get_all_values(self) -> list[Any]:
"""
Get all values
Returns:
list[Any]: the values for each node as a list
"""

def get_all_with_names(self) -> dict[str, Any]:
"""
Returns a dict with node names and values
Returns:
dict[str, Any]: a dict with node names and values
"""

def group_by(self) -> dict[Any, list[str]]:
"""
Groups the `AlgorithmResult` by its values.
Returns:
dict[Any, list[str]]: A mapping where keys are unique values from the `AlgorithmResult` and values are lists of nodes
that share the same value.
"""

def max(self) -> Tuple[Node, Any]:
"""
Find node with maximum value
Returns:
Tuple[Node, Any]: The node and maximum value.
"""

def median(self):
"""
Returns a tuple of the median result with its key
Returns:
Optional[Tuple[Node, Any]]: The node with median value or `None` if there are no nodes.
"""

def min(self) -> Tuple[Node, Any]:
"""
Find node with minimum value
Returns:
Tuple[Node, Any]: The node and minimum value.
"""

def sort_by_node(self, reverse: bool = True) -> list[Tuple[Node, Any]]:
"""
Sorts by node id in ascending or descending order.
Arguments:
reverse (bool): If `true`, sorts the result in descending order; otherwise, sorts in ascending order. Defaults to True.
Returns:
list[Tuple[Node, Any]]: A sorted list of tuples containing nodes and values.
"""

def sort_by_node_name(self, reverse: bool = True) -> list[Tuple[Node, Any]]:
"""
The function `sort_by_node_name` sorts a vector of tuples containing a node and an optional
value by the node name in either ascending or descending order.
Arguments:
reverse (bool): A boolean value indicating whether the sorting should be done in reverse order or not. Defaults to True.
If reverse is true, the sorting will be done in descending order, otherwise it will be done in
ascending order.
Returns:
list[Tuple[Node, Any]]: The function sort_by_node_name returns a vector of tuples. Each tuple contains a Node and value
"""

def sort_by_value(self, reverse: bool = True) -> list[Tuple[Node, Any]]:
"""
Sorts the `AlgorithmResult` by its values in ascending or descending order.
Arguments:
reverse (bool): If `true`, sorts the result in descending order, otherwise, sorts in ascending order. Defaults to True.
Returns:
list[Tuple[Node, Any]]: A sorted vector of tuples containing Nodes and values.
"""

def to_df(self) -> DataFrame:
"""
Creates a dataframe from the result
Returns:
DataFrame: A `pandas.DataFrame` containing the result
"""

def top_k(
self, k: int, percentage: bool = False, reverse: bool = True
) -> list[Tuple[Node, Any]]:
"""
Retrieves the top-k elements from the `AlgorithmResult` based on its values.
Arguments:
k (int): The number of elements to retrieve.
percentage (bool): If `True`, the `k` parameter is treated as a percentage of total elements. Defaults to False.
reverse (bool): If `True`, retrieves the elements in descending order, otherwise, in ascending order. Defaults to True.
Returns:
list[Tuple[Node, Any]]: List of tuples with keys of nodes and values of type `Y`.
If percentage is true, the returned vector contains the top `k` percentage of elements.
If percentage is false, the returned vector contains the top `k` elements.
Returns None if the result is empty or if `k` is 0.
"""

class GraphIndex(object):
"""
A searchable Index for a `Graph`. This allows for fuzzy and exact searches of nodes and edges.
Expand Down
Loading

0 comments on commit 3771175

Please sign in to comment.