graphdatascience 2.0a5__py3-none-any.whl → 2.0a6__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. graphdatascience/arrow_client/arrow_endpoint_version.py +3 -1
  2. graphdatascience/arrow_client/authenticated_flight_client.py +43 -14
  3. graphdatascience/arrow_client/v2/job_client.py +33 -7
  4. graphdatascience/graph/graph_info.py +9 -0
  5. graphdatascience/procedure_surface/api/base_result.py +18 -0
  6. graphdatascience/procedure_surface/api/catalog/node_properties_endpoints.py +4 -4
  7. graphdatascience/procedure_surface/api/catalog/node_property_endpoints.py +5 -1
  8. graphdatascience/procedure_surface/api/catalog/relationship_properties_endpoints.py +5 -1
  9. graphdatascience/procedure_surface/api/catalog/relationship_property_endpoints.py +5 -1
  10. graphdatascience/procedure_surface/api/catalog/relationships_endpoints.py +4 -1
  11. graphdatascience/procedure_surface/api/centrality/hits_endpoints.py +38 -2
  12. graphdatascience/procedure_surface/api/descriptions.py +3 -0
  13. graphdatascience/procedure_surface/api/node_embedding/config.py +57 -0
  14. graphdatascience/procedure_surface/api/node_embedding/embeddings_endpoints.py +29 -0
  15. graphdatascience/procedure_surface/api/node_embedding/encode_endpoints.py +226 -0
  16. graphdatascience/procedure_surface/api/node_embedding/graphsage_endpoints.py +1 -1
  17. graphdatascience/procedure_surface/api/node_embedding/graphsage_train_endpoints.py +1 -1
  18. graphdatascience/procedure_surface/api/node_embedding/hashgnn_endpoints.py +4 -4
  19. graphdatascience/procedure_surface/api/node_embedding/predict_endpoints.py +219 -0
  20. graphdatascience/procedure_surface/api/node_embedding/train_endpoints.py +156 -0
  21. graphdatascience/procedure_surface/arrow/catalog/node_properties_arrow_endpoints.py +2 -2
  22. graphdatascience/procedure_surface/arrow/catalog/relationship_arrow_endpoints.py +2 -0
  23. graphdatascience/procedure_surface/arrow/centrality/hits_arrow_endpoints.py +253 -0
  24. graphdatascience/procedure_surface/arrow/node_embedding/embeddings_arrow_endpoints.py +32 -0
  25. graphdatascience/procedure_surface/arrow/node_embedding/encode_arrow_endpoints.py +175 -0
  26. graphdatascience/procedure_surface/arrow/node_embedding/predict_arrow_endpoints.py +174 -0
  27. graphdatascience/procedure_surface/arrow/node_embedding/train_arrow_endpoints.py +149 -0
  28. graphdatascience/procedure_surface/cypher/catalog/node_properties_cypher_endpoints.py +4 -3
  29. graphdatascience/procedure_surface/cypher/catalog/projection_cypher_endpoints.py +11 -2
  30. graphdatascience/procedure_surface/cypher/catalog/relationship_cypher_endpoints.py +2 -0
  31. graphdatascience/procedure_surface/cypher/centrality/hits_cypher_endpoints.py +28 -0
  32. graphdatascience/session/aura_graph_data_science.py +22 -0
  33. graphdatascience/session/gds_sessions.py +8 -4
  34. graphdatascience/session/remote_ops/project_protocols.py +4 -0
  35. graphdatascience/session/remote_ops/write_protocols.py +41 -12
  36. graphdatascience/version.py +1 -1
  37. {graphdatascience-2.0a5.dist-info → graphdatascience-2.0a6.dist-info}/METADATA +1 -1
  38. {graphdatascience-2.0a5.dist-info → graphdatascience-2.0a6.dist-info}/RECORD +41 -30
  39. {graphdatascience-2.0a5.dist-info → graphdatascience-2.0a6.dist-info}/WHEEL +0 -0
  40. {graphdatascience-2.0a5.dist-info → graphdatascience-2.0a6.dist-info}/licenses/LICENSE +0 -0
  41. {graphdatascience-2.0a5.dist-info → graphdatascience-2.0a6.dist-info}/top_level.txt +0 -0
@@ -19,7 +19,9 @@ class ArrowEndpointVersion(Enum):
19
19
  def check_version_compatibility(
20
20
  compatible_versions: set[ArrowEndpointVersion], arrow_client: AuthenticatedArrowClient
21
21
  ) -> None:
