Skip to content

Commit

Permalink
feat: add Operator.id property (#1918)
Browse files Browse the repository at this point in the history
Added property `id` in class `Operator`
  • Loading branch information
Matteo-Baussart-ANSYS authored Dec 12, 2024
1 parent 60140b1 commit af30b32
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
25 changes: 25 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,30 @@ def config(self, value):
"""
self._api.operator_set_config(self, value)

@property
@version_requires("10.0")
def id(self) -> int:
"""Retrieve the unique identifier of the operator.
This property returns the unique ID associated with the operator.
This property is lazily initialized.
Returns
-------
int
The unique identifier of the operator.
Notes
-----
Property available with server's version starting at 10.0.
"""
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 @@ -1483,3 +1483,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 af30b32

Please sign in to comment.