Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
feded14
feat: add WorkflowTopology class and workflow_to_workflow_topology op…
Matteo-Baussart-ANSYS Nov 15, 2024
4ff8c4e
fix: updated Workflow.get_topology() to use derived classes
Matteo-Baussart-ANSYS Nov 21, 2024
f8467b6
feat: add tests for WorkflowTopology
Matteo-Baussart-ANSYS Nov 26, 2024
2078cd0
fix: add version conditions on new tests
Matteo-Baussart-ANSYS Nov 26, 2024
46c79f8
fix: !! (I forgot one)
Matteo-Baussart-ANSYS Nov 26, 2024
9880d99
feat: add test for WorkflowTopology.__str__()
Matteo-Baussart-ANSYS Nov 27, 2024
87aacb8
fix: remove leftover code
Matteo-Baussart-ANSYS Nov 27, 2024
4dfcee5
fix: add docstrings and typehinting
Matteo-Baussart-ANSYS Nov 29, 2024
2bc8fcd
feat: add titles and descriptions
Matteo-Baussart-ANSYS Nov 29, 2024
0e59baf
fix: add missing title and description for OperatorConnection
Matteo-Baussart-ANSYS Nov 29, 2024
09abcd7
fix: fix circular dependence
Matteo-Baussart-ANSYS Nov 29, 2024
5962788
feat: add get_output with CustomContainerBase and derived class
Matteo-Baussart-ANSYS Dec 2, 2024
f9ff71e
fix: simplify import of WorkflowTopology
Matteo-Baussart-ANSYS Dec 2, 2024
529909b
feat: add tests for derived class outputs
Matteo-Baussart-ANSYS Dec 2, 2024
0d8d7fc
fix: fix broken derived classes (mesh_info)
Matteo-Baussart-ANSYS Dec 2, 2024
2ba8475
fix: fix docstring
Matteo-Baussart-ANSYS Dec 2, 2024
da60366
fix: fix docstring escaping
Matteo-Baussart-ANSYS Dec 2, 2024
0b7522d
fix: remove extra import
Matteo-Baussart-ANSYS Dec 2, 2024
71f35ae
fix: add docstring/typehints; add exception in `Workflow.get_topology()`
Matteo-Baussart-ANSYS Dec 6, 2024
6052034
fix(test): revert some failing changes
Matteo-Baussart-ANSYS Dec 6, 2024
5a026b3
fix(test): revert some failing changes (bis)
Matteo-Baussart-ANSYS Dec 6, 2024
c047105
fix(test): revert some failing changes (ter)
Matteo-Baussart-ANSYS Dec 6, 2024
9e28ee6
fix: change version check
Matteo-Baussart-ANSYS Dec 6, 2024
1399247
feat: add ability to record derived types
Matteo-Baussart-ANSYS Dec 9, 2024
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
1 change: 1 addition & 0 deletions src/ansys/dpf/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@
CustomTypeFieldsCollection:type = _CollectionFactory(CustomTypeField)
GenericDataContainersCollection:type = _CollectionFactory(GenericDataContainer)
StringFieldsCollection:type = _CollectionFactory(StringField)
OperatorsCollection: type = _CollectionFactory(Operator)
AnyCollection:type = _Collection

# for matplotlib
Expand Down
28 changes: 28 additions & 0 deletions src/ansys/dpf/core/custom_container_base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright (C) 2020 - 2024 ANSYS, Inc. and/or its affiliates.
# SPDX-License-Identifier: MIT
#
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

from ansys.dpf.core.generic_data_container import GenericDataContainer


class CustomContainerBase:
def __init__(self, container: GenericDataContainer) -> None:
self._container = container

Check warning on line 28 in src/ansys/dpf/core/custom_container_base.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/dpf/core/custom_container_base.py#L28

Added line #L28 was not covered by tests
12 changes: 10 additions & 2 deletions src/ansys/dpf/core/dpf_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@ def _type_to_output_method(self):
collection_base,
any,
)
from ansys.dpf.core.workflow_topology import workflow_topology