22
- supported_server_versions = {action.type.split("/")[0].lower() for action in arrow_client.list_actions()}
22
+ supported_server_versions = {
23
+ action.type.split("/")[0].lower() for action in arrow_client.list_actions_with_retry()
24
+ }
23
25
  for version in compatible_versions:
24
26
  if version.version() in supported_server_versions:
25
27
  return
@@ -13,6 +13,7 @@ from pyarrow import __version__ as arrow_version
13
13
  from pyarrow.flight import (
14
14
  Action,
15
15
  ActionType,
16
+ FlightCallOptions,
16
17
  FlightInternalError,
17
18
  FlightStreamReader,
18
19
  FlightTimedOutError,
@@ -32,6 +33,12 @@ from .middleware.user_agent_middleware import UserAgentFactory
32
33
 
33
34
  T = TypeVar("T")
34
35
 
36
+ FLIGHT_TRANSIENT_EXCEPTIONS = (
37
+ FlightTimedOutError,
38
+ FlightUnavailableError,
39
+ FlightInternalError,
40
+ )
41
+
35
42
 
36
43
  class AuthenticatedArrowClient:
37
44
  """Arrow Flight client used to communicate with the GDS Arrow server."""
@@ -58,7 +65,9 @@ class AuthenticatedArrowClient:
58
65
  encrypted
59
66
  A flag that indicates whether the connection should be encrypted (default is False)
60
67
  arrow_client_options
61
- Additional options to be passed to the Arrow Flight client.
68
+ Additional options for the Arrow Flight client. The key ``call_timeout`` sets the
69
+ per-call RPC timeout in seconds (default 30s); all other keys are forwarded to
70
+ ``pyarrow.flight.FlightClient``.
62
71
  user_agent
63
72
  The user agent string to use for the connection. (default is `neo4j-graphdatascience-v[VERSION] pyarrow-v[PYARROW_VERSION]`)
64
73
  retry_config
@@ -78,26 +87,27 @@ class AuthenticatedArrowClient:
78
87
 
79
88
  if retry_config is None:
80
89
  retry_config = RetryConfigV2(
81
- retryable_exceptions=[
82
- FlightTimedOutError,
83
- FlightUnavailableError,
84
- FlightInternalError,
85
- ],
90
+ retryable_exceptions=list(FLIGHT_TRANSIENT_EXCEPTIONS),
86
91
  stop_config=StopConfig(after_delay=10, after_attempt=5),
87
92
  wait_config=ExponentialWaitConfig(multiplier=1, min=1, max=10),
88
93
  )
89
94
 
95
+ options_copy = dict(arrow_client_options) if arrow_client_options else {}
96
+ call_timeout = options_copy.pop("call_timeout", 30.0)
97
+
90
98
  self._host = host
91
99
  self._port = int(port)
92
100
  self._auth = auth
93
101
  self._encrypted = encrypted
94
- self._arrow_client_options = arrow_client_options
102
+ self._arrow_client_options = options_copy or None
95
103
  self._user_agent = user_agent
96
104
  self._logger = logging.getLogger("gds_arrow_client")
97
105
  self._retry_config = retry_config
98
106
  self._health_check = health_check
99
107
  if auth:
100
108
  self._auth_middleware = AuthMiddleware(auth)
109
+ self._call_timeout = call_timeout
110
+ self._call_options = self._build_call_options()
101
111
  self.advertised_listen_address = advertised_listen_address
102
112
  self._flight_client: flight.FlightClient = self._instantiate_flight_client()
103
113
 
@@ -143,8 +153,8 @@ class AuthenticatedArrowClient:
143
153
  client = self._flight_client
144
154
  if self._auth:
145
155
  auth_pair = self._auth.auth_pair()
146
- client.authenticate_basic_token(auth_pair[0], auth_pair[1])
147
- except (FlightTimedOutError, FlightUnavailableError, FlightInternalError):
156
+ client.authenticate_basic_token(auth_pair[0], auth_pair[1], self._call_options)
157
+ except FLIGHT_TRANSIENT_EXCEPTIONS:
148
158
  self._reconnect()
149
159
  raise
150
160
 
@@ -160,7 +170,7 @@ class AuthenticatedArrowClient:
160
170
  def do_action(self, endpoint: str, payload: bytes | dict[str, Any]) -> Iterator[Result]:
161
171
  payload_bytes = payload if isinstance(payload, bytes) else json.dumps(payload).encode("utf-8")
162
172
 
163
- return self._flight_client.do_action(Action(endpoint, payload_bytes)) # type: ignore
173
+ return self._flight_client.do_action(Action(endpoint, payload_bytes), self._call_options) # type: ignore
164
174
 
165
175
  def do_action_with_retry(self, endpoint: str, payload: bytes | dict[str, Any]) -> list[Result]:
166
176
  @self._retry_config.decorator(operation_name="Send action", logger=self._logger)
@@ -169,14 +179,25 @@ class AuthenticatedArrowClient:
169
179
  # the Flight response error code is only checked on iterator consumption
170
180
  # we eagerly collect iterator here to trigger retry in case of an error
171
181
  return list(self.do_action(endpoint, payload))
172
- except (FlightTimedOutError, FlightUnavailableError, FlightInternalError):
182
+ except FLIGHT_TRANSIENT_EXCEPTIONS:
173
183
  self._reconnect()
174
184
  raise
175
185
 
176
186
  return self._diagnose_connection_failure(run_with_retry)
177
187
 
178
188
  def list_actions(self) -> set[ActionType]:
179
- return self._flight_client.list_actions() # type: ignore
189
+ return self._flight_client.list_actions(self._call_options) # type: ignore
190
+
191
+ def list_actions_with_retry(self) -> set[ActionType]:
192
+ @self._retry_config.decorator(operation_name="List actions", logger=self._logger)
193
+ def run_with_retry() -> set[ActionType]:
194
+ try:
195
+ return self.list_actions()
196
+ except (FlightTimedOutError, FlightUnavailableError, FlightInternalError):
197
+ self._reconnect()
198
+ raise
199
+
200
+ return self._diagnose_connection_failure(run_with_retry)
180
201
 
181
202
  def do_put_with_retry(
182
203
  self, descriptor: flight.FlightDescriptor, schema: Schema
@@ -185,7 +206,7 @@ class AuthenticatedArrowClient:
185
206
  def run_with_retry() -> tuple[flight.FlightStreamWriter, flight.FlightMetadataReader]:
186
207
  try:
187
208
  return self._flight_client.do_put(descriptor, schema) # type: ignore
188
- except (FlightTimedOutError, FlightUnavailableError, FlightInternalError):
209
+ except FLIGHT_TRANSIENT_EXCEPTIONS:
189
210
  self._reconnect()
190
211
  raise
191
212
 
@@ -198,7 +219,7 @@ class AuthenticatedArrowClient:
198
219
  """
199
220
  try:
200
221
  return operation()
201
- except (FlightTimedOutError, FlightUnavailableError, FlightInternalError):
222
+ except FLIGHT_TRANSIENT_EXCEPTIONS:
202
223
  if self._health_check:
203
224
  self._health_check.raise_if_unhealthy()
204
225
  raise
@@ -218,6 +239,9 @@ class AuthenticatedArrowClient:
218
239
  if self._flight_client:
219
240
  self._flight_client.close()
220
241
 
242
+ def _build_call_options(self) -> FlightCallOptions | None:
243
+ return FlightCallOptions(timeout=self._call_timeout) if self._call_timeout is not None else None
244
+
221
245
  def _instantiate_flight_client(self) -> flight.FlightClient:
222
246
  location = (
223
247
  flight.Location.for_grpc_tls(self._host, self._port)
@@ -248,11 +272,16 @@ class AuthenticatedArrowClient:
248
272
  # Remove the FlightClient as it isn't serializable
249
273
  if "_flight_client" in state:
250
274
  del state["_flight_client"]
275
+ # FlightCallOptions is also not serializable
276
+ if "_call_options" in state:
277
+ del state["_call_options"]
251
278
  return state
252
279
 
253
280
  def __setstate__(self, state: dict[str, Any]) -> None:
254
281
  self.__dict__.update(state)
255
282
  self.__dict__.setdefault("_health_check", None)
283
+ self.__dict__.setdefault("_call_timeout", 30.0)
284
+ self.__dict__.setdefault("_call_options", self._build_call_options())
256
285
  self._flight_client = self._instantiate_flight_client()
257
286
 
258
287
  def _reconnect(self) -> None:
@@ -1,16 +1,22 @@
1
1
  import json
2
+ import logging
3
+ import uuid
2
4
  from typing import Any
3
5
 
4
6
  from pandas import ArrowDtype, DataFrame
7
+ from pyarrow import ArrowKeyError
5
8
  from pyarrow.flight import Ticket
6
- from tenacity import Retrying, retry_if_result
9
+ from tenacity import Retrying, retry_if_exception, retry_if_result, stop_after_attempt, wait_fixed
7
10
 
8
- from graphdatascience.arrow_client.authenticated_flight_client import AuthenticatedArrowClient
11
+ from graphdatascience.arrow_client.authenticated_flight_client import (
12
+ FLIGHT_TRANSIENT_EXCEPTIONS,
13
+ AuthenticatedArrowClient,
14
+ )
9
15
  from graphdatascience.arrow_client.v2.api_types import JobIdConfig, JobStatus
10
16
  from graphdatascience.arrow_client.v2.data_mapper_utils import deserialize_single
11
17
  from graphdatascience.progress.progress_bar import TqdmProgressBar
12
18
  from graphdatascience.query_runner.termination_flag import TerminationFlag
13
- from graphdatascience.retry_utils.retry_utils import job_wait_strategy
19
+ from graphdatascience.retry_utils.retry_utils import before_log, job_wait_strategy
14
20
 
15
21
  JOB_STATUS_ENDPOINT = "v2/jobs.status"
16
22
  JOBS_CANCEL_ENDPOINT = "v2/jobs.cancel"
@@ -31,10 +37,30 @@ class JobClient:
31
37
 
32
38
  @staticmethod
33
39
  def run_job(client: AuthenticatedArrowClient, endpoint: str, config: dict[str, Any]) -> str:
34
- res = client.do_action_with_retry(endpoint, config)
35
-
36
- single = deserialize_single(res)
37
- return JobIdConfig(**single).job_id
40
+ job_id: str = config.setdefault("jobId", str(uuid.uuid4()))
41
+ logger = logging.getLogger(__name__)
42
+
43
+ for attempt in Retrying(
44
+ stop=stop_after_attempt(3),
45
+ wait=wait_fixed(2),
46
+ retry=retry_if_exception(lambda e: isinstance(e, FLIGHT_TRANSIENT_EXCEPTIONS)),
47
+ before=before_log(f"run_job ({endpoint})", logger, logging.DEBUG),
48
+ reraise=True,
49
+ ):
50
+ with attempt:
51
+ try:
52
+ res = client.do_action_with_retry(endpoint, config)
53
+ return JobIdConfig(**deserialize_single(res)).job_id
54
+ except FLIGHT_TRANSIENT_EXCEPTIONS as e:
55
+ try:
56
+ JobClient.get_job_status(client, job_id)
57
+ logger.debug(f"Job '{job_id}' already started, recovering job_id.")
58
+ return job_id
59
+ except ArrowKeyError:
60
+ logger.debug(f"Job '{job_id}' not found on server, will retry run_job.")
61
+ raise e
62
+
63
+ raise RuntimeError("unreachable due to retry logic above")
38
64
 
39
65
  def wait_for_job(
40
66
  self,
@@ -1,5 +1,6 @@
1
1
  from __future__ import annotations
2
2
 
3
+ import math
3
4
  import re
4
5
  from datetime import datetime
5
6
  from typing import Any
@@ -24,6 +25,14 @@ class GraphInfo(BaseResult):
24
25
  graph_schema: dict[str, Any] = Field(alias="schemaWithOrientation")
25
26
  density: float
26
27
 
28
+ @field_validator("memory_usage", mode="before")
29
+ @classmethod
30
+ def coerce_nan_to_none(cls, value: Any) -> Any:
31
+ # pandas transforms the memory_usage column with a null value to NaN
32
+ if isinstance(value, float) and math.isnan(value):
33
+ return None
34
+ return value
35
+
27
36
  @field_validator("creation_time", "modification_time", mode="before")
28
37
  @classmethod
29
38
  def strip_timezone(cls, value: Any) -> Any:
@@ -7,3 +7,21 @@ from pydantic.alias_generators import to_camel
7
7
  class BaseResult(BaseModel, alias_generator=to_camel, populate_by_name=True):
8
8
  def __getitem__(self, item: str) -> Any:
9
9
  return getattr(self, item)
10
+
11
+
12
+ class StatsResult(BaseResult):
13
+ compute_millis: int
14
+ pre_processing_millis: int
15
+ configuration: dict[str, Any]
16
+
17
+
18
+ class MutateResult(StatsResult):
19
+ mutate_millis: int
20
+
21
+
22
+ class WriteResult(StatsResult):
23
+ write_millis: int
24
+
25
+
26
+ class NodeResult(BaseResult):
27
+ node_properties_written: int
@@ -113,7 +113,7 @@ class NodePropertiesEndpoints(ABC):
113
113
  G: Graph,
114
114
  node_properties: list[str],
115
115
  *,
116
- fail_if_missing: bool | None = True,
116
+ fail_if_missing: bool = True,
117
117
  concurrency: int | None = None,
118
118
  username: str | None = None,
119
119
  ) -> NodePropertiesDropResult:
@@ -123,11 +123,11 @@ class NodePropertiesEndpoints(ABC):
123
123
  Parameters
124
124
  ----------
125
125
  G
126
- Graph object to use
126
+ Graph object to use
127
127
  node_properties
128
128
  The node properties to drop
129
- fail_if_missing: bool | None = None,
130
- Whether to fail if any of the node properties are missing
129
+ fail_if_missing
130
+ Whether to fail if any of the node properties are missing.
131
131
  concurrency
132
132
  Number of concurrent threads to use.
133
133
  username
@@ -24,6 +24,7 @@ class NodePropertyEndpoints:
24
24
  sudo: bool = False,
25
25
  log_progress: bool = True,
26
26
  username: str | None = None,
27
+ job_id: str | None = None,
27
28
  db_node_properties: list[str] | None = None,
28
29
  ) -> DataFrame:
29
30
  """
@@ -32,7 +33,7 @@ class NodePropertyEndpoints:
32
33
  Parameters
33
34
  ----------
34
35
  G
35
- Graph object to use
36
+ Graph object to use
36
37
  node_property
37
38
  The node property to stream
38
39
  list_node_labels
@@ -47,6 +48,8 @@ class NodePropertyEndpoints:
47
48
  Display progress logging.
48
49
  username
49
50
  As an administrator, impersonate a different user for accessing their graphs.
51
+ job_id
52
+ Identifier for the computation.
50
53
  db_node_properties
51
54
  Retrieves additional node properties from the database and attaches them to the stream.
52
55
  Returns
@@ -64,6 +67,7 @@ class NodePropertyEndpoints:
64
67
  sudo=sudo,
65
68
  log_progress=log_progress,
66
69
  username=username,
70
+ job_id=job_id,
67
71
  db_node_properties=db_node_properties,
68
72
  )
69
73
 
@@ -25,6 +25,7 @@ class RelationshipPropertiesEndpoints:
25
25
  sudo: bool = False,
26
26
  log_progress: bool = True,
27
27
  username: str | None = None,
28
+ job_id: str | None = None,
28
29
  ) -> RelationshipsDataFrame:
