Skip to content

Commit c4c0e85

Browse files
authored
Fix Any as input of operator and workflow (#1728)
* Fix Any as input of operator and workflow Signed-off-by: paul.profizi <[email protected]> * Update gate Signed-off-by: paul.profizi <[email protected]> * Fix Update gate Signed-off-by: paul.profizi <[email protected]> * Skip test_input_any for operator for DPF<7.0 Signed-off-by: paul.profizi <[email protected]> * Skip test_input_any for workflow for DPF<7.0 Signed-off-by: paul.profizi <[email protected]> * Fix code quality warning Signed-off-by: paul.profizi <[email protected]> * Revert "Fix code quality warning" This reverts commit fa5732d. * Fix code quality warning Signed-off-by: paul.profizi <[email protected]> --------- Signed-off-by: paul.profizi <[email protected]>
1 parent 5e50920 commit c4c0e85

File tree

6 files changed

+61
-2
lines changed

6 files changed

+61
-2
lines changed

src/ansys/dpf/core/dpf_operator.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,9 +470,11 @@ def _type_to_input_method(self):
470470
workflow,
471471
model,
472472
generic_data_container,
473+
any,
473474
)
474475

475476
out = [
477+
(any.Any, self._api.operator_connect_any),
476478
(bool, self._api.operator_connect_bool),
477479
((int, Enum), self._api.operator_connect_int),
478480
(str, self._connect_string),

src/ansys/dpf/core/workflow.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,11 @@ def _type_to_input_method(self):
235235
workflow,
236236
model,
237237
generic_data_container,
238+
any,
238239
)
239240

240241
out = [
242+
(any.Any, self._api.work_flow_connect_any),
241243
(bool, self._api.work_flow_connect_bool),
242244
((int, Enum), self._api.work_flow_connect_int),
243245
(str, self._connect_string),

src/ansys/dpf/gate/operator_grpcapi.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,12 @@ def operator_connect_label_space(op, pin, ptr):
206206
request.label_space.CopyFrom(ptr._internal_obj)
207207
OperatorGRPCAPI.update(op, request)
208208

209+
@staticmethod
210+
def operator_connect_any(op, pin, ptr):
211+
request = OperatorGRPCAPI.update_init(op, pin)
212+
request.as_any.CopyFrom(ptr._internal_obj)
213+
OperatorGRPCAPI.update(op, request)
214+
209215
@staticmethod
210216
def operator_connect_generic_data_container(op, pin, ptr):
211217
request = OperatorGRPCAPI.update_init(op, pin)

src/ansys/dpf/gate/workflow_grpcapi.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,12 @@ def work_flow_connect_data_tree(wf, pin_name, dataTree):
192192
request.data_tree.CopyFrom(dataTree._internal_obj)
193193
_get_stub(wf._server).UpdateConnection(request)
194194

195+
@staticmethod
196+
def work_flow_connect_any(wf, pin_name, ptr):
197+
request = WorkflowGRPCAPI._connect_init(wf, pin_name)
198+
request.as_any.CopyFrom(ptr._internal_obj)
199+
_get_stub(wf._server).UpdateConnection(request)
200+
195201
@staticmethod
196202
def work_flow_connect_generic_data_container(wf, pin_name, container):
197203
request = WorkflowGRPCAPI._connect_init(wf, pin_name)

tests/test_operator.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_4_0,
2020
SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_5_0,
2121
SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_6_2,
22+
SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_7_0,
2223
SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_8_0,
2324
)
2425

@@ -1336,12 +1337,14 @@ def test_connect_get_non_ascii_string(server_type):
13361337
assert str == str_out
13371338

13381339

1339-
@pytest.mark.skipif(not SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_8_0, reason="Available for servers >=8.0")
1340+
@pytest.mark.skipif(not SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_8_0,
1341+
reason="Available for servers >=8.0")
13401342
def test_deep_copy_non_ascii_string(server_type):
13411343
str = "\N{GREEK CAPITAL LETTER DELTA}"
13421344
str_out = dpf.core.core._deep_copy(str, server_type)
13431345
assert str == str_out
13441346

1347+
13451348
def test_output_any(server_type):
13461349
inpt = dpf.core.Field(nentities=3, server=server_type)
13471350
data = [1, 2, 3, 4, 5, 6, 7, 8, 9]
@@ -1356,4 +1359,21 @@ def test_output_any(server_type):
13561359
output_field = op.get_output(0, dpf.core.types.any).cast(dpf.core.Field)
13571360
assert isinstance(output_field, dpf.core.Field)
13581361
assert output_field.data.size == 9
1359-
assert output_field.scoping.size == 3
1362+
assert output_field.scoping.size == 3
1363+
1364+
1365+
@pytest.mark.skipif(condition=not SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_7_0,
1366+
reason="Input of Any requires DPF 7.0 or above.")
1367+
def test_input_any(server_type):
1368+
field = dpf.core.Field(nentities=3, server=server_type)
1369+
data = [1, 2, 3, 4, 5, 6, 7, 8, 9]
1370+
scop = dpf.core.Scoping(server=server_type)
1371+
scop.ids = [1, 2, 3]
1372+
field.data = data
1373+
field.scoping = scop
1374+
inpt = dpf.core.Any.new_from(field)
1375+
op = dpf.core.Operator(name="forward", server=server_type)
1376+
op.connect(pin=0, inpt=inpt)
1377+
output = op.get_output(pin=0, output_type=dpf.core.types.field)
1378+
assert isinstance(output, dpf.core.Field)
1379+
assert len(output.data_as_list) == len(data)

tests/test_workflow.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -952,6 +952,29 @@ def test_output_any(server_type):
952952
assert output_field.scoping.size == 3
953953

954954

955+
@pytest.mark.skipif(condition=not conftest.SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_7_0,
956+
reason="Input of Any requires DPF 7.0 or above.")
957+
def test_input_any(server_type):
958+
field = dpf.core.Field(nentities=3, server=server_type)
959+
data = [1, 2, 3, 4, 5, 6, 7, 8, 9]
960+
scop = dpf.core.Scoping(server=server_type)
961+
scop.ids = [1, 2, 3]
962+
field.data = data
963+
field.scoping = scop
964+
965+
inpt = dpf.core.Any.new_from(field)
966+
fwd = dpf.core.Operator(name="forward", server=server_type)
967+
968+
wf = dpf.core.Workflow(server=server_type)
969+
wf.add_operator(fwd)
970+
wf.set_input_name("in", fwd, 0)
971+
wf.set_output_name("out", fwd, 0)
972+
973+
wf.connect(pin_name="in", inpt=inpt)
974+
output = wf.get_output(pin_name="out", output_type=dpf.core.types.field)
975+
assert isinstance(output, dpf.core.Field)
976+
977+
955978
def main():
956979
test_connect_field_workflow()
957980
velocity_acceleration = conftest.resolve_test_file("velocity_acceleration.rst", "rst_operators")

0 commit comments

Comments
 (0)