-
Notifications
You must be signed in to change notification settings - Fork 54
Use new estimate endpoint (take 2) #1025
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,15 +29,29 @@ def estimate( | |
| self, | ||
| node_count: int, | ||
| relationship_count: int, | ||
| algorithm_categories: list[AlgorithmCategory] | None = None, | ||
| algorithm_categories: list[AlgorithmCategory] | list[str] | None = None, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you have to include
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes its for the typing
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the new part here is allowing also for the raw strings |
||
| node_label_count: int = 0, | ||
| node_property_count: int = 0, | ||
| relationship_property_count: int = 0, | ||
| ) -> SessionMemory: | ||
| if algorithm_categories is None: | ||
| algorithm_categories = [] | ||
| estimation = self._aura_api.estimate_size(node_count, relationship_count, algorithm_categories) | ||
| else: | ||
| algorithm_categories = [ | ||
| AlgorithmCategory(cat) if isinstance(cat, str) else cat for cat in algorithm_categories | ||
| ] | ||
| estimation = self._aura_api.estimate_size( | ||
| node_count=node_count, | ||
| node_label_count=node_label_count, | ||
| node_property_count=node_property_count, | ||
| relationship_count=relationship_count, | ||
| relationship_property_count=relationship_property_count, | ||
| algorithm_categories=algorithm_categories, | ||
| ) | ||
|
|
||
| if estimation.did_exceed_maximum: | ||
| if estimation.exceeds_recommended(): | ||
| warnings.warn( | ||
| f"The estimated memory `{estimation.min_required_memory}` exceeds the maximum size" | ||
| f"The estimated memory `{estimation.estimated_memory}` exceeds the maximum size" | ||
| f" supported by your Aura project (`{estimation.recommended_size}`).", | ||
| ResourceWarning, | ||
| ) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -55,8 +55,10 @@ def __init__(self, api_credentials: AuraAPICredentials) -> None: | |
| """ | ||
| Initializes a new instance of the GdsSessions class. | ||
|
|
||
| Args: | ||
| api_credentials (AuraAPICredentials): The Aura API credentials used for establishing a connection. | ||
| Parameters | ||
| ---------- | ||
| api_credentials | ||
| The Aura API credentials used for establishing a connection. | ||
|
Comment on lines
+58
to
+61
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice |
||
| """ | ||
| aura_env = os.environ.get("AURA_ENV") | ||
| aura_api = AuraApi( | ||
|
|
@@ -71,22 +73,45 @@ def estimate( | |
| self, | ||
| node_count: int, | ||
| relationship_count: int, | ||
| algorithm_categories: list[AlgorithmCategory] | None = None, | ||
| algorithm_categories: list[AlgorithmCategory] | list[str] | None = None, | ||
| node_label_count: int = 0, | ||
| node_property_count: int = 0, | ||
| relationship_property_count: int = 0, | ||
|
Comment on lines
+76
to
+79
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. non-breaking, nice |
||
| ) -> SessionMemory: | ||
| """ | ||
| Estimates the memory required for a session with the given node and relationship counts. | ||
|
|
||
| Args: | ||
| node_count (int): The number of nodes. | ||
| relationship_count (int): The number of relationships. | ||
| algorithm_categories (list[AlgorithmCategory] | None): The algorithm categories to consider. | ||
|
|
||
| Returns: | ||
| SessionMemory: The estimated memory required for the session. | ||
| Parameters | ||
| ---------- | ||
| node_count | ||
| Number of nodes. | ||
| relationship_count | ||
| Number of relationships. | ||
| algorithm_categories | ||
| The algorithm categories to consider. | ||
| node_label_count | ||
| Number of node labels. | ||
| node_property_count | ||
| Number of node properties. | ||
| relationship_property_count | ||
| Number of relationship properties. | ||
|
|
||
|
|
||
| Returns | ||
| ------- | ||
| SessionMemory | ||
| The estimated memory required for the session. | ||
| """ | ||
| if algorithm_categories is None: | ||
| algorithm_categories = [] | ||
| return self._impl.estimate(node_count, relationship_count, algorithm_categories) | ||
| return self._impl.estimate( | ||
| node_count=node_count, | ||
| relationship_count=relationship_count, | ||
| algorithm_categories=algorithm_categories, | ||
| node_label_count=node_label_count, | ||
| node_property_count=node_property_count, | ||
| relationship_property_count=relationship_property_count, | ||
| ) | ||
|
|
||
| def available_cloud_locations(self) -> list[CloudLocation]: | ||
| """ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1099,12 +1099,14 @@ def test_wait_for_instance_deleting(requests_mock: Mocker) -> None: | |
| def test_estimate_size(requests_mock: Mocker) -> None: | ||
| mock_auth_token(requests_mock) | ||
| requests_mock.post( | ||
| "https://api.neo4j.io/v1/instances/sizing", | ||
| json={"data": {"did_exceed_maximum": True, "min_required_memory": "307GB", "recommended_size": "96GB"}}, | ||
| "https://api.neo4j.io/v1/graph-analytics/sessions/sizing", | ||
| json={"data": {"estimated_memory": "3070GB", "recommended_size": "512GB"}}, | ||
| ) | ||
|
|
||
| api = AuraApi("", "", project_id="some-tenant") | ||
| assert api.estimate_size(100, 10, [AlgorithmCategory.NODE_EMBEDDING]) == EstimationDetails("307GB", "96GB", True) | ||
| assert api.estimate_size(100, 1, 1, 10, 1, [AlgorithmCategory.NODE_EMBEDDING]) == EstimationDetails( | ||
| estimated_memory="3070GB", recommended_size="512GB" | ||
| ) | ||
|
|
||
|
|
||
| def test_extract_id() -> None: | ||
|
|
@@ -1215,3 +1217,20 @@ def test_parse_session_info_without_optionals() -> None: | |
| project_id="tenant-1", | ||
| user_id="user-1", | ||
| ) | ||
|
|
||
|
|
||
| def test_estimate_size_parsing() -> None: | ||
| assert EstimationDetails._parse_size("8GB") == 8589934592 | ||
| assert EstimationDetails._parse_size("8G") == 8589934592 | ||
| assert EstimationDetails._parse_size("512MB") == 536870912 | ||
| assert EstimationDetails._parse_size("256KB") == 262144 | ||
| assert EstimationDetails._parse_size("1024B") == 1024 | ||
| assert EstimationDetails._parse_size("12345") == 12345 | ||
|
Comment on lines
+1223
to
+1228
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. great tests, but I am missing one case with an |
||
|
|
||
|
|
||
| def test_estimate_exceeds_maximum() -> None: | ||
| estimation = EstimationDetails(estimated_memory="16Gi", recommended_size="8Gi") | ||
| assert estimation.exceeds_recommended() is True | ||
|
|
||
| estimation = EstimationDetails(estimated_memory="8Gi", recommended_size="16Gi") | ||
| assert estimation.exceeds_recommended() is False | ||
Uh oh!
There was an error while loading. Please reload this page.