29
30
  """
30
31
  Streams the specified relationship properties for all relationships of the specified types.
@@ -32,7 +33,7 @@ class RelationshipPropertiesEndpoints:
32
33
  Parameters
33
34
  ----------
34
35
  G
35
- Graph object to use
36
+ Graph object to use
36
37
  relationship_properties
37
38
  The relationship properties to stream
38
39
  relationship_types
@@ -45,6 +46,8 @@ class RelationshipPropertiesEndpoints:
45
46
  Display progress logging.
46
47
  username
47
48
  As an administrator, impersonate a different user for accessing their graphs.
49
+ job_id
50
+ Identifier for the computation.
48
51
  Returns
49
52
  -------
50
53
  RelationshipsDataFrame
@@ -60,6 +63,7 @@ class RelationshipPropertiesEndpoints:
60
63
  sudo=sudo,
61
64
  log_progress=log_progress,
62
65
  username=username,
66
+ job_id=job_id,
63
67
  )
64
68
 
65
69
  def write(
@@ -22,6 +22,7 @@ class RelationshipPropertyEndpoints:
22
22
  sudo: bool = False,
23
23
  log_progress: bool = True,
24
24
  username: str | None = None,
25
+ job_id: str | None = None,
25
26
  ) -> RelationshipsDataFrame:
26
27
  """
