Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
cdc496b
[TMP] Prototype recursive clone code
greschd Aug 20, 2024
7f0d6c6
Add docstring to recursive_copy
greschd Aug 22, 2024
f5a400d
Add more recursive_copy tests
greschd Aug 22, 2024
0a0967b
Improve docstrings
greschd Aug 22, 2024
692c49e
Fix LUT copying in recursive copy
greschd Aug 23, 2024
435df2a
Fix allowed values in reference_direction_field, small bugfix in .sto…
greschd Aug 23, 2024
82f0ed9
Use linked_object_helpers to replace links
greschd Sep 18, 2024
080d33b
Update src/ansys/acp/core/_recursive_copy.py
greschd Sep 18, 2024
22a2b0c
Implement KEEP / COPY / DISCARD link handling modes
greschd Sep 18, 2024
7113b81
Make tree objects hashable, use them in dict
greschd Sep 18, 2024
74c00ae
Switch to returning an old -> new mapping
greschd Sep 18, 2024
20d9f12
Fix tests
greschd Sep 18, 2024
c2ba9a1
Fix pre-commit hooks and doc build
greschd Sep 18, 2024
5525c3d
Remove _traversal helpers, move dependency graph generation to separa…
greschd Sep 18, 2024
f6f9fb0
Implement suggestions from code review
greschd Sep 18, 2024
b32c7aa
Fix tests
greschd Sep 18, 2024
8eea31d
Test exceptions when copying across models
greschd Sep 18, 2024
3418124
Merge branch 'main' into feat/recursive_clone
greschd Sep 19, 2024
0063971
Improve test_properties performance
greschd Sep 19, 2024
2222235
Adapt test_workflow_unit_system_dat to server changes
greschd Sep 19, 2024
500b2b8
Add tests for EdgePropertyType clone
greschd Sep 19, 2024
37c5c0c
Add tests for the .parent property
greschd Sep 19, 2024
9a3d478
Add multiple coverage uploads
greschd Sep 19, 2024
27174ef
Remove broken HTML coverage upload
greschd Sep 19, 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
21 changes: 11 additions & 10 deletions .github/workflows/ci_cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -172,31 +172,32 @@ jobs:
LICENSE_SERVER: ${{ secrets.LICENSE_SERVER }}
IMAGE_NAME: "ghcr.io/ansys/acp${{ github.event.inputs.docker_image_suffix || ':latest' }}"

- name: "Upload coverage to Codecov"
uses: codecov/codecov-action@v4
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
with:
files: coverage.xml
flags: 'server-latest,python-${{ matrix.python-version }}'

- name: "Unit testing (2024R2 server)"
if: matrix.python-version == env.MAIN_PYTHON_VERSION
working-directory: tests/unittests
run: |
docker pull $IMAGE_NAME
poetry run pytest -v --license-server=1055@$LICENSE_SERVER --no-server-log-files --docker-image=$IMAGE_NAME --cov=ansys.acp.core --cov-report=term --cov-report=xml --cov-report=html --cov-append
poetry run pytest -v --license-server=1055@$LICENSE_SERVER --no-server-log-files --docker-image=$IMAGE_NAME --cov=ansys.acp.core --cov-report=term --cov-report=xml --cov-report=html
env:
LICENSE_SERVER: ${{ secrets.LICENSE_SERVER }}
IMAGE_NAME: "ghcr.io/ansys/acp:2024r2"

- name: "Upload coverage report (HTML)"
uses: actions/upload-artifact@v4
- name: "Upload coverage to Codecov (2024R2 server)"
if: matrix.python-version == env.MAIN_PYTHON_VERSION
with:
name: coverage-report-html
path: htmlcov
retention-days: 7

- name: "Upload coverage to Codecov"
uses: codecov/codecov-action@v4
if: matrix.python-version == env.MAIN_PYTHON_VERSION
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
with:
files: coverage.xml
flags: 'server-242,python-${{ matrix.python-version }}'

- name: Benchmarks
working-directory: tests/benchmarks
Expand Down
1 change: 1 addition & 0 deletions doc/source/api/enum_types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Enumeration data types
FeFormat
GeometricalRuleType
IgnorableEntity
LinkedObjectHandling
LookUpTable3DInterpolationAlgorithm
LookUpTableColumnValueType
NodalDataType
Expand Down
1 change: 1 addition & 0 deletions doc/source/api/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ and attributes.
material_property_sets
enum_types
plot_utils
other_utils
workflow
example_helpers
internal
9 changes: 9 additions & 0 deletions doc/source/api/other_utils.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Other utilities
---------------

