Skip to content

Commit

Permalink
options for predict-as-learnt and predicet-on-cells in selections pp
Browse files Browse the repository at this point in the history
  • Loading branch information
yias committed Dec 24, 2024
1 parent ee4c227 commit a4d433d
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/ansys/simai/core/data/post_processings.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ def surface_vtp(
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 a nvalidArgument error
:class:`PPSurfaceLocation`, otherwise an InvalidArgument error
is raised. Default is PPSurfaceLocation.ON_CELLS.
Returns:
Expand Down
35 changes: 12 additions & 23 deletions src/ansys/simai/core/data/selection_post_processings.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
from ansys.simai.core.data.lists import ExportablePPList, PPList
from ansys.simai.core.data.post_processings import (
GlobalCoefficients,
PPSurfaceLocation,
Slice,
SurfaceEvol,
SurfaceVTP,
SurfaceVTPTDLocation,
VolumeVTU,
)

Expand Down Expand Up @@ -145,7 +145,9 @@ def volume_vtu(self) -> PPList[VolumeVTU]:
"""
return PPList(selection=self._selection, post=lambda pred: pred.post.volume_vtu())

def surface_vtp(self) -> PPList[SurfaceVTP]:
def surface_vtp(
self, pp_location: PPSurfaceLocation = PPSurfaceLocation.ON_CELLS
) -> PPList[SurfaceVTP]:
"""Compute or get the result of each prediction's surface in the VTP format.
This is a non-blocking method. It returns a
Expand All @@ -160,29 +162,16 @@ def surface_vtp(self) -> PPList[SurfaceVTP]:
The computation is launched only on first call of this method.
Subsequent calls do not relaunch it.
Returns:
:py:class:`~ansys.simai.core.data.lists.PPList` instance of
:py:class:`~ansys.simai.core.data.post_processings.SurfaceVTP` objects.
"""
return PPList(selection=self._selection, post=lambda pred: pred.post.surface_vtp())

def predict_as_learnt(self) -> PPList[SurfaceVTPTDLocation]:
"""Compute or get the result of each prediction's surface in the VTP format.
This is a non-blocking method. It returns a
:py:class:`~ansys.simai.core.data.lists.PPList` instance of
:py:class:`~ansys.simai.core.data.post_processings.SurfaceVTP`
objects without waiting. Those ``PostProcessing`` objects may not have
data right away if the computation is still in progress. Data is filled
asynchronously once the computation is finished.
The state of computation can be waited upon with the ``wait()`` method.
The computation is launched only on first call of this method.
Subsequent calls do not relaunch it.
Args:
pp_location: the post-processing data location. It can be one of
:class:`~ansys.simai.core.data.post_processings.PPSurfaceLocation`,
otherwise an InvalidArgument error is raised.
Default is PPSurfaceLocation.ON_CELLS.
Returns:
:py:class:`~ansys.simai.core.data.lists.PPList` instance of
:py:class:`~ansys.simai.core.data.post_processings.SurfaceVTP` objects.
"""
return PPList(selection=self._selection, post=lambda pred: pred.post.predict_as_learnt())
return PPList(
selection=self._selection, post=lambda pred: pred.post.surface_vtp(True, pp_location)
)
29 changes: 29 additions & 0 deletions tests/test_selection_post_processings.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

from ansys.simai.core.data.post_processings import (
GlobalCoefficients,
PostProcessingAsLearnt,
PPSurfaceLocation,
Slice,
SurfaceEvol,
SurfaceVTP,
Expand Down Expand Up @@ -181,6 +183,33 @@ def test_selection_post_processing_surface_vtp(test_selection):
assert isinstance(pp, SurfaceVTP)


@responses.activate
def test_selection_post_processing_surface_vtp_predict_as_learnt(test_selection):
"""WHEN I call post.post.surface_vtp() on a selection
THEN the /SurfaceVTPTDLocation endpoint is called for each prediction in the selection
AND I get a list of PostProcessingVTUExport objects in return
"""
assert len(test_selection.points) == 2

responses.add(
responses.POST,
"https://test.test/predictions/pred1/post-processings/SurfaceVTPTDLocation",
json={"id": "vtu01", "status": "queued"},
status=200,
)
responses.add(
responses.POST,
"https://test.test/predictions/pred2/post-processings/SurfaceVTPTDLocation",
json={"id": "vtu02", "status": "queued"},
status=200,
)
post_processings = test_selection.post.surface_vtp(pp_location=PPSurfaceLocation.AS_LEARNT)
assert isinstance(post_processings, PPList)
assert len(post_processings) == 2
for pp in post_processings:
assert isinstance(pp, PostProcessingAsLearnt)


@responses.activate
def test_selection_post_processing_error(test_selection):
"""WHEN I call post.post.volume_vtu() on a selection
Expand Down

0 comments on commit a4d433d

Please sign in to comment.