|
| 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 CliqueCountingEndpoints(ABC): |
| 14 | + @abstractmethod |
| 15 | + def mutate( |
| 16 | + self, |
| 17 | + G: GraphV2, |
| 18 | + mutate_property: str, |
| 19 | + concurrency: Optional[int] = 4, |
| 20 | + job_id: Optional[str] = None, |
| 21 | + log_progress: bool = True, |
| 22 | + node_labels: Optional[List[str]] = None, |
| 23 | + relationship_types: Optional[List[str]] = None, |
| 24 | + sudo: Optional[bool] = False, |
| 25 | + username: Optional[str] = None, |
| 26 | + ) -> CliqueCountingMutateResult: |
| 27 | + """ |
| 28 | + Executes the clique counting algorithm and writes the results to the in-memory graph as node properties. |
| 29 | +
|
| 30 | + Parameters |
| 31 | + ---------- |
| 32 | + G : GraphV2 |
| 33 | + The graph to run the algorithm on |
| 34 | + mutate_property : str |
| 35 | + The property name to store the clique counts for each node |
| 36 | + concurrency : Optional[int], default=4 |
| 37 | + The number of concurrent threads |
| 38 | + job_id : Optional[str], default=None |
| 39 | + An identifier for the job |
| 40 | + log_progress : bool, default=True |
| 41 | + Whether to log progress |
| 42 | + node_labels : Optional[List[str]], default=None |
| 43 | + The node labels used to select nodes for this algorithm run |
| 44 | + relationship_types : Optional[List[str]], default=None |
| 45 | + The relationship types used to select relationships for this algorithm run |
| 46 | + sudo : Optional[bool], default=False |
| 47 | + Override memory estimation limits |
| 48 | + username : Optional[str], default=None |
| 49 | + The username to attribute the procedure run to |
| 50 | +
|
| 51 | + Returns |
| 52 | + ------- |
| 53 | + CliqueCountingMutateResult |
| 54 | + Algorithm metrics and statistics |
| 55 | + """ |
| 56 | + pass |
| 57 | + |
| 58 | + @abstractmethod |
| 59 | + def stats( |
| 60 | + self, |
| 61 | + G: GraphV2, |
| 62 | + concurrency: Optional[int] = 4, |
| 63 | + job_id: Optional[str] = None, |
| 64 | + log_progress: bool = True, |
| 65 | + node_labels: Optional[List[str]] = None, |
| 66 | + relationship_types: Optional[List[str]] = None, |
| 67 | + sudo: Optional[bool] = False, |
| 68 | + username: Optional[str] = None, |
| 69 | + ) -> CliqueCountingStatsResult: |
| 70 | + """ |
| 71 | + Executes the clique counting algorithm and returns statistics. |
| 72 | +
|
| 73 | + Parameters |
| 74 | + ---------- |
| 75 | + G : GraphV2 |
| 76 | + The graph to run the algorithm on |
| 77 | + concurrency : Optional[int], default=4 |
| 78 | + The number of concurrent threads |
| 79 | + job_id : Optional[str], default=None |
| 80 | + An identifier for the job |
| 81 | + log_progress : bool, default=True |
| 82 | + Whether to log progress |
| 83 | + node_labels : Optional[List[str]], default=None |
| 84 | + The node labels used to select nodes for this algorithm run |
| 85 | + relationship_types : Optional[List[str]], default=None |
| 86 | + The relationship types used to select relationships for this algorithm run |
| 87 | + sudo : Optional[bool], default=False |
| 88 | + Override memory estimation limits |
| 89 | + username : Optional[str], default=None |
| 90 | + The username to attribute the procedure run to |
| 91 | +
|
| 92 | + Returns |
| 93 | + ------- |
| 94 | + CliqueCountingStatsResult |
| 95 | + Algorithm metrics and statistics |
| 96 | + """ |
| 97 | + pass |
| 98 | + |
| 99 | + @abstractmethod |
| 100 | + def stream( |
| 101 | + self, |
| 102 | + G: GraphV2, |
| 103 | + concurrency: Optional[int] = 4, |
| 104 | + job_id: Optional[str] = None, |
| 105 | + log_progress: bool = True, |
| 106 | + node_labels: Optional[List[str]] = None, |
| 107 | + relationship_types: Optional[List[str]] = None, |
| 108 | + sudo: Optional[bool] = False, |
| 109 | + username: Optional[str] = None, |
| 110 | + ) -> DataFrame: |
| 111 | + """ |
| 112 | + Executes the clique counting algorithm and returns a stream of results. |
| 113 | +
|
| 114 | + Parameters |
| 115 | + ---------- |
| 116 | + G : GraphV2 |
| 117 | + The graph to run the algorithm on |
| 118 | + concurrency : Optional[int], default=4 |
| 119 | + The number of concurrent threads |
| 120 | + job_id : Optional[str], default=None |
| 121 | + An identifier for the job |
| 122 | + log_progress : bool, default=True |
| 123 | + Whether to log progress |
| 124 | + node_labels : Optional[List[str]], default=None |
| 125 | + The node labels used to select nodes for this algorithm run |
| 126 | + relationship_types : Optional[List[str]], default=None |
| 127 | + The relationship types used to select relationships for this algorithm run |
| 128 | + sudo : Optional[bool], default=False |
| 129 | + Override memory estimation limits |
| 130 | + username : Optional[str], default=None |
| 131 | + The username to attribute the procedure run to |
| 132 | +
|
| 133 | + Returns |
| 134 | + ------- |
| 135 | + DataFrame |
| 136 | + DataFrame with the algorithm results |
| 137 | + """ |
| 138 | + pass |
| 139 | + |
| 140 | + @abstractmethod |
| 141 | + def write( |
| 142 | + self, |
| 143 | + G: GraphV2, |
| 144 | + write_property: str, |
| 145 | + concurrency: Optional[int] = 4, |
| 146 | + job_id: Optional[str] = None, |
| 147 | + log_progress: bool = True, |
| 148 | + node_labels: Optional[List[str]] = None, |
| 149 | + relationship_types: Optional[List[str]] = None, |
| 150 | + sudo: Optional[bool] = False, |
| 151 | + username: Optional[str] = None, |
| 152 | + write_concurrency: Optional[int] = None, |
| 153 | + write_to_result_store: Optional[bool] = False, |
| 154 | + ) -> CliqueCountingWriteResult: |
| 155 | + """ |
| 156 | + Executes the clique counting algorithm and writes the results back to the database. |
| 157 | +
|
| 158 | + Parameters |
| 159 | + ---------- |
| 160 | + G : GraphV2 |
| 161 | + The graph to run the algorithm on |
| 162 | + write_property : str |
| 163 | + The property name to write the clique counts to |
| 164 | + concurrency : Optional[int], default=4 |
| 165 | + The number of concurrent threads |
| 166 | + job_id : Optional[str], default=None |
| 167 | + An identifier for the job |
| 168 | + log_progress : bool, default=True |
| 169 | + Whether to log progress |
| 170 | + node_labels : Optional[List[str]], default=None |
| 171 | + The node labels used to select nodes for this algorithm run |
| 172 | + relationship_types : Optional[List[str]], default=None |
| 173 | + The relationship types used to select relationships for this algorithm run |
| 174 | + sudo : Optional[bool], default=False |
| 175 | + Override memory estimation limits |
| 176 | + username : Optional[str], default=None |
| 177 | + The username to attribute the procedure run to |
| 178 | + write_concurrency : Optional[int], default=None |
| 179 | + The number of concurrent threads for write operations |
| 180 | + write_to_result_store : Optional[bool], default=False |
| 181 | + Whether to write to the result store |
| 182 | +
|
| 183 | + Returns |
| 184 | + ------- |
| 185 | + CliqueCountingWriteResult |
| 186 | + Algorithm metrics and statistics |
| 187 | + """ |
| 188 | + pass |
| 189 | + |
| 190 | + @abstractmethod |
| 191 | + def estimate( |
| 192 | + self, |
| 193 | + G: Union[GraphV2, dict[str, Any]], |
| 194 | + concurrency: Optional[int] = 4, |
| 195 | + node_labels: Optional[List[str]] = None, |
| 196 | + relationship_types: Optional[List[str]] = None, |
| 197 | + ) -> EstimationResult: |
| 198 | + """ |
| 199 | + Estimates the memory requirements for running the clique counting algorithm. |
| 200 | +
|
| 201 | + Parameters |
| 202 | + ---------- |
| 203 | + G : Union[GraphV2, dict[str, Any]] |
| 204 | + The graph or graph configuration to estimate for |
| 205 | + concurrency : Optional[int], default=4 |
| 206 | + The number of concurrent threads |
| 207 | + node_labels : Optional[List[str]], default=None |
| 208 | + The node labels used to select nodes for this algorithm run |
| 209 | + relationship_types : Optional[List[str]], default=None |
| 210 | + The relationship types used to select relationships for this algorithm run |
| 211 | +
|
| 212 | + Returns |
| 213 | + ------- |
| 214 | + EstimationResult |
| 215 | + The memory estimation result |
| 216 | + """ |
| 217 | + pass |
| 218 | + |
| 219 | + |
| 220 | +class CliqueCountingMutateResult(BaseResult): |
| 221 | + compute_millis: int |
| 222 | + configuration: dict[str, Any] |
| 223 | + global_count: List[Any] |
| 224 | + mutate_millis: int |
| 225 | + node_properties_written: int |
| 226 | + pre_processing_millis: int |
| 227 | + |
| 228 | + |
| 229 | +class CliqueCountingStatsResult(BaseResult): |
| 230 | + compute_millis: int |
| 231 | + configuration: dict[str, Any] |
| 232 | + global_count: List[Any] |
| 233 | + pre_processing_millis: int |
| 234 | + |
| 235 | + |
| 236 | +class CliqueCountingWriteResult(BaseResult): |
| 237 | + compute_millis: int |
| 238 | + configuration: dict[str, Any] |
| 239 | + global_count: List[Any] |
| 240 | + node_properties_written: int |
| 241 | + pre_processing_millis: int |
| 242 | + write_millis: int |
0 commit comments