Skip to content

Commit 9c55142

Browse files
committed
Add support for sllpa in v2
1 parent f4d4e0c commit 9c55142

File tree

7 files changed

+1002
-2
lines changed

7 files changed

+1002
-2
lines changed
Lines changed: 343 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,343 @@
1+
from __future__ import annotations
2+
3+
from abc import ABC, abstractmethod
4+
from typing import Any, List, Optional, Union
5+
6+
from pandas import DataFrame
7+
8+
from graphdatascience.procedure_surface.api.base_result import BaseResult
9+
from graphdatascience.procedure_surface.api.catalog.graph_api import GraphV2
10+
from graphdatascience.procedure_surface.api.estimation_result import EstimationResult
11+
12+
13+
class SllpaEndpoints(ABC):
14+
@abstractmethod
15+
def mutate(
16+
self,
17+
G: GraphV2,
18+
mutate_property: str,
19+
*,
20+
max_iterations: int,
21+
concurrency: Optional[int] = None,
22+
job_id: Optional[str] = None,
23+
log_progress: bool = True,
24+
min_association_strength: Optional[float] = None,
25+
node_labels: Optional[List[str]] = None,
26+
partitioning: Optional[Any] = None,
27+
relationship_types: Optional[List[str]] = None,
28+
sudo: Optional[bool] = False,
29+
username: Optional[str] = None,
30+
) -> SllpaMutateResult:
31+
"""
32+
Executes the Speaker-Listener Label Propagation algorithm (SLLPA) and writes the results to the in-memory graph as node properties.
33+
34+
Parameters
35+
----------
36+
G : GraphV2
37+
The graph to run the algorithm on
38+
mutate_property : str
39+
The property name to store the community ID for each node
40+
max_iterations : int
41+
Maximum number of iterations for the algorithm
42+
concurrency : Optional[int], default=None
43+
The number of concurrent threads
44+
job_id : Optional[str], default=None
45+
An identifier for the job
46+
log_progress : bool, default=True
47+
Whether to log progress
48+
min_association_strength : Optional[float], default=None
49+
Minimum association strength for community assignment
50+
node_labels : Optional[List[str]], default=None
51+
Filter nodes with specific labels
52+
partitioning : Optional[Any], default=None
53+
Partitioning configuration for the algorithm
54+
relationship_types : Optional[List[str]], default=None
55+
Filter relationships with specific types
56+
sudo : Optional[bool], default=False
57+
Run with elevated privileges
58+
username : Optional[str], default=None
59+
Username for authentication
60+
61+
Returns
62+
-------
63+
SllpaMutateResult
64+
An object containing metadata about the algorithm execution and the mutation
65+
"""
66+
...
67+
68+
@abstractmethod
69+
def stats(
70+
self,
71+
G: GraphV2,
72+
*,
73+
max_iterations: int,
74+
concurrency: Optional[int] = None,
75+
job_id: Optional[str] = None,
76+
log_progress: bool = True,
77+
min_association_strength: Optional[float] = None,
78+
node_labels: Optional[List[str]] = None,
79+
partitioning: Optional[Any] = None,
80+
relationship_types: Optional[List[str]] = None,
81+
sudo: Optional[bool] = False,
82+
username: Optional[str] = None,
83+
) -> SllpaStatsResult:
84+
"""
85+
Executes the Speaker-Listener Label Propagation algorithm (SLLPA) and returns statistics about the communities.
86+
87+
Parameters
88+
----------
89+
G : GraphV2
90+
The graph to run the algorithm on
91+
concurrency : Optional[int], default=None
92+
The number of concurrent threads
93+
job_id : Optional[str], default=None
94+
An identifier for the job
95+
log_progress : bool, default=True
96+
Whether to log progress
97+
min_association_strength : Optional[float], default=None
98+
Minimum association strength for community assignment
99+
node_labels : Optional[List[str]], default=None
100+
Filter nodes with specific labels
101+
partitioning : Optional[Any], default=None
102+
Partitioning configuration for the algorithm
103+
relationship_types : Optional[List[str]], default=None
104+
Filter relationships with specific types
105+
sudo : Optional[bool], default=False
106+
Run with elevated privileges
107+
username : Optional[str], default=None
108+
Username for authentication
109+
110+
Returns
111+
-------
112+
SllpaStatsResult
113+
An object containing statistics about the algorithm execution
114+
"""
115+
...
116+
117+
@abstractmethod
118+
def stream(
119+
self,
120+
G: GraphV2,
121+
*,
122+
max_iterations: int,
123+
concurrency: Optional[int] = None,
124+
job_id: Optional[str] = None,
125+
log_progress: bool = True,
126+
min_association_strength: Optional[float] = None,
127+
node_labels: Optional[List[str]] = None,
128+
partitioning: Optional[Any] = None,
129+
relationship_types: Optional[List[str]] = None,
130+
sudo: Optional[bool] = False,
131+
username: Optional[str] = None,
132+
) -> DataFrame:
133+
"""
134+
Executes the Speaker-Listener Label Propagation algorithm (SLLPA) and returns the results as a DataFrame.
135+
136+
Parameters
137+
----------
138+
G : GraphV2
139+
The graph to run the algorithm on
140+
concurrency : Optional[int], default=None
141+
The number of concurrent threads
142+
job_id : Optional[str], default=None
143+
An identifier for the job
144+
log_progress : bool, default=True
145+
Whether to log progress
146+
min_association_strength : Optional[float], default=None
147+
Minimum association strength for community assignment
148+
node_labels : Optional[List[str]], default=None
149+
Filter nodes with specific labels
150+
partitioning : Optional[Any], default=None
151+
Partitioning configuration for the algorithm
152+
relationship_types : Optional[List[str]], default=None
153+
Filter relationships with specific types
154+
sudo : Optional[bool], default=False
155+
Run with elevated privileges
156+
username : Optional[str], default=None
157+
Username for authentication
158+
159+
Returns
160+
-------
161+
DataFrame
162+
DataFrame containing node IDs and their community values
163+
"""
164+
...
165+
166+
@abstractmethod
167+
def write(
168+
self,
169+
G: GraphV2,
170+
write_property: str,
171+
*,
172+
max_iterations: int,
173+
concurrency: Optional[int] = None,
174+
job_id: Optional[str] = None,
175+
log_progress: bool = True,
176+
min_association_strength: Optional[float] = None,
177+
node_labels: Optional[List[str]] = None,
178+
partitioning: Optional[Any] = None,
179+
relationship_types: Optional[List[str]] = None,
180+
sudo: Optional[bool] = False,
181+
username: Optional[str] = None,
182+
write_concurrency: Optional[int] = None,
183+
) -> SllpaWriteResult:
184+
"""
185+
Executes the Speaker-Listener Label Propagation algorithm (SLLPA) and writes the results back to the database.
186+
187+
Parameters
188+
----------
189+
G : GraphV2
190+
The graph to run the algorithm on
191+
write_property : str
192+
The property name to store the community ID for each node in the database
193+
concurrency : Optional[int], default=None
194+
The number of concurrent threads
195+
job_id : Optional[str], default=None
196+
An identifier for the job
197+
log_progress : bool, default=True
198+
Whether to log progress
199+
min_association_strength : Optional[float], default=None
200+
Minimum association strength for community assignment
201+
node_labels : Optional[List[str]], default=None
202+
Filter nodes with specific labels
203+
partitioning : Optional[Any], default=None
204+
Partitioning configuration for the algorithm
205+
relationship_types : Optional[List[str]], default=None
206+
Filter relationships with specific types
207+
sudo : Optional[bool], default=False
208+
Run with elevated privileges
209+
username : Optional[str], default=None
210+
Username for authentication
211+
write_concurrency : Optional[int], default=None
212+
The number of concurrent threads for writing
213+
214+
Returns
215+
-------
216+
SllpaWriteResult
217+
An object containing metadata about the algorithm execution and the write operation
218+
"""
219+
...
220+
221+
@abstractmethod
222+
def estimate(
223+
self,
224+
G: Union[GraphV2, dict[str, Any]],
225+
*,
226+
max_iterations: int,
227+
concurrency: Optional[int] = None,
228+
min_association_strength: Optional[float] = None,
229+
node_labels: Optional[List[str]] = None,
230+
partitioning: Optional[Any] = None,
231+
relationship_types: Optional[List[str]] = None,
232+
) -> EstimationResult:
233+
"""
234+
Estimates the memory consumption for running the Speaker-Listener Label Propagation algorithm (SLLPA).
235+
236+
Parameters
237+
----------
238+
G : Union[GraphV2, dict[str, Any]]
239+
The graph to estimate for, or a graph configuration dictionary
240+
concurrency : Optional[int], default=None
241+
The number of concurrent threads
242+
min_association_strength : Optional[float], default=None
243+
Minimum association strength for community assignment
244+
node_labels : Optional[List[str]], default=None
245+
Filter nodes with specific labels
246+
partitioning : Optional[Any], default=None
247+
Partitioning configuration for the algorithm
248+
relationship_types : Optional[List[str]], default=None
249+
Filter relationships with specific types
250+
251+
Returns
252+
-------
253+
EstimationResult
254+
An object containing the memory estimation
255+
"""
256+
...
257+
258+
259+
class SllpaMutateResult(BaseResult):
260+
"""
261+
Represents the result of the Speaker-Listener Label Propagation algorithm (SLLPA) mutate operation.
262+
263+
Attributes
264+
----------
265+
ran_iterations : int
266+
The number of iterations the algorithm ran
267+
did_converge : bool
268+
Whether the algorithm converged
269+
pre_processing_millis : int
270+
Time spent preprocessing in milliseconds
271+
compute_millis : int
272+
Time spent computing in milliseconds
273+
mutate_millis : int
274+
Time spent writing results to the graph in milliseconds
275+
node_properties_written : int
276+
The number of node properties written
277+
configuration : dict
278+
The configuration used for the algorithm
279+
"""
280+
281+
ran_iterations: int
282+
did_converge: bool
283+
pre_processing_millis: int
284+
compute_millis: int
285+
mutate_millis: int
286+
node_properties_written: int
287+
configuration: dict[str, Any]
288+
289+
290+
class SllpaStatsResult(BaseResult):
291+
"""
292+
Represents the result of the Speaker-Listener Label Propagation algorithm (SLLPA) stats operation.
293+
294+
Attributes
295+
----------
296+
ran_iterations : int
297+
The number of iterations the algorithm ran
298+
did_converge : bool
299+
Whether the algorithm converged
300+
pre_processing_millis : int
301+
Time spent preprocessing in milliseconds
302+
compute_millis : int
303+
Time spent computing in milliseconds
304+
configuration : dict
305+
The configuration used for the algorithm
306+
"""
307+
308+
ran_iterations: int
309+
did_converge: bool
310+
pre_processing_millis: int
311+
compute_millis: int
312+
configuration: dict[str, Any]
313+
314+
315+
class SllpaWriteResult(BaseResult):
316+
"""
317+
Represents the result of the Speaker-Listener Label Propagation algorithm (SLLPA) write operation.
318+
319+
Attributes
320+
----------
321+
ran_iterations : int
322+
The number of iterations the algorithm ran
323+
did_converge : bool
324+
Whether the algorithm converged
325+
pre_processing_millis : int
326+
Time spent preprocessing in milliseconds
327+
compute_millis : int
328+
Time spent computing in milliseconds
329+
write_millis : int
330+
Time spent writing results to the database in milliseconds
331+
node_properties_written : int
332+
The number of node properties written
333+
configuration : dict
334+
The configuration used for the algorithm
335+
"""
336+
337+
ran_iterations: int
338+
did_converge: bool
339+
pre_processing_millis: int
340+
compute_millis: int
341+
write_millis: int
342+
node_properties_written: int
343+
configuration: dict[str, Any]

0 commit comments

Comments
 (0)