27
28
  Streams the specified relationship property for all relationships of the specified types.
@@ -29,7 +30,7 @@ class RelationshipPropertyEndpoints:
29
30
  Parameters
30
31
  ----------
31
32
  G
32
- Graph object to use
33
+ Graph object to use
33
34
  relationship_property
34
35
  The relationship property to stream
35
36
  relationship_types
@@ -42,6 +43,8 @@ class RelationshipPropertyEndpoints:
42
43
  Display progress logging.
43
44
  username
44
45
  As an administrator, impersonate a different user for accessing their graphs.
46
+ job_id
47
+ Identifier for the computation.
45
48
  Returns
46
49
  -------
47
50
  RelationshipsDataFrame
@@ -56,6 +59,7 @@ class RelationshipPropertyEndpoints:
56
59
  sudo=sudo,
57
60
  log_progress=log_progress,
58
61
  username=username,
62
+ job_id=job_id,
59
63
  )
60
64
 
61
65
  return RelationshipsDataFrame(result.rename(columns={relationship_property: "propertyValue"}))
@@ -24,6 +24,7 @@ class RelationshipsEndpoints(ABC):
24
24
  sudo: bool = False,
25
25
  log_progress: bool = True,
26
26
  username: str | None = None,
27
+ job_id: str | None = None,
27
28
  ) -> RelationshipsDataFrame:
