-
Notifications
You must be signed in to change notification settings - Fork 1
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
[feat] Support post processing predict as learnt and predict on cells for surface variables #117
Open
yias
wants to merge
3
commits into
main
Choose a base branch
from
ibatian/feature/sc-26496/sdk-surface-pp-predict-as-learnt
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ | |
import numbers | ||
import sys | ||
from abc import ABC, abstractmethod | ||
from enum import Enum | ||
from inspect import cleandoc | ||
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Type, Union | ||
|
||
|
@@ -274,6 +275,40 @@ class SurfaceVTP(_PostProcessingVTKExport): | |
""" | ||
|
||
|
||
class PostProcessingOnCells(SurfaceVTP): | ||
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. I didn't follow the product story but these class name seems too generic. |
||
"""Decodes the server response for the on-cells prediction of the surface in VTP format. | ||
|
||
This class is generated through the :meth:`~PredictionPostProcessings.surface_vtp()` method. | ||
""" | ||
|
||
@classmethod | ||
def _api_name(cls): | ||
return "SurfaceVTP" | ||
|
||
|
||
class PostProcessingAsLearnt(SurfaceVTP): | ||
"""Decodes the server response for the as-learnt prediction of the surface in VTP format. | ||
|
||
This class is generated through the :meth:`~PredictionPostProcessings.surface_vtp()` method. | ||
""" | ||
|
||
@classmethod | ||
def _api_name(cls): | ||
return "SurfaceVTPTDLocation" | ||
|
||
|
||
class PPSurfaceLocation(Enum): | ||
"""Enumerates the post-processing options on the data location. | ||
|
||
Args: | ||
ON_CELLS: identifies that the post-processing should run on cell data. | ||
AS_LEARNT: identifies that the post-processing should run on the data as they are learnt. | ||
""" | ||
|
||
AS_LEARNT = PostProcessingAsLearnt | ||
ON_CELLS = PostProcessingOnCells | ||
|
||
|
||
class CustomVolumePointCloud(PostProcessing): | ||
"""Provides a representation of a CustomVolumePointCloud post-processing. | ||
|
||
|
@@ -425,7 +460,9 @@ def slice( | |
plane = convert_axis_and_coordinate_to_plane_eq_coeffs(axis, coordinate) | ||
return self._get_or_run(Slice, {"plane": plane, "output_format": format}, run) | ||
|
||
def surface_vtp(self, run: bool = True) -> Optional[SurfaceVTP]: | ||
def surface_vtp( | ||
self, run: bool = True, pp_location: PPSurfaceLocation = PPSurfaceLocation.ON_CELLS | ||
) -> Optional[SurfaceVTP]: | ||
"""Compute or get the result of the prediction's surface in VTP format. | ||
|
||
This is a non-blocking method. It returns the ``PostProcessingVTP`` | ||
|
@@ -442,24 +479,42 @@ def surface_vtp(self, run: bool = True) -> Optional[SurfaceVTP]: | |
run: Boolean indicating whether to compute or get the postprocessing. | ||
The default is ``True``. If ``False``, the postprocessing is not | ||
computed, and ``None`` is returned if it does not exist yet. | ||
pp_location: the post-processing data location. It can be one of | ||
:class:`PPSurfaceLocation`, otherwise an InvalidArgument error | ||
is raised. Default is PPSurfaceLocation.ON_CELLS. | ||
|
||
Returns: | ||
:class:`SurfaceVTP` object that allows downloading the binary data. | ||
Returns ``None`` if ``run=False`` and the postprocessing does not exist. | ||
|
||
Examples: | ||
Run and download a surface VTP. | ||
Run and download a surface VTP for data location on cells (predict on cells). | ||
|
||
.. code-block:: python | ||
|
||
import ansys.simai.core | ||
from ansys.simai.core.data.post_processings import PPSurfaceLocation | ||
|
||
simai = ansys.simai.core.from_config() | ||
prediction = simai.predictions.list()[0] | ||
surface_vtp = prediction.post.surface_vtp().data.download("/tmp/simai.vtp") | ||
surface_vtp = prediction.post.surface_vtp( | ||
pp_location=PPSurfaceLocation.ON_CELLS | ||
).data.download("/tmp/simai.vtp") | ||
|
||
Run and download a surface VTP with data location as it is learnt (predict as learnt). | ||
|
||
.. code-block:: python | ||
|
||
import ansys.simai.core | ||
from ansys.simai.core.data.post_processings import PPSurfaceLocation | ||
|
||
simai = ansys.simai.core.from_config() | ||
prediction = simai.predictions.list()[0] | ||
surface_vtp = prediction.post.surface_vtp( | ||
pp_location=PPSurfaceLocation.AS_LEARNT | ||
).data.download("/tmp/simai.vtp") | ||
|
||
Run a surface VTP and open a plot using PyVista. | ||
Run a surface VTP with data location on cells, and open a plot using PyVista. | ||
|
||
.. code-block:: python | ||
|
||
|
@@ -477,7 +532,9 @@ def surface_vtp(self, run: bool = True) -> Optional[SurfaceVTP]: | |
surface_vtp = pyvista.read(temp_vtp_file.name) | ||
surface_vtp.plot() | ||
""" | ||
return self._get_or_run(SurfaceVTP, {}, run) | ||
if not isinstance(pp_location, PPSurfaceLocation): | ||
raise InvalidArguments(f"pp_location should be one of {PPSurfaceLocation}") | ||
return self._get_or_run(pp_location.value, {}, run) | ||
|
||
def volume_vtu(self, run: bool = True) -> Optional[VolumeVTU]: | ||
"""Compute or get the result of the prediction's volume in VTU format. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might want to have inherited-members as well.