From 7b461f39be30c9c873ca9400a6a6d674b66a3a05 Mon Sep 17 00:00:00 2001 From: PProfizi Date: Thu, 5 Jun 2025 11:01:57 +0200 Subject: [PATCH 1/2] Fix support for list of float and list of string as operator input --- src/ansys/dpf/core/dpf_operator.py | 6 ++++-- src/ansys/dpf/core/inputs.py | 9 +++++++-- src/ansys/dpf/core/mapping_types.py | 3 ++- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/ansys/dpf/core/dpf_operator.py b/src/ansys/dpf/core/dpf_operator.py index b621db50d6..71bab8f3ce 100644 --- a/src/ansys/dpf/core/dpf_operator.py +++ b/src/ansys/dpf/core/dpf_operator.py @@ -816,7 +816,9 @@ def eval(self, pin=None): if output._pin == pin: return output() - def _find_outputs_corresponding_pins(self, type_names, inpt, pin, corresponding_pins): + def _find_outputs_corresponding_pins( + self, type_names, inpt, pin, corresponding_pins, input_type_name + ): from ansys.dpf.core.results import Result for python_name in type_names: @@ -827,7 +829,7 @@ def _find_outputs_corresponding_pins(self, type_names, inpt, pin, corresponding_ python_name = "bool" # Type match - if type(inpt).__name__ == python_name: + if input_type_name == python_name: corresponding_pins.append(pin) # if the inpt has multiple potential outputs, find which ones can match elif isinstance(inpt, (_Outputs, Operator, Result)): diff --git a/src/ansys/dpf/core/inputs.py b/src/ansys/dpf/core/inputs.py index 0dfdce4ac7..9357a8e7ff 100644 --- a/src/ansys/dpf/core/inputs.py +++ b/src/ansys/dpf/core/inputs.py @@ -106,6 +106,8 @@ def connect(self, inpt): inpt = inpt.value input_type_name = type(inpt).__name__ + if input_type_name == "list": + input_type_name = f"list[{type(inpt[0]).__name__}]" if not (input_type_name in self._python_expected_types or ["Outputs", "Output", "Any"]): for types in self._python_expected_types: print(types, end=" ") @@ -114,7 +116,7 @@ def connect(self, inpt): corresponding_pins = [] self._operator()._find_outputs_corresponding_pins( - self._python_expected_types, inpt, self._pin, corresponding_pins + self._python_expected_types, inpt, self._pin, corresponding_pins, input_type_name ) if len(corresponding_pins) > 1: err_str = "Pin connection is ambiguous, specify the input to connect to with:\n" @@ -132,7 +134,7 @@ def connect(self, inpt): if len(corresponding_pins) == 0: err_str = ( - f"The input operator for the {self._spec.name} pin must be " + f"The input for the {self._spec.name} pin is of type {input_type_name} but must be " "one of the following types:\n" ) err_str += "\n".join([f"- {py_type}" for py_type in self._python_expected_types]) @@ -260,12 +262,15 @@ def connect(self, inpt): inpt = inpt.value input_type_name = type(inpt).__name__ + if input_type_name == "list": + input_type_name = f"list[{type(inpt[0]).__name__}]" for input_pin in self._inputs: self._operator()._find_outputs_corresponding_pins( input_pin._python_expected_types, inpt, input_pin._pin, corresponding_pins, + input_type_name, ) if len(corresponding_pins) > 1: err_str = "Pin connection is ambiguous, specify the input to connect to with:\n" diff --git a/src/ansys/dpf/core/mapping_types.py b/src/ansys/dpf/core/mapping_types.py index 9a7ad1e190..bd0698a54d 100644 --- a/src/ansys/dpf/core/mapping_types.py +++ b/src/ansys/dpf/core/mapping_types.py @@ -71,5 +71,6 @@ def __missing__(self, key): map_types_to_python = _smart_dict_snake() for k, v in map_types_to_cpp.items(): map_types_to_python[v] = k -map_types_to_python["vector"] = "list" +map_types_to_python["vector"] = "list[float]" +map_types_to_python["vector"] = "list[str]" map_types_to_python["b"] = "bool" From ba413a2515061dc8c9f77f37020d404b1adba29b Mon Sep 17 00:00:00 2001 From: PProfizi Date: Thu, 5 Jun 2025 15:40:39 +0200 Subject: [PATCH 2/2] Add mapping for list[int] and list[bool] --- src/ansys/dpf/core/mapping_types.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/ansys/dpf/core/mapping_types.py b/src/ansys/dpf/core/mapping_types.py index bd0698a54d..958ef52f73 100644 --- a/src/ansys/dpf/core/mapping_types.py +++ b/src/ansys/dpf/core/mapping_types.py @@ -71,6 +71,8 @@ def __missing__(self, key): map_types_to_python = _smart_dict_snake() for k, v in map_types_to_cpp.items(): map_types_to_python[v] = k +map_types_to_python["vector"] = "list[bool]" +map_types_to_python["vector"] = "list[int]" map_types_to_python["vector"] = "list[float]" map_types_to_python["vector"] = "list[str]" map_types_to_python["b"] = "bool"