From 422f8f756338c06a3ce4af2311fbfa4751cfb49c Mon Sep 17 00:00:00 2001 From: Maid Sultanovic Date: Wed, 29 Apr 2026 10:38:45 +0200 Subject: [PATCH 1/4] deprecate: mark `download_latent_parameters_json` as deprecated --- .../simai/core/data/geomai/workspaces.py | 34 +++++++++++++++++-- tests/geomai/test_geomai_workspaces.py | 23 +++++++++++++ 2 files changed, 54 insertions(+), 3 deletions(-) diff --git a/src/ansys/simai/core/data/geomai/workspaces.py b/src/ansys/simai/core/data/geomai/workspaces.py index c8dd410e..55f1067a 100644 --- a/src/ansys/simai/core/data/geomai/workspaces.py +++ b/src/ansys/simai/core/data/geomai/workspaces.py @@ -21,6 +21,7 @@ # SOFTWARE. import json +import warnings from typing import TYPE_CHECKING, BinaryIO, List, Optional, Union from ansys.simai.core.data.base import DataModel, Directory @@ -29,10 +30,12 @@ File, Filters, Identifiable, + Path, SizedIterator, get_id_from_identifiable, to_raw_filters, ) +from ansys.simai.core.errors import PySimAIDepreciationWarning from ansys.simai.core.utils.pagination import DataModelIterator if TYPE_CHECKING: @@ -91,17 +94,42 @@ def set_as_current_workspace(self) -> None: def download_latent_parameters_json(self, file: Optional[File] = None) -> Union[None, BinaryIO]: """Download the json file containing the latent parameters for the model's training data. + Warning: + This feature is deprecated and will be retired in August 2026. Please use :py:meth:`~get_latent_parameters` instead. + Args: file: Binary file-object or the path of the file to put the content into. Returns: ``None`` if a file is specified or a binary file-object otherwise. """ + warnings.warn( + "`download_latent_parameters_json` is deprecated. Use 'get_latent_parameters' instead.", + PySimAIDepreciationWarning, + stacklevel=2, + ) + # We don't use `get_latent_parameters` here because it doesn't return a binary file-object when file is None return self._client._api.download_geomai_workspace_latent_parameters(self.id, file) - def get_latent_parameters(self) -> dict[str, List[float]]: - """Get the dictionary mapping geometry names to their latent parameter vectors for the model's training data.""" - data = self._client._api.download_geomai_workspace_latent_parameters(self.id, None) + def get_latent_parameters( + self, + file: Optional[File] = None, + ) -> dict[str, List[float]] | Union[None, BinaryIO]: + """Get mapping geometry names to their latent parameter vectors for the model's training data. + + Args: + file: Binary file-object or the path of the file to put the content into. + + Returns: + ``None`` or a binary file-object if a file is specified or a dictionary mapping geometry names to latent parameter + vectors otherwise. + """ + data = self._client._api.download_geomai_workspace_latent_parameters(self.id, file) + if file: + if isinstance(file, File) and not isinstance(file, (str, Path)): + return file + return data + if data is None: return {} latent_parameters = json.loads(data.read().decode("utf-8")) diff --git a/tests/geomai/test_geomai_workspaces.py b/tests/geomai/test_geomai_workspaces.py index 55b145ff..a6f314bb 100644 --- a/tests/geomai/test_geomai_workspaces.py +++ b/tests/geomai/test_geomai_workspaces.py @@ -21,6 +21,7 @@ # SOFTWARE. import json +from io import BytesIO from typing import TYPE_CHECKING from urllib.parse import urlencode @@ -93,6 +94,28 @@ def test_geomai_workspace_get_latent_parameters(simai_client, httpx_mock): assert latent_parameters == {"geometry1": [1, 2, 3]} +def test_geomai_workspace_get_latent_parameters_returns_binary_file_when_file_set( + simai_client, httpx_mock +): + workspace: GeomAIWorkspace = simai_client.geomai._workspace_directory._model_from( + {"id": "abc123", "name": "HL3"} + ) + + httpx_mock.add_response( + method="GET", + url=f"https://test.test/geomai/workspaces/{workspace.id}/model/latent-parameters-json", + text='{"geometry1": [1,2,3]}', + status_code=200, + ) + target_file = BytesIO() + returned_file = BytesIO(b'{"geometry1": [1,2,3]}') + + latent_parameters = workspace.get_latent_parameters(target_file) + + assert isinstance(latent_parameters, BytesIO) + assert latent_parameters.getvalue() == returned_file.getvalue() + + def test_get_workspace_model_configuration(mocker, simai_client, httpx_mock, training_data_factory): workspace: GeomAIWorkspace = simai_client.geomai._workspace_directory._model_from( {"id": "0011", "name": "riri"} From 3f453ceed7bb4f415c631aa2cf6b3a580e62e342 Mon Sep 17 00:00:00 2001 From: Maid Sultanovic <31742841+msd-11@users.noreply.github.com> Date: Tue, 26 May 2026 13:41:36 +0200 Subject: [PATCH 2/4] Update src/ansys/simai/core/data/geomai/workspaces.py Co-authored-by: Marie Lelandais <125036775+marielelandais@users.noreply.github.com> --- src/ansys/simai/core/data/geomai/workspaces.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ansys/simai/core/data/geomai/workspaces.py b/src/ansys/simai/core/data/geomai/workspaces.py index 55f1067a..ca1ca654 100644 --- a/src/ansys/simai/core/data/geomai/workspaces.py +++ b/src/ansys/simai/core/data/geomai/workspaces.py @@ -92,7 +92,7 @@ def set_as_current_workspace(self) -> None: self._client.geomai.current_workspace = self def download_latent_parameters_json(self, file: Optional[File] = None) -> Union[None, BinaryIO]: - """Download the json file containing the latent parameters for the model's training data. + """Download the JSON file containing the latent parameters for the model's training data. Warning: This feature is deprecated and will be retired in August 2026. Please use :py:meth:`~get_latent_parameters` instead. From 0c164dd2888d3241a19ce8a75c3830aa592ca44b Mon Sep 17 00:00:00 2001 From: Maid Sultanovic <31742841+msd-11@users.noreply.github.com> Date: Tue, 26 May 2026 13:41:48 +0200 Subject: [PATCH 3/4] Update src/ansys/simai/core/data/geomai/workspaces.py Co-authored-by: Marie Lelandais <125036775+marielelandais@users.noreply.github.com> --- src/ansys/simai/core/data/geomai/workspaces.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ansys/simai/core/data/geomai/workspaces.py b/src/ansys/simai/core/data/geomai/workspaces.py index ca1ca654..f2095705 100644 --- a/src/ansys/simai/core/data/geomai/workspaces.py +++ b/src/ansys/simai/core/data/geomai/workspaces.py @@ -115,7 +115,7 @@ def get_latent_parameters( self, file: Optional[File] = None, ) -> dict[str, List[float]] | Union[None, BinaryIO]: - """Get mapping geometry names to their latent parameter vectors for the model's training data. + """Get the mapping between geometry names and their latent parameter vectors for the model's training data. Args: file: Binary file-object or the path of the file to put the content into. From 7365cb2f684e856e95a3b4b4262ab42fdaee6b1c Mon Sep 17 00:00:00 2001 From: Maid Sultanovic <31742841+msd-11@users.noreply.github.com> Date: Tue, 26 May 2026 13:45:31 +0200 Subject: [PATCH 4/4] Update src/ansys/simai/core/data/geomai/workspaces.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/ansys/simai/core/data/geomai/workspaces.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ansys/simai/core/data/geomai/workspaces.py b/src/ansys/simai/core/data/geomai/workspaces.py index f2095705..aa2c4d59 100644 --- a/src/ansys/simai/core/data/geomai/workspaces.py +++ b/src/ansys/simai/core/data/geomai/workspaces.py @@ -114,7 +114,7 @@ def download_latent_parameters_json(self, file: Optional[File] = None) -> Union[ def get_latent_parameters( self, file: Optional[File] = None, - ) -> dict[str, List[float]] | Union[None, BinaryIO]: + ) -> Union[dict[str, List[float]], None, BinaryIO]: """Get the mapping between geometry names and their latent parameter vectors for the model's training data. Args: