Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Remove reinitialize from enhanced meshing workflow. #2880

Merged
merged 13 commits into from
Jun 13, 2024
Merged
Changes from 4 commits
Commits
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
7 changes: 1 addition & 6 deletions src/ansys/fluent/core/meshing/meshing_workflow.py
Original file line number Diff line number Diff line change
@@ -72,14 +72,9 @@ def __init__(
self._unsubscribe_root_affected_callback()
self._new_workflow(name=self._name)

def reinitialize(self) -> None:
"""Reinitialize the same workflow."""
self._new_workflow(name=self._name)

def __getattribute__(self, item: str):
if (
item not in ["reinitialize"]
and not item.startswith("_")
not item.startswith("_")
and not getattr(self._meshing.GlobalSettings, self._identifier)()
):
raise RuntimeError(
94 changes: 56 additions & 38 deletions src/ansys/fluent/core/workflow.py
Original file line number Diff line number Diff line change
@@ -131,6 +131,16 @@ def _refresh_task_accessors(obj):
_refresh_task_accessors(task)


def _call_refresh_task_accessors(obj):
"""This layer handles exception for PyConsole."""
try:
_refresh_task_accessors(obj)
except Exception:
# Is there a more specific Exception derived class
# for which we know it is correct to pass?
pass


def _convert_task_list_to_display_names(workflow_root, task_list):
if workflow_root.service.cache is not None:
workflow_state = workflow_root.service.cache.get_state(
@@ -1280,37 +1290,41 @@ def __init__(
command_source : PyMenuGeneric
The application root for commanding.
"""
self._workflow = workflow
self._command_source = command_source
self._python_task_names = []
self._lock = threading.RLock()
self._refreshing = False
self._dynamic_python_names = False
self._refresh_count = 0
self._ordered_children = []
self._task_list = []
self._getattr_recurse_depth = 0
self._main_thread_ident = None
self._task_objects = {}
self._dynamic_interface = False
self._python_name_command_id_map = {}
self._python_name_display_id_map = {}
self._python_name_display_text_map = {}
self._repeated_task_python_name_display_text_map = {}
self._initial_task_python_names_map = {}
self._unwanted_attrs = {
"reset_workflow",
"initialize_workflow",
"load_workflow",
"insert_new_task",
"create_composite_task",
"create_new_workflow",
"rules",
"service",
"task_object",
"workflow",
}
self._fluent_version = fluent_version
self.__dict__.update(
dict(
_workflow=workflow,
_command_source=command_source,
_python_task_names=[],
_lock=threading.RLock(),
_refreshing=False,
_dynamic_python_names=False,
_refresh_count=0,
_ordered_children=[],
_task_list=[],
_getattr_recurse_depth=0,
_main_thread_ident=None,
_task_objects={},
_dynamic_interface=False,
_python_name_command_id_map={},
_python_name_display_id_map={},
_python_name_display_text_map={},
_repeated_task_python_name_display_text_map={},
_initial_task_python_names_map={},
_unwanted_attrs={
"reset_workflow",
"initialize_workflow",
"load_workflow",
"insert_new_task",
"create_composite_task",
"create_new_workflow",
"rules",
"service",
"task_object",
"workflow",
},
_fluent_version=fluent_version,
)
)

def task(self, name: str) -> BaseTask:
"""Get a TaskObject by name, in a ``BaseTask`` wrapper.
@@ -1396,6 +1410,7 @@ def inactive_tasks() -> list:

def __getattr__(self, attr):
"""Delegate attribute lookup to the wrapped workflow object."""
_call_refresh_task_accessors(self)
if attr in self._repeated_task_python_name_display_text_map:
return self.task(self._repeated_task_python_name_display_text_map[attr])
_task_object = self._task_objects.get(attr)
@@ -1414,6 +1429,15 @@ def __getattr__(self, attr):
return obj
return super().__getattribute__(attr)

def __setattr__(self, attr, value):
prmukherj marked this conversation as resolved.
Show resolved Hide resolved
logger.debug(f"Workflow.__setattr__({attr}, {value})")
if attr in self.__dict__:
self.__dict__[attr] = value
elif attr in self._task_objects:
self._task_objects[attr].set_state(value)
else:
super().__setattr__(attr, value)

def __dir__(self):
"""Override the behavior of ``dir`` to include attributes in the
``WorkflowWrapper`` class and the underlying workflow."""
@@ -1467,7 +1491,6 @@ def _activate_dynamic_interface(self, dynamic_interface: bool):
self._initialize_methods(dynamic_interface=dynamic_interface)

def _unsubscribe_root_affected_callback(self):
# if the same workflow is not being reinitialized, unsubscribe the root affected callback
if self._workflow.service in self._root_affected_cb_by_server:
self._root_affected_cb_by_server[self._workflow.service].unsubscribe()
self._root_affected_cb_by_server.pop(self._workflow.service)
@@ -1557,12 +1580,7 @@ def refresh_after_sleep(_):
logger.debug("Already _refreshing, ...")
self._refreshing = True
logger.debug("Call _refresh_task_accessors")
try:
_refresh_task_accessors(self)
except Exception:
# Is there a more specific Exception derived class
# for which we know it is correct to pass?
pass
_call_refresh_task_accessors(self)
self._refresh_count += 1
self._refreshing = False

16 changes: 7 additions & 9 deletions tests/test_new_meshing_workflow.py
Original file line number Diff line number Diff line change
@@ -1101,9 +1101,8 @@ def test_attrs_in_watertight_meshing_workflow(new_mesh_session):

assert watertight.import_geometry.file_name()
# Reinitialize the workflow:
watertight.reinitialize()
# Failing randomly in CI.
# assert not watertight.import_geometry.file_name()
watertight = new_mesh_session.watertight()
assert not watertight.import_geometry.file_name()


@pytest.mark.codegen_required
@@ -1147,8 +1146,7 @@ def test_attrs_in_fault_tolerant_meshing_workflow(new_mesh_session):

assert fault_tolerant.import_cad_and_part_management.fmd_file_name()
# Reinitialize the workflow:
fault_tolerant.reinitialize()

fault_tolerant = new_mesh_session.fault_tolerant()
assert not fault_tolerant.import_cad_and_part_management.fmd_file_name()


@@ -1177,7 +1175,7 @@ def test_switch_between_workflows(new_mesh_session):
watertight.import_geometry.arguments()

# Re-initialize watertight
watertight.reinitialize()
watertight = meshing.watertight()

# 'import_cad_and_part_management' is a fault-tolerant workflow command which is not
# available now since we have changed to watertight in the backend.
@@ -1201,12 +1199,12 @@ def test_switch_between_workflows(new_mesh_session):
fault_tolerant.import_cad_and_part_management.arguments()

# Re-initialize fault-tolerant
fault_tolerant.reinitialize()
fault_tolerant = meshing.fault_tolerant()
assert fault_tolerant.import_cad_and_part_management.arguments()


@pytest.mark.codegen_required
@pytest.mark.fluent_version(">=24.1")
@pytest.mark.fluent_version(">=24.2")
def test_new_meshing_workflow_without_dm_caching(
disable_datamodel_cache, new_mesh_session
):
@@ -1265,7 +1263,7 @@ def test_new_meshing_workflow_switching_without_dm_caching(
watertight.import_geometry.arguments()
assert fault_tolerant.import_cad_and_part_management.arguments()

watertight.reinitialize()
watertight = new_mesh_session.watertight()
with pytest.raises(RuntimeError):
fault_tolerant.import_cad_and_part_management.arguments()
assert watertight.import_geometry.arguments()