Skip to content

Commit af30b32

Browse files
feat: add Operator.id property (#1918)
Added property `id` in class `Operator`
1 parent 60140b1 commit af30b32

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

src/ansys/dpf/core/dpf_operator.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ def __init__(self, name=None, config=None, server=None, operator=None):
127127
self._internal_obj = None
128128
self._description = None
129129
self._inputs = None
130+
self._id = None
130131

131132
# step 1: get server
132133
self._server = server_module.get_or_create_server(
@@ -661,6 +662,30 @@ def config(self, value):
661662
"""
662663
self._api.operator_set_config(self, value)
663664

665+
@property
666+
@version_requires("10.0")
667+
def id(self) -> int:
668+
"""Retrieve the unique identifier of the operator.
669+
670+
This property returns the unique ID associated with the operator.
671+
This property is lazily initialized.
672+
673+
Returns
674+
-------
675+
int
676+
The unique identifier of the operator.
677+
678+
Notes
679+
-----
680+
Property available with server's version starting at 10.0.
681+
"""
682+
if self._id is None:
683+
operator_id_op = Operator("operator_id", server=self._server)
684+
operator_id_op.connect_operator_as_input(0, self)
685+
self._id = operator_id_op.outputs.id()
686+
687+
return self._id
688+
664689
@property
665690
def inputs(self):
666691
"""Inputs connected to the operator.

tests/test_operator.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1483,3 +1483,16 @@ class TestContainer2(CustomContainerBase):
14831483

14841484
record_derived_class(class_name, TestContainer2, overwrite=True)
14851485
assert derived_classes[class_name] is TestContainer2
1486+
1487+
1488+
@conftest.raises_for_servers_version_under("10.0")
1489+
def test_operator_id(server_type):
1490+
ids = set()
1491+
1492+
for _ in range(10):
1493+
op = ops.utility.forward(server=server_type)
1494+
1495+
assert op.id >= 0
1496+
assert op.id not in ids
1497+
1498+
ids.add(op.id)

0 commit comments

Comments
 (0)