Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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 @@
"""
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()

Check warning on line 685 in src/ansys/dpf/core/dpf_operator.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/dpf/core/dpf_operator.py#L682-L685

Added lines #L682 - L685 were not covered by tests

return self._id

Check warning on line 687 in src/ansys/dpf/core/dpf_operator.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/dpf/core/dpf_operator.py#L687

Added line #L687 was not covered by tests

@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)
Loading