out = [
(any.Any, self._api.operator_getoutput_as_any),
Expand Down Expand Up @@ -481,6 +482,11 @@ def _type_to_output_method(self):
self._api.operator_getoutput_as_any,
lambda obj, type: any.Any(server=self._server, any_dpf=obj).cast(type),
),
(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Matteo-Baussart-ANSYS can a Workflow also potentially take in or output a WorkflowTopology object?
Can an operator take a WorkflowTopology as input?

Copy link
Contributor Author

@Matteo-Baussart-ANSYS Matteo-Baussart-ANSYS Dec 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WorkflowTopology can be the output for an Operator and from a Workflow. Following syntaxes are tested:

# For operator outputs
workflow_to_workflow_topology_op.outputs.workflow_topology()
workflow_to_workflow_topology_op.get_output(0, WorkflowTopology)
# For workflow outputs
workflow_topology = dpf_workflow_wrapper.get_output("output", WorkflowTopology)

As for inputs, there is currently no operator requiring a CustomContainerBase as input.

workflow_topology.WorkflowTopology,
None,
"WorkflowTopology",
),
]
if hasattr(self._api, "operator_getoutput_generic_data_container"):
out.append(
Expand Down Expand Up @@ -726,8 +732,10 @@ def default_config(name, server=None):

def __del__(self):
try:
if self._internal_obj is not None:
self._deleter_func[0](self._deleter_func[1](self))
if hasattr(self, "_deleter_func"):
obj = self._deleter_func[1](self)
if obj is not None:
self._deleter_func[0](obj)
except:
warnings.warn(traceback.format_exc())

Expand Down
16 changes: 16 additions & 0 deletions src/ansys/dpf/core/helpers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,19 @@
warnings.warn(txt)
# Return the accepted arguments
return kwargs_in


def indent(text, subsequent_indent="", initial_indent=None):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Matteo-Baussart-ANSYS this will need a docstring with description and parameters. Also typehinting?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added docstring and typehinting

if initial_indent is None:
initial_indent = subsequent_indent

Check warning on line 55 in src/ansys/dpf/core/helpers/utils.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/dpf/core/helpers/utils.py#L54-L55

Added lines #L54 - L55 were not covered by tests

if not isinstance(text, str):
text = str(text)

Check warning on line 58 in src/ansys/dpf/core/helpers/utils.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/dpf/core/helpers/utils.py#L57-L58

Added lines #L57 - L58 were not covered by tests

lines = text.rstrip().splitlines()
indented_lines = [

Check warning on line 61 in src/ansys/dpf/core/helpers/utils.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/dpf/core/helpers/utils.py#L60-L61

Added lines #L60 - L61 were not covered by tests
f"{initial_indent if index == 0 else subsequent_indent}{line}"
for (index, line) in enumerate(lines)
]

return "\n".join(indented_lines)

Check warning on line 66 in src/ansys/dpf/core/helpers/utils.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/dpf/core/helpers/utils.py#L66

Added line #L66 was not covered by tests
9 changes: 9 additions & 0 deletions src/ansys/dpf/core/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -953,6 +953,15 @@
"""Saves the workflow to a GraphViz file."""
return self._api.work_flow_export_graphviz(self, str(path))

def get_topology(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Matteo-Baussart-ANSYS same, missing a docstring and typehinting

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added docstring and typehinting

workflow_to_workflow_topology_op = dpf_operator.Operator(

Check warning on line 957 in src/ansys/dpf/core/workflow.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/dpf/core/workflow.py#L957

Added line #L957 was not covered by tests
"workflow_to_workflow_topology", server=self._server
)
workflow_to_workflow_topology_op.inputs.workflow.connect(self)
workflow_topology_container = workflow_to_workflow_topology_op.outputs.workflow_topology()

Check warning on line 961 in src/ansys/dpf/core/workflow.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/dpf/core/workflow.py#L960-L961

Added lines #L960 - L961 were not covered by tests

return workflow_topology_container

Check warning on line 963 in src/ansys/dpf/core/workflow.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/dpf/core/workflow.py#L963

Added line #L963 was not covered by tests

def __del__(self):
try:
if hasattr(self, "_internal_obj"):
Expand Down
89 changes: 89 additions & 0 deletions src/ansys/dpf/core/workflow_topology/data_connection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# Copyright (C) 2020 - 2024 ANSYS, Inc. and/or its affiliates.
# SPDX-License-Identifier: MIT
#
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will need a title, reference tag and description. You can find examples of that being done in other modules.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added titles and descriptions

from ansys.dpf.core.custom_container_base import CustomContainerBase


class DataConnection(CustomContainerBase):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Matteo-Baussart-ANSYS again, missing docstrings and typehinting everywhere

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added docstrings and typehinting

def __init__(self, container):
super().__init__(container)
self._source_data = None
self._target_operator = None
self._target_pin_id = None

@property
def source_data(self):
if self._source_data is None:
self._source_data = self._container.get_property("source_data")

return self._source_data

@property
def target_operator(self):
from ansys.dpf.core.dpf_operator import Operator

if self._target_operator is None:
self._target_operator = self._container.get_property("target_operator", Operator)

return self._target_operator

@property
def target_pin_id(self):
if self._target_pin_id is None:
self._target_pin_id = self._container.get_property("target_pin_id", int)

return self._target_pin_id

def __str__(self):
from ansys.dpf.core.helpers.utils import indent

indents = " "
return (
"DataConnection with properties:\n"
" - source_data:\n"
f"{indent(self.source_data, indents)}\n"
" - target_operator:\n"
f"{indent(self.target_operator.name, indents)}\n"
" - target_pin_id:\n"
f"{indent(self.target_pin_id, indents)}"
)


class DataConnectionsCollection:
def __init__(self, collection):
self._collection = collection

def __len__(self):
return len(self._collection)

def __getitem__(self, index):
return DataConnection(self._collection[index])

def __iter__(self):
for i in range(len(self)):
yield self[i]

def __str__(self):
from ansys.dpf.core.helpers.utils import indent

indents = (" ", " - ")
return "\n".join([indent(data_connection, *indents) for data_connection in self])
89 changes: 89 additions & 0 deletions src/ansys/dpf/core/workflow_topology/exposed_pin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# Copyright (C) 2020 - 2024 ANSYS, Inc. and/or its affiliates.
# SPDX-License-Identifier: MIT
#
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

from ansys.dpf.core.custom_container_base import CustomContainerBase


class ExposedPin(CustomContainerBase):
def __init__(self, container):
super().__init__(container)
self._name = None
self._operator = None
self._pin_id = None

@property
def name(self):
if self._name is None:
self._name = self._container.get_property("name", str)

return self._name

@property
def operator(self):
from ansys.dpf.core.dpf_operator import Operator

if self._operator is None:
self._operator = self._container.get_property("operator", Operator)

return self._operator

@property
def pin_id(self):
if self._pin_id is None:
self._pin_id = self._container.get_property("pin_id", int)

return self._pin_id

def __str__(self):
from ansys.dpf.core.helpers.utils import indent

indents = " "
return (
"ExposedPin with properties:\n"
" - name:\n"
f"{indent(self.name, indents)}\n"
" - operator:\n"
f"{indent(self.operator.name, indents)}\n"
" - pin_id:\n"
f"{indent(self.pin_id, indents)}"
)


class ExposedPinsCollection:
def __init__(self, collection):
self._collection = collection

def __len__(self):
return len(self._collection)

def __getitem__(self, index):
return ExposedPin(self._collection[index])

def __iter__(self):
for i in range(len(self)):
yield self[i]

def __str__(self):
from ansys.dpf.core.helpers.utils import indent

indents = (" ", " - ")
return "\n".join([indent(exposed_pin, *indents) for exposed_pin in self])
101 changes: 101 additions & 0 deletions src/ansys/dpf/core/workflow_topology/operator_connection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# Copyright (C) 2020 - 2024 ANSYS, Inc. and/or its affiliates.
# SPDX-License-Identifier: MIT
#
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

from ansys.dpf.core.custom_container_base import CustomContainerBase


class OperatorConnection(CustomContainerBase):
def __init__(self, container):
super().__init__(container)
self._source_operator = None
self._source_pin_id = None
self._target_operator = None
self._target_pin_id = None

@property
def source_operator(self):
from ansys.dpf.core.dpf_operator import Operator

if self._source_operator is None:
self._source_operator = self._container.get_property("source_operator", Operator)

return self._source_operator

@property
def source_pin_id(self):
if self._source_pin_id is None:
self._source_pin_id = self._container.get_property("source_pin_id", int)

return self._source_pin_id

@property
def target_operator(self):
from ansys.dpf.core.dpf_operator import Operator

if self._target_operator is None:
self._target_operator = self._container.get_property("target_operator", Operator)

return self._target_operator

@property
def target_pin_id(self):
if self._target_pin_id is None:
self._target_pin_id = self._container.get_property("target_pin_id", int)

return self._target_pin_id

def __str__(self):
from ansys.dpf.core.helpers.utils import indent

indents = " "
return (
"OperatorConnection with properties:\n"
" - source_operator:\n"
f"{indent(self.source_operator.name, indents)}\n"
" - source_pin_id:\n"
f"{indent(self.source_pin_id, indents)}\n"
" - target_operator:\n"
f"{indent(self.target_operator.name, indents)}\n"
" - target_pin_id:\n"
f"{indent(self.target_pin_id, indents)}"
)


class OperatorConnectionsCollection:
def __init__(self, collection):
self._collection = collection

def __len__(self):
return len(self._collection)

def __getitem__(self, index):
return OperatorConnection(self._collection[index])

def __iter__(self):
for i in range(len(self)):
yield self[i]

def __str__(self):
from ansys.dpf.core.helpers.utils import indent

indents = (" ", " - ")
return "\n".join([indent(operator_connection, *indents) for operator_connection in self])
Loading