graphdatascience 2.1__py3-none-any.whl → 2.3__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.
- graphdatascience/arrow_client/authenticated_flight_client.py +2 -2
- graphdatascience/arrow_client/v1/gds_arrow_client.py +3 -3
- graphdatascience/arrow_client/v2/api_types.py +21 -0
- graphdatascience/arrow_client/v2/gds_arrow_client.py +2 -2
- graphdatascience/arrow_client/v2/job_client.py +67 -15
- graphdatascience/datasets/ogb_loader.py +7 -13
- graphdatascience/embedding/__init__.py +7 -0
- graphdatascience/{procedure_surface/api/node_embedding → embedding}/config.py +2 -24
- graphdatascience/error/feature_not_enabled.py +24 -0
- graphdatascience/graph/graph_api.py +2 -2
- graphdatascience/graph_construction/cypher_graph_constructor.py +1 -1
- graphdatascience/graph_data_science.py +2 -2
- graphdatascience/procedure_surface/api/catalog/relationships_endpoints.py +2 -2
- graphdatascience/procedure_surface/api/centrality/hits_endpoints.py +2 -2
- graphdatascience/procedure_surface/api/node_embedding/__init__.py +0 -14
- graphdatascience/procedure_surface/api/node_embedding/embedding_endpoints.py +30 -29
- graphdatascience/procedure_surface/api/node_embedding/fastpath_endpoints.py +18 -3
- graphdatascience/procedure_surface/api/node_embedding/graphsage_endpoints.py +0 -48
- graphdatascience/procedure_surface/api/pipeline/node_regression_metric.py +2 -2
- graphdatascience/procedure_surface/api/projection_job_handle.py +13 -1
- graphdatascience/procedure_surface/api/topological_link_prediction_endpoints.py +2 -2
- graphdatascience/procedure_surface/arrow/catalog/catalog_arrow_endpoints.py +35 -5
- graphdatascience/procedure_surface/arrow/catalog/graph_backend_arrow.py +8 -2
- graphdatascience/procedure_surface/arrow/catalog/graph_ops_arrow.py +13 -2
- graphdatascience/procedure_surface/arrow/catalog/graph_sampling_arrow_endpoints.py +13 -2
- graphdatascience/procedure_surface/arrow/catalog/projection_arrow_endpoints.py +22 -3
- graphdatascience/procedure_surface/arrow/node_embedding/embedding_arrow_endpoints.py +22 -18
- graphdatascience/procedure_surface/arrow/node_embedding/fastpath_arrow_endpoints.py +18 -32
- graphdatascience/procedure_surface/arrow/node_embedding/graphsage_session_endpoints.py +93 -0
- graphdatascience/procedure_surface/arrow/node_embedding/graphsage_supervised_arrow_endpoints.py +36 -0
- graphdatascience/procedure_surface/arrow/node_embedding/graphsage_unsupervised_arrow_endpoints.py +35 -0
- graphdatascience/procedure_surface/arrow/stream_result_mapper.py +44 -51
- graphdatascience/procedure_surface/cypher/catalog/projection_cypher_endpoints.py +5 -4
- graphdatascience/procedure_surface/utils/node_matching.py +11 -7
- graphdatascience/procedure_surface/utils/result_utils.py +1 -1
- graphdatascience/progress/progress_bar.py +44 -17
- graphdatascience/progress/query_progress_provider.py +13 -6
- graphdatascience/query_runner/neo4j_query_runner.py +17 -5
- graphdatascience/query_runner/query_mode.py +2 -2
- graphdatascience/query_runner/query_runner.py +3 -3
- graphdatascience/resources/imdb/serialize_imdb.py +6 -6
- graphdatascience/resources/lastfm/serialize_lastfm.py +5 -5
- graphdatascience/session/aura_api.py +5 -0
- graphdatascience/session/aura_api_responses.py +30 -15
- graphdatascience/session/aura_graph_data_science.py +14 -4
- graphdatascience/session/dbms/instance_type_resolver.py +39 -0
- graphdatascience/session/dbms_connection_info.py +1 -1
- graphdatascience/session/gds_sessions.py +51 -54
- graphdatascience/session/graph_mapping_context.py +54 -0
- graphdatascience/session/graph_mappings_api.py +81 -0
- graphdatascience/session/instance_type.py +39 -0
- graphdatascience/session/remote_ops/project_protocols.py +63 -20
- graphdatascience/session/session_target.py +145 -0
- graphdatascience/version.py +1 -1
- {graphdatascience-2.1.dist-info → graphdatascience-2.3.dist-info}/METADATA +4 -5
- {graphdatascience-2.1.dist-info → graphdatascience-2.3.dist-info}/RECORD +59 -51
- {graphdatascience-2.1.dist-info → graphdatascience-2.3.dist-info}/WHEEL +1 -1
- {graphdatascience-2.1.dist-info → graphdatascience-2.3.dist-info}/licenses/LICENSE +0 -0
- {graphdatascience-2.1.dist-info → graphdatascience-2.3.dist-info}/top_level.txt +0 -0
|
@@ -7,7 +7,7 @@ import platform
|
|
|
7
7
|
import socket
|
|
8
8
|
from dataclasses import dataclass
|
|
9
9
|
from types import TracebackType
|
|
10
|
-
from typing import Any, Callable, Iterator, Type, TypeVar
|
|
10
|
+
from typing import Any, Callable, Iterator, Self, Type, TypeVar
|
|
11
11
|
|
|
12
12
|
import certifi
|
|
13
13
|
from pyarrow import Schema, flight
|
|
@@ -274,7 +274,7 @@ class AuthenticatedArrowClient:
|
|
|
274
274
|
except OSError:
|
|
275
275
|
return False
|
|
276
276
|
|
|
277
|
-
def __enter__(self) ->
|
|
277
|
+
def __enter__(self) -> Self:
|
|
278
278
|
return self
|
|
279
279
|
|
|
280
280
|
def __exit__(
|
|
@@ -3,7 +3,7 @@ from __future__ import annotations
|
|
|
3
3
|
import json
|
|
4
4
|
import logging
|
|
5
5
|
from types import TracebackType
|
|
6
|
-
from typing import Any, Iterable, Type
|
|
6
|
+
from typing import Any, Iterable, Self, Type
|
|
7
7
|
|
|
8
8
|
import pandas
|
|
9
9
|
import pyarrow
|
|
@@ -83,7 +83,7 @@ class GdsArrowClient:
|
|
|
83
83
|
|
|
84
84
|
result = self._get_data(graph_name, database, proc, concurrency, config)
|
|
85
85
|
if list_node_labels:
|
|
86
|
-
result.rename(columns={"labels": "nodeLabels"}
|
|
86
|
+
result = result.rename(columns={"labels": "nodeLabels"})
|
|
87
87
|
|
|
88
88
|
return result
|
|
89
89
|
|
|
@@ -567,7 +567,7 @@ class GdsArrowClient:
|
|
|
567
567
|
arrow_table = self._sanitize_arrow_table(arrow_table)
|
|
568
568
|
return arrow_table.to_pandas(types_mapper=pandas.ArrowDtype) # type: ignore
|
|
569
569
|
|
|
570
|
-
def __enter__(self) ->
|
|
570
|
+
def __enter__(self) -> Self:
|
|
571
571
|
return self
|
|
572
572
|
|
|
573
573
|
def __exit__(
|
|
@@ -8,6 +8,26 @@ class JobIdConfig(ArrowBaseModel):
|
|
|
8
8
|
UNKNOWN_PROGRESS = -1
|
|
9
9
|
|
|
10
10
|
|
|
11
|
+
class StepProgress(ArrowBaseModel):
|
|
12
|
+
"""Progress of a single step within a multi-step job.
|
|
13
|
+
|
|
14
|
+
``progress`` is ``None`` for qualitative steps (e.g. "Fetching graph") and a fraction
|
|
15
|
+
in ``[0, 1]`` for quantitative steps (e.g. "Training epoch 3").
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
current: int
|
|
19
|
+
total: int
|
|
20
|
+
progress: float | None = None
|
|
21
|
+
|
|
22
|
+
def progress_percent(self) -> float | None:
|
|
23
|
+
if self.progress is None:
|
|
24
|
+
return None
|
|
25
|
+
return self.progress * 100
|
|
26
|
+
|
|
27
|
+
def label(self) -> str:
|
|
28
|
+
return f"{self.current}/{self.total}"
|
|
29
|
+
|
|
30
|
+
|
|
11
31
|
class JobStatus(ArrowBaseModel):
|
|
12
32
|
"""Status and progress information for a GDS Arrow job."""
|
|
13
33
|
|
|
@@ -15,6 +35,7 @@ class JobStatus(ArrowBaseModel):
|
|
|
15
35
|
status: str
|
|
16
36
|
progress: float
|
|
17
37
|
description: str
|
|
38
|
+
step_progress: StepProgress | None = None
|
|
18
39
|
|
|
19
40
|
def progress_known(self) -> bool:
|
|
20
41
|
if self.progress == UNKNOWN_PROGRESS:
|
|
@@ -3,7 +3,7 @@ from __future__ import annotations
|
|
|
3
3
|
import json
|
|
4
4
|
import logging
|
|
5
5
|
from types import TracebackType
|
|
6
|
-
from typing import Any, Type
|
|
6
|
+
from typing import Any, Self, Type
|
|
7
7
|
|
|
8
8
|
import pandas
|
|
9
9
|
import pyarrow
|
|
@@ -547,7 +547,7 @@ class GdsArrowClient:
|
|
|
547
547
|
ack_stream.read()
|
|
548
548
|
progress_callback(partition.num_rows)
|
|
549
549
|
|
|
550
|
-
def __enter__(self) ->
|
|
550
|
+
def __enter__(self) -> Self:
|
|
551
551
|
return self
|
|
552
552
|
|
|
553
553
|
def __exit__(
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import json
|
|
2
2
|
import logging
|
|
3
3
|
import uuid
|
|
4
|
+
from dataclasses import dataclass
|
|
4
5
|
from typing import Any
|
|
5
6
|
|
|
6
7
|
from pandas import ArrowDtype, DataFrame
|
|
@@ -23,6 +24,67 @@ JOBS_CANCEL_ENDPOINT = "v2/jobs.cancel"
|
|
|
23
24
|
RESULTS_SUMMARY_ENDPOINT = "v2/results.summary"
|
|
24
25
|
|
|
25
26
|
|
|
27
|
+
@dataclass(frozen=True)
|
|
28
|
+
class BarSignature:
|
|
29
|
+
"""Identifies the bar currently shown; a change means the bar must be replaced."""
|
|
30
|
+
|
|
31
|
+
step: int
|
|
32
|
+
quantitative: bool
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class JobProgressBar:
|
|
36
|
+
"""The single progress bar shown while waiting for one job.
|
|
37
|
+
|
|
38
|
+
Renders one status per poll and replaces the bar whenever the reported step (or its
|
|
39
|
+
qualitative <-> quantitative mode) changes.
|
|
40
|
+
"""
|
|
41
|
+
|
|
42
|
+
def __init__(self, bar_options: dict[str, Any]) -> None:
|
|
43
|
+
self._bar_options = bar_options
|
|
44
|
+
self._bar: TqdmProgressBar | None = None
|
|
45
|
+
self._signature: BarSignature | None = None
|
|
46
|
+
|
|
47
|
+
def render(self, job_status: JobStatus) -> None:
|
|
48
|
+
base_task = job_status.base_task()
|
|
49
|
+
sub_tasks = job_status.sub_tasks()
|
|
50
|
+
step = job_status.step_progress
|
|
51
|
+
|
|
52
|
+
if step is None:
|
|
53
|
+
if self._bar is None:
|
|
54
|
+
self._bar = TqdmProgressBar(
|
|
55
|
+
task_name=base_task,
|
|
56
|
+
relative_progress=job_status.progress_percent(),
|
|
57
|
+
bar_options=self._bar_options,
|
|
58
|
+
)
|
|
59
|
+
self._bar.update(job_status.status, job_status.progress_percent(), sub_tasks)
|
|
60
|
+
else:
|
|
61
|
+
percent = step.progress_percent()
|
|
62
|
+
signature = BarSignature(step=step.current, quantitative=percent is not None)
|
|
63
|
+
if self._bar is None or signature != self._signature:
|
|
64
|
+
# A new step (or a qualitative <-> quantitative switch) replaces the bar.
|
|
65
|
+
if self._bar is not None:
|
|
66
|
+
self._bar.close()
|
|
67
|
+
self._bar = TqdmProgressBar(
|
|
68
|
+
task_name=base_task,
|
|
69
|
+
relative_progress=percent,
|
|
70
|
+
bar_options=self._bar_options,
|
|
71
|
+
)
|
|
72
|
+
self._signature = signature
|
|
73
|
+
self._bar.update(job_status.status, percent, sub_tasks, step=step.label())
|
|
74
|
+
|
|
75
|
+
def finish(self, job_status: JobStatus) -> None:
|
|
76
|
+
if self._bar is None:
|
|
77
|
+
return
|
|
78
|
+
if job_status.base_task():
|
|
79
|
+
self.render(job_status)
|
|
80
|
+
step = job_status.step_progress
|
|
81
|
+
self._bar.finish(
|
|
82
|
+
success=job_status.succeeded(),
|
|
83
|
+
step=None if step is None else step.label(),
|
|
84
|
+
sub_tasks_description=job_status.sub_tasks(),
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
|
|
26
88
|
class JobClient:
|
|
27
89
|
def __init__(self, progress_bar_options: dict[str, Any] | None = None):
|
|
28
90
|
self._progress_bar_options = progress_bar_options or {}
|
|
@@ -70,10 +132,10 @@ class JobClient:
|
|
|
70
132
|
expected_status: str | None = None,
|
|
71
133
|
termination_flag: TerminationFlag | None = None,
|
|
72
134
|
) -> None:
|
|
73
|
-
|
|
135
|
+
progress = JobProgressBar(self._progress_bar_options)
|
|
74
136
|
|
|
75
137
|
def check_expected_status(status: JobStatus) -> bool:
|
|
76
|
-
return
|
|
138
|
+
return status.succeeded() if expected_status is None else status.status == expected_status
|
|
77
139
|
|
|
78
140
|
if termination_flag is None:
|
|
79
141
|
termination_flag = TerminationFlag.create()
|
|
@@ -84,21 +146,11 @@ class JobClient:
|
|
|
84
146
|
job_status = self.get_job_status(client, job_id)
|
|
85
147
|
|
|
86
148
|
if check_expected_status(job_status) or job_status.aborted():
|
|
87
|
-
|
|
88
|
-
progress_bar.finish(success=job_status.succeeded())
|
|
149
|
+
progress.finish(job_status)
|
|
89
150
|
return
|
|
90
151
|
|
|
91
|
-
if show_progress:
|
|
92
|
-
|
|
93
|
-
base_task = job_status.base_task()
|
|
94
|
-
if base_task:
|
|
95
|
-
progress_bar = TqdmProgressBar(
|
|
96
|
-
task_name=base_task,
|
|
97
|
-
relative_progress=job_status.progress_percent(),
|
|
98
|
-
bar_options=self._progress_bar_options,
|
|
99
|
-
)
|
|
100
|
-
if progress_bar:
|
|
101
|
-
progress_bar.update(job_status.status, job_status.progress_percent(), job_status.sub_tasks())
|
|
152
|
+
if show_progress and job_status.base_task():
|
|
153
|
+
progress.render(job_status)
|
|
102
154
|
|
|
103
155
|
@staticmethod
|
|
104
156
|
def cancel_job(client: AuthenticatedArrowClient, job_id: str) -> None:
|
|
@@ -2,7 +2,7 @@ from __future__ import annotations
|
|
|
2
2
|
|
|
3
3
|
import logging
|
|
4
4
|
from abc import ABC, abstractmethod
|
|
5
|
-
from typing import Any, Protocol, TypedDict
|
|
5
|
+
from typing import Any, NotRequired, Protocol, TypedDict
|
|
6
6
|
from warnings import warn
|
|
7
7
|
|
|
8
8
|
import numpy as np
|
|
@@ -13,24 +13,18 @@ from graphdatascience.datasets.graph_constructor_func import GraphConstructorFun
|
|
|
13
13
|
from graphdatascience.graph import Graph
|
|
14
14
|
|
|
15
15
|
|
|
16
|
-
class
|
|
16
|
+
class HomogeneousOGBGraph(TypedDict):
|
|
17
17
|
edge_index: npt.NDArray[np.int64]
|
|
18
18
|
num_nodes: int
|
|
19
|
+
edge_feat: NotRequired[npt.NDArray[np.float64] | None]
|
|
20
|
+
node_feat: NotRequired[npt.NDArray[np.float64] | None]
|
|
19
21
|
|
|
20
22
|
|
|
21
|
-
class
|
|
22
|
-
edge_feat: npt.NDArray[np.float64] | None
|
|
23
|
-
node_feat: npt.NDArray[np.float64] | None
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
class _HeterogeneousOGBGraphBase(TypedDict):
|
|
23
|
+
class HeterogeneousOGBGraph(TypedDict):
|
|
27
24
|
edge_index_dict: dict[tuple[str, str, str], npt.NDArray[np.int64]]
|
|
28
25
|
num_nodes_dict: dict[str, int]
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
class HeterogeneousOGBGraph(_HeterogeneousOGBGraphBase, total=False):
|
|
32
|
-
edge_feat_dict: dict[tuple[str, str, str], npt.NDArray[np.float64]]
|
|
33
|
-
node_feat_dict: dict[str, npt.NDArray[np.float64]]
|
|
26
|
+
edge_feat_dict: NotRequired[dict[tuple[str, str, str], npt.NDArray[np.float64]]]
|
|
27
|
+
node_feat_dict: NotRequired[dict[str, npt.NDArray[np.float64]]]
|
|
34
28
|
|
|
35
29
|
|
|
36
30
|
class HomogeneousOGBNDataset(Protocol):
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
from typing import Annotated, Literal
|
|
1
|
+
from typing import Annotated, Literal, Self
|
|
2
2
|
|
|
3
3
|
from annotated_types import Len
|
|
4
4
|
from pydantic import BaseModel, Field, PositiveInt, model_validator
|
|
@@ -12,7 +12,6 @@ class GraphSAGEConfig(BaseModel):
|
|
|
12
12
|
"""Configuration for the GraphSAGE graph encoder."""
|
|
13
13
|
|
|
14
14
|
graph_encoder_type: Literal["graphsage"] = "graphsage"
|
|
15
|
-
target_type: NodeType = Field(description="Node type (label) of the nodes the encoder is trained on.")
|
|
16
15
|
hidden_dims: Annotated[list[PositiveInt], Len(max_length=3)] | None = Field(
|
|
17
16
|
default=None,
|
|
18
17
|
description="Sizes of the hidden layers. The depth of the GNN is inferred as `len(hidden_dims) + 1`.",
|
|
@@ -25,7 +24,7 @@ class GraphSAGEConfig(BaseModel):
|
|
|
25
24
|
dropout: Dropout | None = Field(default=None, description="Dropout probability applied during training.")
|
|
26
25
|
|
|
27
26
|
@model_validator(mode="after")
|
|
28
|
-
def depth_validator(self) ->
|
|
27
|
+
def depth_validator(self) -> Self:
|
|
29
28
|
if self.hidden_dims is not None:
|
|
30
29
|
if self.num_neighbors is not None:
|
|
31
30
|
if len(self.hidden_dims) + 1 != len(self.num_neighbors):
|
|
@@ -50,24 +49,6 @@ class FastRPConfig(BaseModel):
|
|
|
50
49
|
)
|
|
51
50
|
|
|
52
51
|
|
|
53
|
-
class IdentityConfig(BaseModel):
|
|
54
|
-
"""Configuration for the Identity encoder, which passes node properties through unchanged."""
|
|
55
|
-
|
|
56
|
-
graph_encoder_type: Literal["identity"] = "identity"
|
|
57
|
-
target_type: NodeType = Field(description="Node type (label) of the nodes to encode.")
|
|
58
|
-
out_dim: PositiveInt = Field(description="Output dimensionality of the embeddings.")
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
NoTrainGraphEncoderConfig = FastRPConfig | IdentityConfig # can be run without training
|
|
62
|
-
GraphEncoderConfig = FastRPConfig | GraphSAGEConfig | IdentityConfig
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
class GBClassifierConfig(BaseModel):
|
|
66
|
-
"""Configuration for the gradient boosted tree classifier decoder."""
|
|
67
|
-
|
|
68
|
-
decoder_type: Literal["gb_classifier"] = "gb_classifier"
|
|
69
|
-
|
|
70
|
-
|
|
71
52
|
class MLPClassifierConfig(BaseModel):
|
|
72
53
|
"""Configuration for the multi-layer perceptron classifier decoder."""
|
|
73
54
|
|
|
@@ -76,6 +57,3 @@ class MLPClassifierConfig(BaseModel):
|
|
|
76
57
|
default=None, description="Sizes of the hidden layers of the network."
|
|
77
58
|
)
|
|
78
59
|
dropout: Dropout | None = Field(default=None, description="Dropout probability applied during training.")
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
DecoderConfig = GBClassifierConfig | MLPClassifierConfig
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
from contextlib import contextmanager
|
|
2
|
+
from typing import Iterator
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class FeatureNotEnabledError(Exception):
|
|
6
|
+
"""Raised when an endpoint is invoked against a session that does not have the feature enabled."""
|
|
7
|
+
|
|
8
|
+
def __init__(self, feature: str) -> None:
|
|
9
|
+
super().__init__(
|
|
10
|
+
f"{feature} is not enabled for this session. "
|
|
11
|
+
"Please reach out to the Neo4j GDS team to have it enabled for your session."
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
@contextmanager
|
|
16
|
+
def translate_feature_not_enabled(endpoint: str, feature: str) -> Iterator[None]:
|
|
17
|
+
"""Translate the session's "unsupported action" error into a clear feature-not-enabled error."""
|
|
18
|
+
try:
|
|
19
|
+
yield
|
|
20
|
+
except Exception as e:
|
|
21
|
+
message = str(e)
|
|
22
|
+
if "Unsupported action" in message and endpoint in message:
|
|
23
|
+
raise FeatureNotEnabledError(feature) from e
|
|
24
|
+
raise
|
|
@@ -2,7 +2,7 @@ from __future__ import annotations
|
|
|
2
2
|
|
|
3
3
|
from datetime import datetime
|
|
4
4
|
from types import TracebackType
|
|
5
|
-
from typing import Any, Type
|
|
5
|
+
from typing import Any, Self, Type
|
|
6
6
|
|
|
7
7
|
from graphdatascience.graph.graph_backend import GraphBackend
|
|
8
8
|
from graphdatascience.graph.graph_info import GraphInfo
|
|
@@ -19,7 +19,7 @@ class Graph:
|
|
|
19
19
|
self._name = name
|
|
20
20
|
self._backend = backend
|
|
21
21
|
|
|
22
|
-
def __enter__(self
|
|
22
|
+
def __enter__(self) -> Self:
|
|
23
23
|
return self
|
|
24
24
|
|
|
25
25
|
def __exit__(
|
|
@@ -146,7 +146,7 @@ class CypherGraphConstructor(GraphConstructor):
|
|
|
146
146
|
# this way we don't duplicate the node property data and its cheaper
|
|
147
147
|
combined_df: DataFrame = concat(aligned_node_dfs + aligned_rel_dfs, ignore_index=True)
|
|
148
148
|
# sort the columns to ensure the order is the same (for testing)
|
|
149
|
-
combined_df.sort_index(axis="columns"
|
|
149
|
+
combined_df = combined_df.sort_index(axis="columns")
|
|
150
150
|
# using a list and not a set to preserve the order
|
|
151
151
|
combined_cols: list[str] = combined_df.columns.tolist()
|
|
152
152
|
|
|
@@ -2,7 +2,7 @@ from __future__ import annotations
|
|
|
2
2
|
|
|
3
3
|
import warnings
|
|
4
4
|
from types import TracebackType
|
|
5
|
-
from typing import Any, Literal, Type
|
|
5
|
+
from typing import Any, Literal, Self, Type
|
|
6
6
|
|
|
7
7
|
import neo4j
|
|
8
8
|
from neo4j import Driver
|
|
@@ -972,7 +972,7 @@ class GraphDataScience:
|
|
|
972
972
|
self._arrow_client.close()
|
|
973
973
|
self._query_runner.close()
|
|
974
974
|
|
|
975
|
-
def __enter__(self) ->
|
|
975
|
+
def __enter__(self) -> Self:
|
|
976
976
|
return self
|
|
977
977
|
|
|
978
978
|
def __exit__(
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
3
|
from abc import ABC, abstractmethod
|
|
4
|
-
from enum import
|
|
4
|
+
from enum import StrEnum
|
|
5
5
|
from typing import Any
|
|
6
6
|
|
|
7
7
|
from pydantic import AliasChoices, Field, field_validator
|
|
@@ -312,7 +312,7 @@ class CollapsePathResult(BaseResult):
|
|
|
312
312
|
configuration: dict[str, Any]
|
|
313
313
|
|
|
314
314
|
|
|
315
|
-
class Aggregation(
|
|
315
|
+
class Aggregation(StrEnum):
|
|
316
316
|
"""
|
|
317
317
|
Specifies how to aggregate parallel relationships in a graph.
|
|
318
318
|
"""
|
|
@@ -17,7 +17,7 @@ class HitsEndpoints(ABC):
|
|
|
17
17
|
self,
|
|
18
18
|
G: Graph,
|
|
19
19
|
*,
|
|
20
|
-
mutate_property: str
|
|
20
|
+
mutate_property: str,
|
|
21
21
|
hits_iterations: int = 20,
|
|
22
22
|
auth_property: str = "auth",
|
|
23
23
|
hub_property: str = "hub",
|
|
@@ -176,7 +176,7 @@ class HitsEndpoints(ABC):
|
|
|
176
176
|
self,
|
|
177
177
|
G: Graph,
|
|
178
178
|
*,
|
|
179
|
-
write_property: str
|
|
179
|
+
write_property: str,
|
|
180
180
|
hits_iterations: int = 20,
|
|
181
181
|
auth_property: str = "auth",
|
|
182
182
|
hub_property: str = "hub",
|
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
from graphdatascience.procedure_surface.api.node_embedding.config import (
|
|
2
|
-
FastRPConfig,
|
|
3
|
-
GBClassifierConfig,
|
|
4
|
-
GraphSAGEConfig,
|
|
5
|
-
IdentityConfig,
|
|
6
|
-
MLPClassifierConfig,
|
|
7
|
-
)
|
|
8
1
|
from graphdatascience.procedure_surface.api.node_embedding.embedding_endpoints import (
|
|
9
2
|
EmbeddingCreateResult,
|
|
10
3
|
EmbeddingEndpoints,
|
|
@@ -23,7 +16,6 @@ from graphdatascience.procedure_surface.api.node_embedding.fastrp_endpoints impo
|
|
|
23
16
|
)
|
|
24
17
|
from graphdatascience.procedure_surface.api.node_embedding.graphsage_endpoints import (
|
|
25
18
|
GraphSageEndpoints,
|
|
26
|
-
SessionGraphSageEndpoints,
|
|
27
19
|
)
|
|
28
20
|
from graphdatascience.procedure_surface.api.node_embedding.graphsage_predict_endpoints import (
|
|
29
21
|
GraphSageMutateResult,
|
|
@@ -69,7 +61,6 @@ __all__ = [
|
|
|
69
61
|
"EmbeddingEndpoints",
|
|
70
62
|
"EmbeddingCreateResult",
|
|
71
63
|
"EmbeddingTrainResult",
|
|
72
|
-
"FastRPConfig",
|
|
73
64
|
"FastRPEndpoints",
|
|
74
65
|
"FastRPMutateResult",
|
|
75
66
|
"FastRPStatsResult",
|
|
@@ -77,8 +68,6 @@ __all__ = [
|
|
|
77
68
|
"FastPathEndpoints",
|
|
78
69
|
"FastPathMutateResult",
|
|
79
70
|
"FastPathWriteResult",
|
|
80
|
-
"GBClassifierConfig",
|
|
81
|
-
"GraphSAGEConfig",
|
|
82
71
|
"GraphSageEndpoints",
|
|
83
72
|
"GraphSageMutateResult",
|
|
84
73
|
"GraphSagePredictEndpoints",
|
|
@@ -98,10 +87,7 @@ __all__ = [
|
|
|
98
87
|
"HashGNNEndpoints",
|
|
99
88
|
"HashGNNMutateResult",
|
|
100
89
|
"HashGNNWriteResult",
|
|
101
|
-
"IdentityConfig",
|
|
102
|
-
"MLPClassifierConfig",
|
|
103
90
|
"Node2VecEndpoints",
|
|
104
91
|
"Node2VecMutateResult",
|
|
105
92
|
"Node2VecWriteResult",
|
|
106
|
-
"SessionGraphSageEndpoints",
|
|
107
93
|
]
|
|
@@ -2,23 +2,14 @@ from __future__ import annotations
|
|
|
2
2
|
|
|
3
3
|
import random
|
|
4
4
|
from abc import ABC, abstractmethod
|
|
5
|
-
from typing import
|
|
5
|
+
from typing import Literal
|
|
6
6
|
|
|
7
7
|
from pydantic import BaseModel, Field, PositiveInt
|
|
8
8
|
|
|
9
|
+
from graphdatascience.embedding import FastRPConfig, GraphSAGEConfig, MLPClassifierConfig
|
|
9
10
|
from graphdatascience.graph.graph_api import Graph
|
|
10
11
|
from graphdatascience.procedure_surface.api.base_result import MutateResult, NodeResult, StatsResult
|
|
11
12
|
from graphdatascience.procedure_surface.api.descriptions import RANDOM_SEED_DESCRIPTION, TASK_NAME_DESCRIPTION
|
|
12
|
-
from graphdatascience.procedure_surface.api.node_embedding.config import (
|
|
13
|
-
DecoderConfig,
|
|
14
|
-
FastRPConfig,
|
|
15
|
-
GBClassifierConfig,
|
|
16
|
-
GraphEncoderConfig,
|
|
17
|
-
GraphSAGEConfig,
|
|
18
|
-
IdentityConfig,
|
|
19
|
-
MLPClassifierConfig,
|
|
20
|
-
NoTrainGraphEncoderConfig,
|
|
21
|
-
)
|
|
22
13
|
|
|
23
14
|
|
|
24
15
|
class EmbeddingEndpoints(ABC):
|
|
@@ -27,13 +18,14 @@ class EmbeddingEndpoints(ABC):
|
|
|
27
18
|
self,
|
|
28
19
|
G: Graph,
|
|
29
20
|
*,
|
|
30
|
-
graph_encoder: str |
|
|
21
|
+
graph_encoder: str | FastRPConfig | None = None,
|
|
22
|
+
embedding_dimension: int | None = None,
|
|
31
23
|
random_seed: int | None = None,
|
|
32
|
-
mutate_property: str,
|
|
24
|
+
mutate_property: str = "embedding",
|
|
33
25
|
job_id: str | None = None,
|
|
34
26
|
node_labels: list[str] = ["*"],
|
|
35
27
|
relationship_types: list[str] = ["*"],
|
|
36
|
-
|
|
28
|
+
input_properties: list[str] = [],
|
|
37
29
|
) -> EmbeddingCreateResult:
|
|
38
30
|
"""
|
|
39
31
|
Parameters
|
|
@@ -42,6 +34,8 @@ class EmbeddingEndpoints(ABC):
|
|
|
42
34
|
Graph object to use
|
|
43
35
|
graph_encoder
|
|
44
36
|
Encoder used to produce node embeddings: either the name of a previously trained encoder model, or an inline configuration for a non-trainable encoder (e.g. FastRP or Identity).
|
|
37
|
+
embedding_dimension
|
|
38
|
+
Dimension of the node embeddings.
|
|
45
39
|
random_seed
|
|
46
40
|
Seed for random number generation to ensure reproducible results.
|
|
47
41
|
mutate_property
|
|
@@ -52,7 +46,7 @@ class EmbeddingEndpoints(ABC):
|
|
|
52
46
|
Filter the graph using the given node labels. Nodes with any of the given labels will be included.
|
|
53
47
|
relationship_types
|
|
54
48
|
Filter the graph using the given relationship types. Relationships with any of the given types will be included.
|
|
55
|
-
|
|
49
|
+
input_properties
|
|
56
50
|
Names of the node properties to use as input features
|
|
57
51
|
|
|
58
52
|
Returns
|
|
@@ -65,19 +59,19 @@ class EmbeddingEndpoints(ABC):
|
|
|
65
59
|
self,
|
|
66
60
|
G: Graph,
|
|
67
61
|
*,
|
|
68
|
-
graph_encoder:
|
|
69
|
-
decoder:
|
|
70
|
-
|
|
62
|
+
graph_encoder: GraphSAGEConfig | None = None,
|
|
63
|
+
decoder: MLPClassifierConfig | None = None,
|
|
64
|
+
embedding_dimension: int | None = None,
|
|
65
|
+
model_name: str,
|
|
71
66
|
target_label: str,
|
|
72
67
|
target_property: str,
|
|
73
68
|
num_epochs: int | None = None,
|
|
74
69
|
batch_size: int | None = None,
|
|
75
|
-
num_trials: int = 1,
|
|
76
70
|
random_seed: int | None = None,
|
|
77
71
|
job_id: str | None = None,
|
|
78
72
|
node_labels: list[str] = ["*"],
|
|
79
73
|
relationship_types: list[str] = ["*"],
|
|
80
|
-
|
|
74
|
+
input_properties: list[str],
|
|
81
75
|
) -> EmbeddingTrainResult:
|
|
82
76
|
"""
|
|
83
77
|
embeddings.train is a preview feature and may change or be removed in future releases.
|
|
@@ -90,7 +84,9 @@ class EmbeddingEndpoints(ABC):
|
|
|
90
84
|
Configuration for the graph encoder to train (e.g. FastRP, GraphSAGE, or Identity).
|
|
91
85
|
decoder
|
|
92
86
|
Configuration for the decoder to train on top of the graph encoder's embeddings.
|
|
93
|
-
|
|
87
|
+
embedding_dimension
|
|
88
|
+
Dimension of the node embeddings.
|
|
89
|
+
model_name
|
|
94
90
|
Name to save the trained graph encoder + decoder model under.
|
|
95
91
|
target_label
|
|
96
92
|
Node label to train on.
|
|
@@ -110,7 +106,7 @@ class EmbeddingEndpoints(ABC):
|
|
|
110
106
|
Filter the graph using the given node labels. Nodes with any of the given labels will be included.
|
|
111
107
|
relationship_types
|
|
112
108
|
Filter the graph using the given relationship types. Relationships with any of the given types will be included.
|
|
113
|
-
|
|
109
|
+
input_properties
|
|
114
110
|
Names of the node properties to use as input features
|
|
115
111
|
"""
|
|
116
112
|
|
|
@@ -119,21 +115,26 @@ class EncodeConfig(BaseModel):
|
|
|
119
115
|
task_name: Literal["GML_ENCODE"] = Field(
|
|
120
116
|
"GML_ENCODE", validation_alias="taskName", description=TASK_NAME_DESCRIPTION
|
|
121
117
|
)
|
|
122
|
-
graph_encoder: str |
|
|
123
|
-
description="Encoder used to produce node embeddings: either the name of a previously trained encoder model, or an inline configuration for a non-trainable encoder
|
|
118
|
+
graph_encoder: str | FastRPConfig | None = Field(
|
|
119
|
+
description="Encoder used to produce node embeddings: either the name of a previously trained encoder model, or an inline configuration for a non-trainable encoder, i.e. FastRP."
|
|
124
120
|
)
|
|
121
|
+
embedding_dimension: int | None = Field(default=None, description="Dimension of the node embeddings.")
|
|
125
122
|
random_seed: int = Field(default_factory=lambda: random.randint(0, 2**32 - 1), description=RANDOM_SEED_DESCRIPTION)
|
|
126
123
|
|
|
127
124
|
|
|
128
125
|
class EmbeddingTrainConfig(BaseModel):
|
|
129
126
|
task_name: Literal["GML_TRAIN"] = Field("GML_TRAIN", validation_alias="taskName", description=TASK_NAME_DESCRIPTION)
|
|
130
|
-
graph_encoder:
|
|
131
|
-
description="Configuration for the graph encoder
|
|
127
|
+
graph_encoder: GraphSAGEConfig | None = Field(
|
|
128
|
+
default=None, description="Configuration for the graph encoder (GraphSAGE) to train."
|
|
132
129
|
)
|
|
133
|
-
decoder:
|
|
134
|
-
|
|
130
|
+
decoder: MLPClassifierConfig | None = Field(
|
|
131
|
+
default=None,
|
|
132
|
+
description="Configuration for the decoder (MLP) to train on top of the graph encoder's embeddings.",
|
|
133
|
+
)
|
|
134
|
+
embedding_dimension: int | None = Field(default=None, description="Dimension of the node embeddings.")
|
|
135
|
+
model_save_name: str | None = Field(
|
|
136
|
+
default=None, description="Name to save the trained graph encoder + decoder model under."
|
|
135
137
|
)
|
|
136
|
-
model_save_name: str = Field(description="Name to save the trained graph encoder + decoder model under.")
|
|
137
138
|
target_label: str = Field(description="Node label to train on.")
|
|
138
139
|
target_property: str = Field(description="Node property to train on.")
|
|
139
140
|
num_epochs: PositiveInt | None = Field(default=None, description="Maximum number of training epochs.")
|
|
@@ -32,7 +32,8 @@ class FastPathEndpoints(ABC):
|
|
|
32
32
|
mutate_property: str,
|
|
33
33
|
embedding_dimension: int,
|
|
34
34
|
lookback_horizon: int,
|
|
35
|
-
num_time_anchors: int,
|
|
35
|
+
num_time_anchors: int | None = None,
|
|
36
|
+
time_anchor_interval: float | None = None,
|
|
36
37
|
*,
|
|
37
38
|
event_node_categorical_properties: list[str] = [],
|
|
38
39
|
relationship_types: list[str] = ALL_TYPES,
|
|
@@ -69,6 +70,10 @@ class FastPathEndpoints(ABC):
|
|
|
69
70
|
Maximum age of events (relative to the observation time) that are processed.
|
|
70
71
|
num_time_anchors
|
|
71
72
|
Number of grid points used to discretize elapsed time.
|
|
73
|
+
Exactly one of `num_time_anchors` and `time_anchor_interval` must be specified.
|
|
74
|
+
time_anchor_interval
|
|
75
|
+
Time interval between anchor embeddings in the grid.
|
|
76
|
+
Exactly one of `num_time_anchors` and `time_anchor_interval` must be specified.
|
|
72
77
|
event_node_categorical_properties
|
|
73
78
|
Event node properties holding categorical values.
|
|
74
79
|
relationship_types
|
|
@@ -114,7 +119,8 @@ class FastPathEndpoints(ABC):
|
|
|
114
119
|
event_node_label: str,
|
|
115
120
|
embedding_dimension: int,
|
|
116
121
|
lookback_horizon: int,
|
|
117
|
-
num_time_anchors: int,
|
|
122
|
+
num_time_anchors: int | None = None,
|
|
123
|
+
time_anchor_interval: float | None = None,
|
|
118
124
|
*,
|
|
119
125
|
event_node_categorical_properties: list[str] = [],
|
|
120
126
|
relationship_types: list[str] = ALL_TYPES,
|
|
@@ -149,6 +155,10 @@ class FastPathEndpoints(ABC):
|
|
|
149
155
|
Maximum age of events (relative to the observation time) that are processed.
|
|
150
156
|
num_time_anchors
|
|
151
157
|
Number of grid points used to discretize elapsed time.
|
|
158
|
+
Exactly one of `num_time_anchors` and `time_anchor_interval` must be specified.
|
|
159
|
+
time_anchor_interval
|
|
160
|
+
Time interval between anchor embeddings in the grid.
|
|
161
|
+
Exactly one of `num_time_anchors` and `time_anchor_interval` must be specified.
|
|
152
162
|
event_node_categorical_properties
|
|
153
163
|
Event node properties holding categorical values.
|
|
154
164
|
relationship_types
|
|
@@ -195,7 +205,8 @@ class FastPathEndpoints(ABC):
|
|
|
195
205
|
write_property: str,
|
|
196
206
|
embedding_dimension: int,
|
|
197
207
|
lookback_horizon: int,
|
|
198
|
-
num_time_anchors: int,
|
|
208
|
+
num_time_anchors: int | None = None,
|
|
209
|
+
time_anchor_interval: float | None = None,
|
|
199
210
|
*,
|
|
200
211
|
event_node_categorical_properties: list[str] = [],
|
|
201
212
|
relationship_types: list[str] = ALL_TYPES,
|
|
@@ -233,6 +244,10 @@ class FastPathEndpoints(ABC):
|
|
|
233
244
|
Maximum age of events (relative to the observation time) that are processed.
|
|
234
245
|
num_time_anchors
|
|
235
246
|
Number of grid points used to discretize elapsed time.
|
|
247
|
+
Exactly one of `num_time_anchors` and `time_anchor_interval` must be specified.
|
|
248
|
+
time_anchor_interval
|
|
249
|
+
Time interval between anchor embeddings in the grid.
|
|
250
|
+
Exactly one of `num_time_anchors` and `time_anchor_interval` must be specified.
|
|
236
251
|
event_node_categorical_properties
|
|
237
252
|
Event node properties holding categorical values.
|
|
238
253
|
relationship_types
|