Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

from abc import ABC, abstractmethod

from graphdatascience.procedure_surface.api.pathfinding.single_source_bellman_ford_endpoints import (
SingleSourceBellmanFordEndpoints,
)
from graphdatascience.procedure_surface.api.pathfinding.single_source_delta_endpoints import SingleSourceDeltaEndpoints
from graphdatascience.procedure_surface.api.pathfinding.single_source_dijkstra_endpoints import (
SingleSourceDijkstraEndpoints,
Expand All @@ -28,9 +25,3 @@ def delta(self) -> SingleSourceDeltaEndpoints:
def dijkstra(self) -> SingleSourceDijkstraEndpoints:
"""Access to Dijkstra shortest path algorithm endpoints."""
...

@property
@abstractmethod
def bellman_ford(self) -> SingleSourceBellmanFordEndpoints:
"""Access to Bellman-Ford shortest path algorithm endpoints."""
...
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@
from graphdatascience.procedure_surface.api.estimation_result import EstimationResult


class BellmanFordStatsResult(BaseResult):
pre_processing_millis: int
compute_millis: int
post_processing_millis: int
contains_negative_cycle: bool
configuration: dict[str, Any]


class BellmanFordWriteResult(BaseResult):
pre_processing_millis: int
compute_millis: int
Expand Down Expand Up @@ -80,6 +88,54 @@ def stream(
totalCost, nodeIds, costs, index, and isNegativeCycle.
"""

@abstractmethod
def stats(
self,
G: GraphV2,
source_node: int,
relationship_weight_property: str | None = None,
relationship_types: list[str] | None = None,
node_labels: list[str] | None = None,
sudo: bool = False,
log_progress: bool = True,
username: str | None = None,
concurrency: int | None = None,
job_id: str | None = None,
) -> BellmanFordStatsResult:
"""
Runs the Bellman-Ford shortest path algorithm and returns statistics about the execution.

The Bellman-Ford algorithm can detect negative cycles in the graph.

Parameters
----------
G : GraphV2
The graph to run the algorithm on.
source_node : int
The source node for the shortest path computation.
relationship_weight_property : str | None, default=None
The relationship property to use as weights.
relationship_types : list[str] | None, default=None
Filter on relationship types.
node_labels : list[str] | None, default=None
Filter on node labels.
sudo : bool, default=False
Run the algorithm with elevated privileges.
log_progress : bool, default=True
Whether to log progress.
username : str | None, default=None
Username for the operation.
concurrency : int | None, default=None
Concurrency configuration.
job_id : str | None, default=None
Job ID for the operation.

Returns
-------
BellmanFordStatsResult
Object containing statistics from the execution, including whether negative cycles were detected.
"""

@abstractmethod
def mutate(
self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@
from graphdatascience.procedure_surface.api.estimation_result import EstimationResult


class DeltaSteppingStatsResult(BaseResult):
pre_processing_millis: int
compute_millis: int
post_processing_millis: int
configuration: dict[str, Any]


class DeltaSteppingWriteResult(BaseResult):
pre_processing_millis: int
compute_millis: int
Expand Down Expand Up @@ -78,6 +85,55 @@ def stream(
The shortest path results as a DataFrame with columns for sourceNode, targetNode, totalCost, nodeIds, costs, index.
"""

@abstractmethod
def stats(
self,
G: GraphV2,
source_node: int,
delta: float = 2.0,
relationship_weight_property: str | None = None,
relationship_types: list[str] | None = None,
node_labels: list[str] | None = None,
sudo: bool = False,
log_progress: bool = True,
username: str | None = None,
concurrency: int | None = None,
job_id: str | None = None,
) -> DeltaSteppingStatsResult:
"""
Runs the Delta Stepping shortest path algorithm and returns statistics about the execution.

Parameters
----------
G : GraphV2
The graph to run the algorithm on.
source_node : int
The source node for the shortest path computation.
delta : float, default=2.0
The bucket width for grouping nodes by tentative distance.
relationship_weight_property : str | None, default=None
The relationship property to use as weights.
relationship_types : list[str] | None, default=None
Filter on relationship types.
node_labels : list[str] | None, default=None
Filter on node labels.
sudo : bool, default=False
Run the algorithm with elevated privileges.
log_progress : bool, default=True
Whether to log progress.
username : str | None, default=None
Username for the operation.
concurrency : int | None, default=None
Concurrency configuration.
job_id : str | None, default=None
Job ID for the operation.

Returns
-------
DeltaSteppingStatsResult
Object containing statistics from the execution.
"""

@abstractmethod
def mutate(
self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
from graphdatascience.arrow_client.authenticated_flight_client import AuthenticatedArrowClient
from graphdatascience.arrow_client.v2.remote_write_back_client import RemoteWriteBackClient
from graphdatascience.procedure_surface.api.pathfinding.all_shortest_path_endpoints import AllShortestPathEndpoints
from graphdatascience.procedure_surface.api.pathfinding.single_source_bellman_ford_endpoints import (
SingleSourceBellmanFordEndpoints,
)
from graphdatascience.procedure_surface.api.pathfinding.single_source_delta_endpoints import SingleSourceDeltaEndpoints
from graphdatascience.procedure_surface.api.pathfinding.single_source_dijkstra_endpoints import (
SingleSourceDijkstraEndpoints,
Expand Down Expand Up @@ -39,7 +36,3 @@ def delta(self) -> SingleSourceDeltaEndpoints:
@property
def dijkstra(self) -> SingleSourceDijkstraEndpoints:
return self._dijkstra

@property
def bellman_ford(self) -> SingleSourceBellmanFordEndpoints:
return self._bellman_ford
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from graphdatascience.procedure_surface.api.estimation_result import EstimationResult
from graphdatascience.procedure_surface.api.pathfinding.single_source_bellman_ford_endpoints import (
BellmanFordMutateResult,
BellmanFordStatsResult,
BellmanFordWriteResult,
SingleSourceBellmanFordEndpoints,
)
Expand Down Expand Up @@ -61,6 +62,36 @@ def stream(

return result

def stats(
self,
G: GraphV2,
source_node: int,
relationship_weight_property: str | None = None,
relationship_types: list[str] | None = None,
node_labels: list[str] | None = None,
sudo: bool = False,
log_progress: bool = True,
username: str | None = None,
concurrency: int | None = None,
job_id: str | None = None,
) -> BellmanFordStatsResult:
config = self._endpoints_helper.create_base_config(
G,
sourceNode=source_node,
relationshipWeightProperty=relationship_weight_property,
relationshipTypes=relationship_types,
nodeLabels=node_labels,
sudo=sudo,
logProgress=log_progress,
username=username,
concurrency=concurrency,
jobId=job_id,
)

result = self._endpoints_helper.run_job_and_get_summary("v2/pathfinding.singleSource.bellmanFord", config)

return BellmanFordStatsResult(**result)

def mutate(
self,
G: GraphV2,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from graphdatascience.procedure_surface.api.estimation_result import EstimationResult
from graphdatascience.procedure_surface.api.pathfinding.single_source_delta_endpoints import (
DeltaSteppingMutateResult,
DeltaSteppingStatsResult,
DeltaSteppingWriteResult,
SingleSourceDeltaEndpoints,
)
Expand Down Expand Up @@ -61,6 +62,38 @@ def stream(

return result

def stats(
self,
G: GraphV2,
source_node: int,
delta: float = 2.0,
relationship_weight_property: str | None = None,
relationship_types: list[str] | None = None,
node_labels: list[str] | None = None,
sudo: bool = False,
log_progress: bool = True,
username: str | None = None,
concurrency: int | None = None,
job_id: str | None = None,
) -> DeltaSteppingStatsResult:
config = self._endpoints_helper.create_base_config(
G,
sourceNode=source_node,
delta=delta,
relationshipWeightProperty=relationship_weight_property,
relationshipTypes=relationship_types,
nodeLabels=node_labels,
sudo=sudo,
logProgress=log_progress,
username=username,
concurrency=concurrency,
jobId=job_id,
)

result = self._endpoints_helper.run_job_and_get_summary("v2/pathfinding.singleSource.deltaStepping", config)

return DeltaSteppingStatsResult(**result)

def mutate(
self,
G: GraphV2,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from graphdatascience.procedure_surface.api.estimation_result import EstimationResult
from graphdatascience.procedure_surface.api.pathfinding.single_source_bellman_ford_endpoints import (
BellmanFordMutateResult,
BellmanFordStatsResult,
BellmanFordWriteResult,
SingleSourceBellmanFordEndpoints,
)
Expand Down Expand Up @@ -63,6 +64,37 @@ def stream(
], # skip reoute column
)

def stats(
self,
G: GraphV2,
source_node: int,
relationship_weight_property: str | None = None,
relationship_types: list[str] | None = None,
node_labels: list[str] | None = None,
sudo: bool = False,
log_progress: bool = True,
username: str | None = None,
concurrency: int | None = None,
job_id: str | None = None,
) -> BellmanFordStatsResult:
config = ConfigConverter.convert_to_gds_config(
sourceNode=source_node,
relationshipWeightProperty=relationship_weight_property,
relationshipTypes=relationship_types,
nodeLabels=node_labels,
sudo=sudo,
logProgress=log_progress,
username=username,
concurrency=concurrency,
jobId=job_id,
)
params = CallParameters(graph_name=G.name(), config=config)
params.ensure_job_id_in_config()

result = self._query_runner.call_procedure("gds.bellmanFord.stats", params=params, logging=log_progress).iloc[0]

return BellmanFordStatsResult(**result.to_dict())

def mutate(
self,
G: GraphV2,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from graphdatascience.procedure_surface.api.estimation_result import EstimationResult
from graphdatascience.procedure_surface.api.pathfinding.single_source_delta_endpoints import (
DeltaSteppingMutateResult,
DeltaSteppingStatsResult,
DeltaSteppingWriteResult,
SingleSourceDeltaEndpoints,
)
Expand Down Expand Up @@ -57,6 +58,41 @@ def stream(
yields=["sourceNode", "targetNode", "totalCost", "nodeIds", "costs", "index"], # skip path column
)

def stats(
self,
G: GraphV2,
source_node: int,
delta: float = 2.0,
relationship_weight_property: str | None = None,
relationship_types: list[str] | None = None,
node_labels: list[str] | None = None,
sudo: bool = False,
log_progress: bool = True,
username: str | None = None,
concurrency: int | None = None,
job_id: str | None = None,
) -> DeltaSteppingStatsResult:
config = ConfigConverter.convert_to_gds_config(
sourceNode=source_node,
delta=delta,
relationshipWeightProperty=relationship_weight_property,
relationshipTypes=relationship_types,
nodeLabels=node_labels,
sudo=sudo,
logProgress=log_progress,
username=username,
concurrency=concurrency,
jobId=job_id,
)
params = CallParameters(graph_name=G.name(), config=config)
params.ensure_job_id_in_config()

result = self._query_runner.call_procedure(
"gds.allShortestPaths.delta.stats", params=params, logging=log_progress
).iloc[0]

return DeltaSteppingStatsResult(**result.to_dict())

def mutate(
self,
G: GraphV2,
Expand Down
Loading