28
29
  """
29
30
  Streams all relationships of the specified types with the specified properties.
@@ -31,7 +32,7 @@ class RelationshipsEndpoints(ABC):
31
32
  Parameters
32
33
  ----------
33
34
  G
34
- Graph object to use
35
+ Graph object to use
35
36
  relationship_types
36
37
  Filter the graph using the given relationship types. Relationships with any of the given types will be included.
37
38
  relationship_properties: list[str] | None
@@ -44,6 +45,8 @@ class RelationshipsEndpoints(ABC):
44
45
  Display progress logging.
45
46
  username
46
47
  As an administrator, impersonate a different user for accessing their graphs.
48
+ job_id
49
+ Identifier for the computation.
47
50
  Returns
48
51
  -------
49
52
  RelationshipsDataFrame
@@ -8,6 +8,7 @@ from pandas import DataFrame
8
8
  from graphdatascience.graph.graph_api import Graph
9
9
  from graphdatascience.procedure_surface.api.base_result import BaseResult
10
10
  from graphdatascience.procedure_surface.api.default_values import ALL_LABELS, ALL_TYPES
11
+ from graphdatascience.procedure_surface.api.estimation_result import EstimationResult
11
12
 
12
13
 
13
14
  class HitsEndpoints(ABC):
@@ -40,7 +41,7 @@ class HitsEndpoints(ABC):
40
41
  G
41
42
  Graph object to use
42
43
  mutate_property
43
- Prefix for the names of the node properties (auth and hub) to store the results in.
44
+ Postfix for the names of the node properties (auth and hub) to store the results in.
44
45
  hits_iterations
45
46
  Number of iterations to run HITS for.
46
47
  auth_property
@@ -197,7 +198,7 @@ class HitsEndpoints(ABC):
197
198
  G
198
199
  Graph object to use
199
200
  write_property
200
- Prefix for the names of the node properties (auth and hub) to store the results in.
201
+ Postfix for the names of the node properties (auth and hub) to store the results in.
201
202
  hits_iterations
202
203
  Number of iterations to run HITS for.
203
204
  auth_property
@@ -229,6 +230,41 @@ class HitsEndpoints(ABC):
229
230
  Algorithm metrics and statistics
230
231
  """
