|
| 1 | +from __future__ import annotations |
| 2 | + |
| 3 | +from abc import ABC, abstractmethod |
| 4 | +from typing import Any |
| 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.default_values import ALL_LABELS, ALL_TYPES |
| 11 | +from graphdatascience.procedure_surface.api.estimation_result import EstimationResult |
| 12 | + |
| 13 | + |
| 14 | +class MaxFlowEndpoints(ABC): |
| 15 | + @abstractmethod |
| 16 | + def mutate( |
| 17 | + self, |
| 18 | + G: GraphV2, |
| 19 | + mutate_property: str, |
| 20 | + mutate_relationship_type: str, |
| 21 | + *, |
| 22 | + capacity_property: str | None = None, |
| 23 | + concurrency: int | None = None, |
| 24 | + job_id: str | None = None, |
| 25 | + log_progress: bool = True, |
| 26 | + node_labels: list[str] = ALL_LABELS, |
| 27 | + relationship_types: list[str] = ALL_TYPES, |
| 28 | + source_nodes: list[int] | None = None, |
| 29 | + sudo: bool = False, |
| 30 | + target_nodes: list[int] | None = None, |
| 31 | + username: str | None = None, |
| 32 | + ) -> MaxFlowMutateResult: |
| 33 | + """ |
| 34 | + Runs the Max Flow algorithm and stores the results in the graph catalog. |
| 35 | +
|
| 36 | + Parameters |
| 37 | + ---------- |
| 38 | + G |
| 39 | + Graph object to use |
| 40 | + mutate_property |
| 41 | + Name of the node property to store the flow results in. |
| 42 | + mutate_relationship_type |
| 43 | + Name of the relationship type to store the flow relationships in. |
| 44 | + capacity_property |
| 45 | + Name of the relationship property containing capacities. |
| 46 | + concurrency |
| 47 | + Number of concurrent threads to use. |
| 48 | + job_id |
| 49 | + Identifier for the computation. |
| 50 | + log_progress |
| 51 | + Display progress logging. |
| 52 | + node_labels |
| 53 | + Filter the graph using the given node labels. Nodes with any of the given labels will be included. |
| 54 | + relationship_types |
| 55 | + Filter the graph using the given relationship types. Relationships with any of the given types will be included. |
| 56 | + source_nodes |
| 57 | + List of source node IDs. |
| 58 | + sudo |
| 59 | + Disable the memory guard. |
| 60 | + target_nodes |
| 61 | + List of target node IDs. |
| 62 | + username |
| 63 | + As an administrator, impersonate a different user for accessing their graphs. |
| 64 | +
|
| 65 | + Returns |
| 66 | + ------- |
| 67 | + MaxFlowMutateResult |
| 68 | + Algorithm metrics and statistics |
| 69 | + """ |
| 70 | + pass |
| 71 | + |
| 72 | + @abstractmethod |
| 73 | + def stats( |
| 74 | + self, |
| 75 | + G: GraphV2, |
| 76 | + *, |
| 77 | + capacity_property: str | None = None, |
| 78 | + concurrency: int | None = None, |
| 79 | + job_id: str | None = None, |
| 80 | + log_progress: bool = True, |
| 81 | + node_labels: list[str] = ALL_LABELS, |
| 82 | + relationship_types: list[str] = ALL_TYPES, |
| 83 | + source_nodes: list[int] | None = None, |
| 84 | + sudo: bool = False, |
| 85 | + target_nodes: list[int] | None = None, |
| 86 | + username: str | None = None, |
| 87 | + ) -> MaxFlowStatsResult: |
| 88 | + """ |
| 89 | + Runs the Max Flow algorithm and returns statistics. |
| 90 | +
|
| 91 | + Parameters |
| 92 | + ---------- |
| 93 | + G |
| 94 | + Graph object to use |
| 95 | + capacity_property |
| 96 | + Name of the relationship property containing capacities. |
| 97 | + concurrency |
| 98 | + Number of concurrent threads to use. |
| 99 | + job_id |
| 100 | + Identifier for the computation. |
| 101 | + log_progress |
| 102 | + Display progress logging. |
| 103 | + node_labels |
| 104 | + Filter the graph using the given node labels. Nodes with any of the given labels will be included. |
| 105 | + relationship_types |
| 106 | + Filter the graph using the given relationship types. Relationships with any of the given types will be included. |
| 107 | + source_nodes |
| 108 | + List of source node IDs. |
| 109 | + sudo |
| 110 | + Disable the memory guard. |
| 111 | + target_nodes |
| 112 | + List of target node IDs. |
| 113 | + username |
| 114 | + As an administrator, impersonate a different user for accessing their graphs. |
| 115 | +
|
| 116 | + Returns |
| 117 | + ------- |
| 118 | + MaxFlowStatsResult |
| 119 | + Algorithm metrics and statistics |
| 120 | + """ |
| 121 | + pass |
| 122 | + |
| 123 | + @abstractmethod |
| 124 | + def stream( |
| 125 | + self, |
| 126 | + G: GraphV2, |
| 127 | + *, |
| 128 | + capacity_property: str | None = None, |
| 129 | + concurrency: int | None = None, |
| 130 | + job_id: str | None = None, |
| 131 | + log_progress: bool = True, |
| 132 | + node_labels: list[str] = ALL_LABELS, |
| 133 | + relationship_types: list[str] = ALL_TYPES, |
| 134 | + source_nodes: list[int] | None = None, |
| 135 | + sudo: bool = False, |
| 136 | + target_nodes: list[int] | None = None, |
| 137 | + username: str | None = None, |
| 138 | + ) -> DataFrame: |
| 139 | + """ |
| 140 | + Runs the Max Flow algorithm and returns a stream of results. |
| 141 | +
|
| 142 | + Parameters |
| 143 | + ---------- |
| 144 | + G |
| 145 | + Graph object to use |
| 146 | + capacity_property |
| 147 | + Name of the relationship property containing capacities. |
| 148 | + concurrency |
| 149 | + Number of concurrent threads to use. |
| 150 | + job_id |
| 151 | + Identifier for the computation. |
| 152 | + log_progress |
| 153 | + Display progress logging. |
| 154 | + node_labels |
| 155 | + Filter the graph using the given node labels. Nodes with any of the given labels will be included. |
| 156 | + relationship_types |
| 157 | + Filter the graph using the given relationship types. Relationships with any of the given types will be included. |
| 158 | + source_nodes |
| 159 | + List of source node IDs. |
| 160 | + sudo |
| 161 | + Disable the memory guard. |
| 162 | + target_nodes |
| 163 | + List of target node IDs. |
| 164 | + username |
| 165 | + As an administrator, impersonate a different user for accessing their graphs. |
| 166 | +
|
| 167 | + Returns |
| 168 | + ------- |
| 169 | + DataFrame |
| 170 | + DataFrame with the algorithm results containing 'source', 'target', and 'flow' columns |
| 171 | + """ |
| 172 | + pass |
| 173 | + |
| 174 | + @abstractmethod |
| 175 | + def write( |
| 176 | + self, |
| 177 | + G: GraphV2, |
| 178 | + write_property: str, |
| 179 | + write_relationship_type: str, |
| 180 | + *, |
| 181 | + capacity_property: str | None = None, |
| 182 | + concurrency: int | None = None, |
| 183 | + job_id: str | None = None, |
| 184 | + log_progress: bool = True, |
| 185 | + node_labels: list[str] = ALL_LABELS, |
| 186 | + relationship_types: list[str] = ALL_TYPES, |
| 187 | + source_nodes: list[int] | None = None, |
| 188 | + sudo: bool = False, |
| 189 | + target_nodes: list[int] | None = None, |
| 190 | + username: str | None = None, |
| 191 | + write_concurrency: int | None = None, |
| 192 | + ) -> MaxFlowWriteResult: |
| 193 | + """ |
| 194 | + Runs the Max Flow algorithm and writes the results to the Neo4j database. |
| 195 | +
|
| 196 | + Parameters |
| 197 | + ---------- |
| 198 | + G |
| 199 | + Graph object to use |
| 200 | + write_property |
| 201 | + Name of the node property to store the flow results in. |
| 202 | + write_relationship_type |
| 203 | + Name of the relationship type to store the flow relationships in. |
| 204 | + capacity_property |
| 205 | + Name of the relationship property containing capacities. |
| 206 | + concurrency |
| 207 | + Number of concurrent threads to use. |
| 208 | + job_id |
| 209 | + Identifier for the computation. |
| 210 | + log_progress |
| 211 | + Display progress logging. |
| 212 | + node_labels |
| 213 | + Filter the graph using the given node labels. Nodes with any of the given labels will be included. |
| 214 | + relationship_types |
| 215 | + Filter the graph using the given relationship types. Relationships with any of the given types will be included. |
| 216 | + source_nodes |
| 217 | + List of source node IDs. |
| 218 | + sudo |
| 219 | + Disable the memory guard. |
| 220 | + target_nodes |
| 221 | + List of target node IDs. |
| 222 | + username |
| 223 | + As an administrator, impersonate a different user for accessing their graphs. |
| 224 | + write_concurrency |
| 225 | + Number of concurrent threads to use for writing. |
| 226 | +
|
| 227 | + Returns |
| 228 | + ------- |
| 229 | + MaxFlowWriteResult |
| 230 | + Algorithm metrics and statistics |
| 231 | + """ |
| 232 | + pass |
| 233 | + |
| 234 | + @abstractmethod |
| 235 | + def estimate( |
| 236 | + self, |
| 237 | + G: GraphV2 | dict[str, Any], |
| 238 | + *, |
| 239 | + capacity_property: str | None = None, |
| 240 | + concurrency: int | None = None, |
| 241 | + node_labels: list[str] = ALL_LABELS, |
| 242 | + relationship_types: list[str] = ALL_TYPES, |
| 243 | + source_nodes: list[int] | None = None, |
| 244 | + target_nodes: list[int] | None = None, |
| 245 | + ) -> EstimationResult: |
| 246 | + """ |
| 247 | + Estimate the memory consumption of an algorithm run. |
| 248 | +
|
| 249 | + Parameters |
| 250 | + ---------- |
| 251 | + G |
| 252 | + Graph object to use or a dictionary representing the graph dimensions. |
| 253 | + capacity_property |
| 254 | + Name of the relationship property containing capacities. |
| 255 | + concurrency |
| 256 | + Number of concurrent threads to use. |
| 257 | + node_labels |
| 258 | + Filter the graph using the given node labels. Nodes with any of the given labels will be included. |
| 259 | + relationship_types |
| 260 | + Filter the graph using the given relationship types. Relationships with any of the given types will be included. |
| 261 | + source_nodes |
| 262 | + List of source node IDs. |
| 263 | + target_nodes |
| 264 | + List of target node IDs. |
| 265 | +
|
| 266 | + Returns |
| 267 | + ------- |
| 268 | + EstimationResult |
| 269 | + Memory estimation details |
| 270 | + """ |
| 271 | + pass |
| 272 | + |
| 273 | + |
| 274 | +class MaxFlowMutateResult(BaseResult): |
| 275 | + total_flow: float |
| 276 | + pre_processing_millis: int |
| 277 | + compute_millis: int |
| 278 | + mutate_millis: int |
| 279 | + relationships_written: int |
| 280 | + configuration: dict[str, Any] |
| 281 | + |
| 282 | + |
| 283 | +class MaxFlowStatsResult(BaseResult): |
| 284 | + total_flow: float |
| 285 | + pre_processing_millis: int |
| 286 | + compute_millis: int |
| 287 | + post_processing_millis: int |
| 288 | + configuration: dict[str, Any] |
| 289 | + |
| 290 | + |
| 291 | +class MaxFlowWriteResult(BaseResult): |
| 292 | + total_flow: float |
| 293 | + pre_processing_millis: int |
| 294 | + compute_millis: int |
| 295 | + write_millis: int |
| 296 | + relationships_written: int |
| 297 | + configuration: dict[str, Any] |
0 commit comments