Skip to content

Commit

Permalink
feat: add Operator.id property
Browse files Browse the repository at this point in the history
feat: add test for Operator.id
  • Loading branch information
Matteo-Baussart-ANSYS committed Dec 11, 2024
1 parent d2063fe commit f5333cd
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/ansys/dpf/core/dpf_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ def __init__(self, name=None, config=None, server=None, operator=None):
self._internal_obj = None
self._description = None
self._inputs = None
self._id = None

# step 1: get server
self._server = server_module.get_or_create_server(
Expand Down Expand Up @@ -661,6 +662,16 @@ def config(self, value):
"""
self._api.operator_set_config(self, value)

@property
@version_requires("10.0")
def id(self):
if self._id is None:
operator_id_op = Operator("operator_id", server=self._server)
operator_id_op.connect_operator_as_input(0, self)
self._id = operator_id_op.outputs.id()

return self._id

@property
def inputs(self):
"""Inputs connected to the operator.
Expand Down
13 changes: 13 additions & 0 deletions tests/test_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -1482,3 +1482,16 @@ class TestContainer2(CustomContainerBase):

record_derived_class(class_name, TestContainer2, overwrite=True)
assert derived_classes[class_name] is TestContainer2


@conftest.raises_for_servers_version_under("10.0")
def test_operator_id(server_type):
ids = set()

for _ in range(10):
op = ops.utility.forward(server=server_type)

assert op.id >= 0
assert op.id not in ids

ids.add(op.id)

0 comments on commit f5333cd

Please sign in to comment.