.. currentmodule:: ansys.acp.core

.. autosummary::
:toctree: _autosummary

recursive_copy
26 changes: 22 additions & 4 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ ansys-tools-path = ">=0"
ansys-tools-local-product-launcher = ">=0.1"
ansys-tools-filetransfer = ">=0.1"
pyvista = ">=0.42.0"
networkx = ">=3.0.0"

# Dependencies for the examples. Update also the 'dev' group when
# these are updated.
Expand Down Expand Up @@ -147,8 +148,9 @@ pretty = true
[[tool.mypy.overrides]]
module = [
"docker.*",
"grpc.*",
"grpc_health.*",
"grpc.*",
"networkx",
"scipy.optimize",
"ansys.mapdl",
"ansys.mapdl.core",
Expand Down
3 changes: 3 additions & 0 deletions src/ansys/acp/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from . import example_helpers, material_property_sets
from ._model_printer import get_model_tree, print_model
from ._plotter import get_directions_plotter
from ._recursive_copy import LinkedObjectHandling, recursive_copy
from ._server import (
ACP,
ConnectLaunchConfig,
Expand Down Expand Up @@ -191,6 +192,7 @@
"Lamina",
"launch_acp",
"LaunchMode",
"LinkedObjectHandling",
"LinkedSelectionRule",
"LookUpTable1D",
"LookUpTable1DColumn",
Expand Down Expand Up @@ -223,6 +225,7 @@
"ProductionPly",
"ProductionPlyElementalData",
"ProductionPlyNodalData",
"recursive_copy",
"Rosette",
"RosetteSelectionMethod",
"RosetteType",
Expand Down
108 changes: 108 additions & 0 deletions src/ansys/acp/core/_dependency_graph.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# Copyright (C) 2022 - 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 collections.abc import Iterable, Iterator
from dataclasses import dataclass

import networkx as nx

from ._tree_objects._grpc_helpers.linked_object_helpers import get_linked_paths
from ._tree_objects._grpc_helpers.mapping import Mapping
from ._tree_objects._grpc_helpers.polymorphic_from_pb import tree_object_from_resource_path
from ._tree_objects.base import CreatableTreeObject, TreeObject


@dataclass
class _WalkTreeOptions:
include_children: bool
include_linked_objects: bool


def _build_dependency_graph(
*, source_objects: Iterable[CreatableTreeObject], options: _WalkTreeOptions
) -> nx.DiGraph:
"""Build a dependency graph of the given objects."""
graph = nx.DiGraph()

# We need to manually keep track of which objects have been visited,
# since the node may also be created when being linked to.
visited_objects: set[CreatableTreeObject] = set()
for tree_object in source_objects:
_build_dependency_graph_impl(
tree_object=tree_object, graph=graph, visited_objects=visited_objects, options=options
)
return graph


def _build_dependency_graph_impl(
*,
tree_object: CreatableTreeObject,
graph: nx.DiGraph,
visited_objects: set[CreatableTreeObject],
options: _WalkTreeOptions,
) -> None:

if tree_object in visited_objects:
return

visited_objects.add(tree_object)
graph.add_node(tree_object)

if options.include_children:
for child_object in _yield_child_objects(tree_object):
if not isinstance(child_object, CreatableTreeObject):
continue
graph.add_edge(child_object, tree_object)
_build_dependency_graph_impl(
tree_object=child_object,
graph=graph,
visited_objects=visited_objects,
options=options,
)
if options.include_linked_objects:
for linked_object in _yield_linked_objects(tree_object):
graph.add_edge(tree_object, linked_object)
_build_dependency_graph_impl(
tree_object=linked_object,
graph=graph,
visited_objects=visited_objects,
options=options,
)


def _yield_child_objects(tree_object: TreeObject) -> Iterator[TreeObject]:
for attr_name in tree_object._GRPC_PROPERTIES:
try:
attr = getattr(tree_object, attr_name)
except (AttributeError, RuntimeError):
continue
if isinstance(attr, Mapping):
yield from attr.values()


def _yield_linked_objects(tree_object: TreeObject) -> Iterator[CreatableTreeObject]:
for linked_path in get_linked_paths(tree_object._pb_object.properties):
linked_object = tree_object_from_resource_path(
linked_path, server_wrapper=tree_object._server_wrapper
)
assert isinstance(linked_object, CreatableTreeObject)
yield linked_object
Loading