Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
6a19100
Expose aliases in Input, Output, and PinSpecification
PProfizi Feb 5, 2025
2a49a32
Add alias to template and operator code generation
PProfizi Feb 5, 2025
061a3c7
Handle retro in Specification
PProfizi Feb 5, 2025
0c00799
Expose alias in operator_specification_grpcapi.py
PProfizi Feb 5, 2025
2608a49
Try getattr in template
PProfizi Feb 5, 2025
572a8da
Handle default __getattr__
PProfizi Feb 6, 2025
13c1c20
Add a deprecation warning when using pin aliases
PProfizi Feb 7, 2025
4764244
Fix Specification doctests
PProfizi Feb 10, 2025
c707fd4
Limit changes to operators with aliases
PProfizi Feb 10, 2025
dec7e2b
Fix retro compatibility condition
PProfizi Feb 17, 2025
1141954
Make operator_specification_get_pin_num_aliases retro-compatible
PProfizi Feb 26, 2025
69f6b11
Remove server version check
PProfizi Feb 26, 2025
05e54a5
Revert "Remove server version check"
PProfizi Feb 26, 2025
73575bb
Add server version check
PProfizi Feb 26, 2025
9e5a5c3
Do not remove translator.py during code_generation.py
PProfizi Mar 3, 2025
41ead92
Add default value to variable for error reporting in build.py
PProfizi Mar 3, 2025
43e5b09
Add aliases as valid operator inputs in the signature
PProfizi Mar 3, 2025
8ad4d18
Fix indent in operator.mustache
PProfizi Mar 3, 2025
0ccccbe
Fix indentation in operator.mustache
PProfizi Mar 3, 2025
eacedfe
Print server path for operator generation
PProfizi Mar 3, 2025
b0faf24
Limit tests to mac operator
PProfizi Mar 4, 2025
d086139
Add aliases to operator signature
PProfizi Mar 4, 2025
09f6ca8
Fix dict creation
PProfizi Mar 4, 2025
1b7b619
Revert "Limit tests to mac operator"
PProfizi Mar 4, 2025
433ba3c
update generated code (#2129)
pyansys-ci-bot Mar 4, 2025
cdaa510
Remove redundant code following rebase
PProfizi Mar 4, 2025
42be3fd
Reactivate retro testing for test_animation.py and test_animator.py
PProfizi Mar 4, 2025
5679732
Add deprecation warning when using an alias as operator instantiation…
PProfizi Mar 4, 2025
059cf9f
Add test_specification.py with test_pin_alias
PProfizi Mar 4, 2025
69c57d6
update generated code (#2131)
pyansys-ci-bot Mar 4, 2025
c36b6e3
Skip test_pin_alias during retro tests
PProfizi Mar 4, 2025
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
4 changes: 2 additions & 2 deletions src/ansys/dpf/core/dpf_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ def id(self) -> int:
return self._id

@property
def inputs(self):
def inputs(self) -> Inputs:
"""Inputs connected to the operator.

Returns
Expand All @@ -702,7 +702,7 @@ def inputs(self):
return self._inputs

@property
def outputs(self):
def outputs(self) -> Outputs:
"""Outputs from the operator's evaluation.

Returns
Expand Down
6 changes: 6 additions & 0 deletions src/ansys/dpf/core/inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
self._python_expected_types.append(map_types_to_python[cpp_type])
if len(self._spec.type_names) == 0:
self._python_expected_types.append("Any")
self.aliases = self._spec.aliases
docstr = self.__str__()
self.name = self._spec.name
if self._count_ellipsis != -1:
Expand Down Expand Up @@ -187,6 +188,8 @@
docstr += "\n".join(wrap(self._spec.document.capitalize())) + "\n"
if self._count_ellipsis >= 0:
docstr += "is ellipsis\n"
if self.aliases:
docstr += f"aliases: {self.aliases}\n"
return docstr

def __inc_if_ellipsis(self):
Expand Down Expand Up @@ -317,6 +320,9 @@
def __call__(self, inpt):
self.connect(inpt)

def __getitem__(self, item) -> Input:
return self._inputs[item]

Check warning on line 324 in src/ansys/dpf/core/inputs.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/dpf/core/inputs.py#L324

Added line #L324 was not covered by tests


# Dynamic class Inputs
class Inputs(_Inputs):
Expand Down
26 changes: 21 additions & 5 deletions src/ansys/dpf/core/operator_specification.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class PinSpecification:
optional: bool
ellipsis: bool
name_derived_class = str
aliases: list[str]

def __init__(
self,
Expand All @@ -87,13 +88,15 @@ def __init__(
optional=False,
ellipsis=False,
name_derived_class="",
aliases=[],
):
self.name = name
self.type_names = type_names
self.optional = optional
self.document = document
self.ellipsis = ellipsis
self.name_derived_class = name_derived_class
self.aliases = aliases

@property
def type_names(self) -> list[str]:
Expand Down Expand Up @@ -140,6 +143,7 @@ def _get_copy(other, changed_types) -> PinSpecification:
other.optional,
other.ellipsis,
other.name_derived_class,
other.aliases,
)

def __repr__(self):
Expand Down Expand Up @@ -367,7 +371,7 @@ def description(self) -> str:
return ""

@property
def inputs(self) -> dict:
def inputs(self) -> dict[int, PinSpecification]:
"""Returns a dictionary mapping the input pin numbers to their ``PinSpecification``.

Returns
Expand All @@ -382,15 +386,15 @@ def inputs(self) -> dict:
True
>>> operator.specification.inputs[4]
PinSpecification(name='data_sources', _type_names=['data_sources'], ...set', ellipsis=False,
name_derived_class='')
name_derived_class='', aliases=[...])
"""
if self._map_input_pin_spec is None:
self._map_input_pin_spec = {}
self._fill_pins(True, self._map_input_pin_spec)
return self._map_input_pin_spec

@property
def outputs(self) -> dict:
def outputs(self) -> dict[int, PinSpecification]:
"""Returns a dictionary mapping the output pin numbers to their ``PinSpecification``.

Returns
Expand All @@ -403,7 +407,7 @@ def outputs(self) -> dict:
>>> operator = dpf.operators.mesh.mesh_provider()
>>> operator.specification.outputs
{0: PinSpecification(name='mesh', _type_names=['abstract_meshed_region'], ...=False,
name_derived_class='')}
name_derived_class='', aliases=[...])}
"""
if self._map_output_pin_spec is None:
self._map_output_pin_spec = {}
Expand All @@ -429,7 +433,18 @@ def _fill_pins(self, binput, to_fill):
self._api.operator_specification_get_pin_type_name(self, binput, i_pin, i_type)
for i_type in range(n_types)
]

pin_aliases = []
if server_meet_version("10.0", self._server) and hasattr(
self._api, "operator_specification_get_pin_num_aliases"
):
for i_alias in range(
self._api.operator_specification_get_pin_num_aliases(self, binput, i_pin)
):
pin_aliases.append(
self._api.operator_specification_get_pin_alias(
self, binput, i_pin, i_alias
)
)
pin_derived_class_type_name = ""
if server_meet_version("7.0", self._server) and hasattr(
self._api, "operator_specification_get_pin_derived_class_type_name"
Expand All @@ -448,6 +463,7 @@ def _fill_pins(self, binput, to_fill):
pin_opt,
pin_ell,
pin_derived_class_type_name,
pin_aliases,
)

@property
Expand Down
10 changes: 9 additions & 1 deletion src/ansys/dpf/core/operators/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ def build_pin_data(pins, output=False):
"document": document,
"document_pin_docstring": document_pin_docstring,
"ellipsis": 0 if specification.ellipsis else -1,
"has_aliases": len(specification.aliases) > 0,
"aliases_list": [dict([("alias", alias)]) for alias in specification.aliases],
"aliases": str(specification.aliases),
}