231
232
 
233
+ @abstractmethod
234
+ def estimate(
235
+ self,
236
+ G: Graph | dict[str, Any],
237
+ *,
238
+ hits_iterations: int = 20,
239
+ partitioning: str = "AUTO",
240
+ relationship_types: list[str] = ALL_TYPES,
241
+ node_labels: list[str] = ALL_LABELS,
242
+ concurrency: int | None = None,
243
+ ) -> EstimationResult:
244
+ """
245
+ Estimate the memory consumption of an algorithm run.
246
+
247
+ Parameters
248
+ ----------
249
+ G
250
+ Graph object to use or a dictionary representing the graph dimensions.
251
+ hits_iterations
252
+ Number of iterations to run HITS for.
253
+ partitioning
254
+ The partitioning scheme used to divide the work between threads.
255
+ relationship_types
256
+ Filter the graph using the given relationship types. Relationships with any of the given types will be included.
257
+ node_labels
258
+ Filter the graph using the given node labels. Nodes with any of the given labels will be included.
259
+ concurrency
260
+ Number of concurrent threads to use.
261
+
262
+ Returns
263
+ -------
264
+ EstimationResult
265
+ An object containing the result of the estimation including memory requirements
266
+ """
267
+
232
268
 
233
269
  class HitsMutateResult(BaseResult):
234
270
  ran_iterations: int
@@ -0,0 +1,3 @@
1
+ TASK_NAME_DESCRIPTION = "Discriminator identifying which task the backend should run; not settable by the client."
2
+ RANDOM_SEED_DESCRIPTION = "Seed for random number generation to ensure reproducible results."
3
+ GRAPH_NAME_DESCRIPTION = "Name of the projected graph to run the procedure on."
@@ -0,0 +1,57 @@
1
+ from typing import Annotated, Literal
2
+
3
+ from annotated_types import Len
4
+ from pydantic import BaseModel, Field, PositiveInt, model_validator
5
+
6
+ NodeType = str
7
+
8
+ Dropout = Annotated[float, Field(ge=0.0, lt=1.0)]
9
+
10
+
11
+ class GraphSAGEConfig(BaseModel):
12
+ graph_encoder_type: Literal["graphsage"] = "graphsage"
13
+ target_type: NodeType
14
+ hidden_dims: Annotated[list[PositiveInt], Len(max_length=3)] | None = None
15
+ num_neighbors: Annotated[list[PositiveInt], Len(min_length=1, max_length=4)] | None = None
16
+ out_dim: PositiveInt | None = None
17
+ dropout: Dropout | None = None
18
+
19
+ @model_validator(mode="after")
20
+ def depth_validator(self) -> "GraphSAGEConfig":
21
+ if self.hidden_dims is not None:
22
+ if self.num_neighbors is not None:
23
+ if len(self.hidden_dims) + 1 != len(self.num_neighbors):
24
+ raise ValueError(
25
+ "The depth of the GNN is inferred from the hidden dimensions per layer (+1) and the number of neighbors per layer. These do not align."
26
+ )
27
+ return self
28
+
29
+
30
+ class FastRPConfig(BaseModel):
31
+ graph_encoder_type: Literal["fast_rp"] = "fast_rp"
32
+ out_dim: PositiveInt | None = None
33
+ coefficients: list[float] | None = None
34
+ normalization_strength: float | None = None
35
+
36
+
37
+ class IdentityConfig(BaseModel):
38
+ graph_encoder_type: Literal["identity"] = "identity"
39
+ target_type: NodeType
40
+ out_dim: PositiveInt
41
+
42
+
43
+ NoTrainGraphEncoderConfig = FastRPConfig | IdentityConfig # can be run without training
44
+ GraphEncoderConfig = FastRPConfig | GraphSAGEConfig | IdentityConfig
45
+
46
+
47
+ class GBClassifierConfig(BaseModel):
48
+ decoder_type: Literal["gb_classifier"] = "gb_classifier"
49
+
50
+
51
+ class MLPClassifierConfig(BaseModel):
52
+ decoder_type: Literal["mlp_classifier"] = "mlp_classifier"
53
+ hidden_dims: list[PositiveInt] | None = None
54
+ dropout: Dropout | None = None
55
+
56
+
57
+ DecoderConfig = GBClassifierConfig | MLPClassifierConfig
@@ -0,0 +1,29 @@
1
+ from __future__ import annotations
2
+
3
+ from abc import ABC, abstractmethod
4
+
5
+ from graphdatascience.procedure_surface.api.node_embedding.encode_endpoints import EncodeEndpoints
6
+ from graphdatascience.procedure_surface.api.node_embedding.predict_endpoints import PredictEndpoints
7
+ from graphdatascience.procedure_surface.api.node_embedding.train_endpoints import TrainEndpoints
8
+
9
+ __all__ = ["EmbeddingsEndpoints"]
10
+
11
+
12
+ class EmbeddingsEndpoints(ABC):
13
+ @property
14
+ @abstractmethod
15
+ def train(self) -> TrainEndpoints:
16
+ """Access embedding training procedures."""
17
+ pass
18
+
19
+ @property
20
+ @abstractmethod
21
+ def predict(self) -> PredictEndpoints:
22
+ """Access embedding prediction procedures."""
23
+ pass
24
+
25
+ @property
26
+ @abstractmethod
27
+ def encode(self) -> EncodeEndpoints:
28
+ """Access embedding encoding procedures."""
29
+ pass