if specification.ellipsis:
Expand All @@ -127,11 +130,13 @@ def build_operator(
input_pins = []
if specification.inputs:
input_pins = build_pin_data(specification.inputs)
has_input_aliases = any(len(pin["aliases_list"]) > 0 for pin in input_pins)

output_pins = []
if specification.outputs:
output_pins = build_pin_data(specification.outputs, output=True)
multiple_output_types = any(pin["multiple_types"] for pin in output_pins)
has_output_aliases = any(len(pin["aliases_list"]) > 0 for pin in output_pins)

docstring = build_docstring(specification_description)

Expand All @@ -150,6 +155,8 @@ def build_operator(
"multiple_output_types": multiple_output_types,
"category": category,
"date_and_time": date_and_time,
"has_input_aliases": has_input_aliases,
"has_output_aliases": has_output_aliases,
}

this_path = os.path.dirname(os.path.abspath(__file__))
Expand All @@ -164,7 +171,7 @@ def build_operator(


def build_operators():
print(f"Generating operators for server {dpf.SERVER.version}")
print(f"Generating operators for server {dpf.SERVER.version} ({dpf.SERVER.ansys_path})")
time_0 = time.time()

this_path = os.path.dirname(os.path.abspath(__file__))
Expand Down Expand Up @@ -228,6 +235,7 @@ def build_operators():
# Write to operator file
operator_file = os.path.join(category_path, scripting_name + ".py")
with open(operator_file, "wb") as f:
operator_str = scripting_name
try:
operator_str = build_operator(
specification,
Expand Down
28 changes: 27 additions & 1 deletion src/ansys/dpf/core/operators/math/accumulate.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,13 @@ class accumulate(Operator):
"""

def __init__(
self, fieldA=None, weights=None, time_scoping=None, config=None, server=None
self,
fieldA=None,
weights=None,
time_scoping=None,
config=None,
server=None,
ponderation=None,
):
super().__init__(name="accumulate", config=config, server=server)
self._inputs = InputsAccumulate(self)
Expand All @@ -70,6 +76,13 @@ def __init__(
self.inputs.fieldA.connect(fieldA)
if weights is not None:
self.inputs.weights.connect(weights)
elif ponderation is not None:
warn(
DeprecationWarning(
f'Operator accumulate: Input name "ponderation" is deprecated in favor of "weights".'
)
)
self.inputs.weights.connect(ponderation)
if time_scoping is not None:
self.inputs.time_scoping.connect(time_scoping)

Expand All @@ -92,6 +105,7 @@ def _spec() -> Specification:
type_names=["field"],
optional=True,
document=r"""Field containing weights, one weight per entity""",
aliases=["ponderation"],
),
2: PinSpecification(
name="time_scoping",
Expand Down Expand Up @@ -243,6 +257,18 @@ def time_scoping(self) -> Input:
"""
return self._time_scoping

def __getattr__(self, name):
if name in ["ponderation"]:
warn(
DeprecationWarning(
f'Operator accumulate: Input name "{name}" is deprecated in favor of "weights".'
)
)
return self.weights
raise AttributeError(
f"'{self.__class__.__name__}' object has no attribute '{name}'."
)


class OutputsAccumulate(_Outputs):
"""Intermediate class used to get outputs from
Expand Down
21 changes: 21 additions & 0 deletions src/ansys/dpf/core/operators/math/accumulate_fc.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def __init__(
time_scoping=None,
config=None,
server=None,
ponderation=None,
):
super().__init__(name="accumulate_fc", config=config, server=server)
self._inputs = InputsAccumulateFc(self)
Expand All @@ -75,6 +76,13 @@ def __init__(
self.inputs.fields_container.connect(fields_container)
if weights is not None:
self.inputs.weights.connect(weights)
elif ponderation is not None:
warn(
DeprecationWarning(
f'Operator accumulate_fc: Input name "ponderation" is deprecated in favor of "weights".'
)
)
self.inputs.weights.connect(ponderation)
if time_scoping is not None:
self.inputs.time_scoping.connect(time_scoping)

Expand All @@ -97,6 +105,7 @@ def _spec() -> Specification:
type_names=["field"],
optional=True,
document=r"""Field containing weights, one weight per entity""",
aliases=["ponderation"],
),
2: PinSpecification(
name="time_scoping",
Expand Down Expand Up @@ -248,6 +257,18 @@ def time_scoping(self) -> Input:
"""
return self._time_scoping

def __getattr__(self, name):
if name in ["ponderation"]:
warn(
DeprecationWarning(
f'Operator accumulate_fc: Input name "{name}" is deprecated in favor of "weights".'
)
)
return self.weights
raise AttributeError(
f"'{self.__class__.__name__}' object has no attribute '{name}'."
)


class OutputsAccumulateFc(_Outputs):
"""Intermediate class used to get outputs from
Expand Down
29 changes: 28 additions & 1 deletion src/ansys/dpf/core/operators/math/add_constant.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,28 @@ class add_constant(Operator):
>>> result_field = op.outputs.field()
"""

def __init__(self, field=None, weights=None, config=None, server=None):
def __init__(
self,
field=None,
weights=None,
config=None,
server=None,
ponderation=None,
):
super().__init__(name="add_constant", config=config, server=server)
self._inputs = InputsAddConstant(self)
self._outputs = OutputsAddConstant(self)
if field is not None:
self.inputs.field.connect(field)
if weights is not None:
self.inputs.weights.connect(weights)
elif ponderation is not None:
warn(
DeprecationWarning(
f'Operator add_constant: Input name "ponderation" is deprecated in favor of "weights".'
)
)
self.inputs.weights.connect(ponderation)

@staticmethod
def _spec() -> Specification:
Expand All @@ -80,6 +94,7 @@ def _spec() -> Specification:
type_names=["double", "vector<double>"],
optional=False,
document=r"""double or vector of double""",
aliases=["ponderation"],
),
},
map_output_pin_spec={
Expand Down Expand Up @@ -200,6 +215,18 @@ def weights(self) -> Input:
"""
return self._weights

def __getattr__(self, name):
if name in ["ponderation"]:
warn(
DeprecationWarning(
f'Operator add_constant: Input name "{name}" is deprecated in favor of "weights".'
)
)
return self.weights
raise AttributeError(
f"'{self.__class__.__name__}' object has no attribute '{name}'."
)


class OutputsAddConstant(_Outputs):
"""Intermediate class used to get outputs from
Expand Down
Loading
Loading