Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/pip/pytest-eq-8.3.4
Browse files Browse the repository at this point in the history
  • Loading branch information
prmukherj authored Jan 2, 2025
2 parents 11582d1 + 7a8f248 commit 6869550
Show file tree
Hide file tree
Showing 11 changed files with 121 additions and 78 deletions.
15 changes: 6 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,6 @@ jobs:
cat src/ansys/fluent/core/generated/fluent_version_251.py
python -c "from ansys.fluent.core.generated.solver.settings_251 import SHASH; print(f'SETTINGS_HASH = {SHASH}')"
# Replace v25.2.0 with ${{ vars.FLUENT_STABLE_IMAGE_DEV }} after the first successful nightly test run
- name: Cache 25.2 API Code
uses: actions/cache@v4
id: cache-252-api-code
Expand All @@ -453,25 +452,25 @@ jobs:
doc/source/api/core/meshing/datamodel
doc/source/api/core/solver/tui
doc/source/api/core/solver/datamodel
key: API-Code-v${{ env.API_CODE_CACHE }}-${{ steps.version.outputs.PYFLUENT_VERSION }}-v25.2.0-${{ hashFiles('src/ansys/fluent/core/codegen/**') }}
restore-keys: API-Code-v${{ env.API_CODE_CACHE }}-${{ steps.version.outputs.PYFLUENT_VERSION }}-v25.2.0
key: API-Code-v${{ env.API_CODE_CACHE }}-${{ steps.version.outputs.PYFLUENT_VERSION }}-${{ vars.FLUENT_STABLE_IMAGE_DEV }}-${{ hashFiles('src/ansys/fluent/core/codegen/**') }}
restore-keys: API-Code-v${{ env.API_CODE_CACHE }}-${{ steps.version.outputs.PYFLUENT_VERSION }}-${{ vars.FLUENT_STABLE_IMAGE_DEV }}

- name: Pull 25.2 Fluent docker image
if: steps.cache-251-api-code.outputs.cache-hit != 'true'
run: make docker-pull
env:
FLUENT_IMAGE_TAG: v25.2.0
FLUENT_IMAGE_TAG: ${{ vars.FLUENT_STABLE_IMAGE_DEV }}

- name: Run 25.2 API codegen
if: steps.cache-252-api-code.outputs.cache-hit != 'true'
run: make api-codegen
env:
FLUENT_IMAGE_TAG: v25.2.0
FLUENT_IMAGE_TAG: ${{ vars.FLUENT_STABLE_IMAGE_DEV }}

- name: Print 25.2 Fluent version info
run: |
cat src/ansys/fluent/core/generated/fluent_version_252.py
python -c "from ansys.fluent.core.generated.solver.settings_251 import SHASH; print(f'SETTINGS_HASH = {SHASH}')"
python -c "from ansys.fluent.core.generated.solver.settings_252 import SHASH; print(f'SETTINGS_HASH = {SHASH}')"
- name: Install again after codegen
run: |
Expand Down Expand Up @@ -517,9 +516,7 @@ jobs:
version: 252
timeout-minutes: 120
env:
# Enable this after the first successful nightly test run
# FLUENT_IMAGE_TAG: ${{ matrix.version == 252 && vars.FLUENT_STABLE_IMAGE_DEV || matrix.image-tag }}
FLUENT_IMAGE_TAG: ${{ matrix.image-tag }}
FLUENT_IMAGE_TAG: ${{ matrix.version == 252 && vars.FLUENT_STABLE_IMAGE_DEV || matrix.image-tag }}

steps:

Expand Down
2 changes: 1 addition & 1 deletion doc/source/cheatsheet/cheat_sheet.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ field_info = solver.fields.field_info
### Get fields info and range

```{python}
field_info.get_fields_info()
field_info.get_scalar_fields_info()
field_info.get_range("velocity")
field_info.get_range("cell-weight")
```
Expand Down
12 changes: 6 additions & 6 deletions doc/source/user_guide/fields/field_info.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@ Sample requests

Here are the methods for requesting field information:

- ``get_fields_info`` for getting fields information.
- ``get_scalar_fields_info`` for getting fields information.
- ``get_range`` for getting the range of the field.
- ``get_vector_fields_info`` for getting vector fields information.
- ``get_surfaces_info`` for getting the surfaces information.

Get fields info
~~~~~~~~~~~~~~~
Get scalar fields info
~~~~~~~~~~~~~~~~~~~~~~
You can request the fields information (field name, domain, and section) by
calling the ``get_fields_info`` method.
calling the ``get_scalar_fields_info`` method.

.. code-block:: python
>>> field_info.get_fields_info()
>>> field_info.get_scalar_fields_info()
{'pressure': {'display_name': 'Static Pressure', 'section': 'Pressure...', 'domain': 'mixture'},
'pressure-coefficient': {'display_name': 'Pressure Coefficient', 'section': 'Pressure...', 'domain': 'mixture'},
'dynamic-pressure': {'display_name': 'Dynamic Pressure', 'section': 'Pressure...', 'domain': 'mixture'},
Expand All @@ -52,7 +52,7 @@ Get range
~~~~~~~~~
You can request the range (minimum and maximum values) for a given ``field`` by
calling the ``get_range`` method. It takes a ``field`` argument which can be obtained
from the keys of the dictionary returned by ``get_fields_info`` method.
from the keys of the dictionary returned by ``get_scalar_fields_info`` method.

.. code-block:: python
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ python = ">=3.10,<4.0"
ansys-api-fluent = "^0.3.30"
ansys-platform-instancemanagement = "~=1.0"
ansys-tools-filetransfer = ">=0.1,<0.3"
ansys-units = "^0.3.3"
ansys-units = ">=0.3.3,<0.5"
docker = ">=7.1.0"
grpcio = "^1.30.0"
grpcio-health-checking = "^1.30.0"
Expand Down Expand Up @@ -78,7 +78,7 @@ beautifulsoup4 = "==4.12.3"
openpyxl = { version = ">=3.1.5", optional = true }
plotly = { version = ">=5.22.0", optional = true }
python-pptx = { version = ">=0.6.23", optional = true }
quarto-cli = "==1.6.37"
quarto-cli = "==1.6.39"
pdf2image = "==1.17.0"
seaborn = { version = ">=0.13.2", optional = true }
tensorflow = { version = ">=2.17.0", optional = true }
Expand Down
45 changes: 41 additions & 4 deletions src/ansys/fluent/core/services/datamodel_se.py
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,7 @@ def add_on_affected_at_type_path(
self.event_streaming.register_callback(subscription.tag, obj, cb)
return subscription

def add_on_command_executed(
def add_on_command_executed_old(
self, rules: str, path: str, command: str, obj, cb: Callable
) -> EventSubscription:
"""Add on command executed."""
Expand All @@ -826,6 +826,24 @@ def add_on_command_executed(
self.event_streaming.register_callback(subscription.tag, obj, cb)
return subscription

def add_on_command_executed(
self, rules: str, path: str, obj, cb: Callable
) -> EventSubscription:
"""Add on command executed."""
request_dict = {
"eventrequest": [
{
"rules": rules,
"commandExecutedEventRequest": {
"path": path,
},
}
]
}
subscription = EventSubscription(self, path, request_dict)
self.event_streaming.register_callback(subscription.tag, obj, cb)
return subscription

def add_on_attribute_changed(
self, rules: str, path: str, attribute: str, obj, cb: Callable
) -> EventSubscription:
Expand Down Expand Up @@ -1326,13 +1344,15 @@ def add_on_affected_at_type_path(
self.rules, convert_path_to_se_path(self.path), child_type, self, cb
)

def add_on_command_executed(self, command: str, cb: Callable) -> EventSubscription:
def add_on_command_executed_old(
self, command: str, cb: Callable
) -> EventSubscription:
"""Register a callback for when a command is executed.
Parameters
----------
command : str
command name
Command name
cb : Callable
Callback function
Expand All @@ -1341,10 +1361,27 @@ def add_on_command_executed(self, command: str, cb: Callable) -> EventSubscripti
EventSubscription
EventSubscription instance which can be used to unregister the callback
"""
return self.service.add_on_command_executed(
return self.service.add_on_command_executed_old(
self.rules, convert_path_to_se_path(self.path), command, self, cb
)

def add_on_command_executed(self, cb: Callable) -> EventSubscription:
"""Register a callback for when a command is executed.
Parameters
----------
cb : Callable
Callback function
Returns
-------
EventSubscription
EventSubscription instance which can be used to unregister the callback
"""
return self.service.add_on_command_executed(
self.rules, convert_path_to_se_path(self.path), self, cb
)


class PyParameter(PyStateContainer):
"""Object class using StateEngine based DatamodelService as backend.
Expand Down
3 changes: 2 additions & 1 deletion src/ansys/fluent/core/services/datamodel_tui.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ def get_static_info(self, path: str):
request = DataModelProtoModule.GetStaticInfoRequest()
request.path = path
response = self._impl.get_static_info(request)
return MessageToDict(response.info, including_default_value_fields=True)
# Note: MessageToDict's parameter names are different in different protobuf versions
return MessageToDict(response.info, True)


class PyMenu:
Expand Down
6 changes: 3 additions & 3 deletions src/ansys/fluent/core/solver/flobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -1165,7 +1165,7 @@ def __getattr__(self, name: str):
except KeyError as ex:
raise AttributeError(
allowed_name_error_message(
context=self._state_cls.__name__,
context=self._state_cls._python_name,
trial_name=name,
allowed_values=self.get_active_child_names(),
)
Expand Down Expand Up @@ -1366,7 +1366,7 @@ def __getitem__(self, name: str) -> ChildTypeT:
)
raise KeyError(
allowed_name_error_message(
context=self.__class__.__name__,
context=self.__class__._python_name,
trial_name=name,
allowed_values=self.get_object_names(),
)
Expand Down Expand Up @@ -1910,7 +1910,7 @@ def __setitem__(self, name: str, value):
else:
raise KeyError(
allowed_name_error_message(
context=self.__class__.__name__,
context=self.__class__._python_name,
trial_name=name,
allowed_values=self.get_object_names(),
)
Expand Down
5 changes: 2 additions & 3 deletions src/ansys/fluent/core/streaming_services/events_streaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,9 +398,8 @@ def _construct_event_info(
self, response: EventsProtoModule.BeginStreamingResponse, event: TEvent
):
event_info_msg = getattr(response, event.value.lower())
event_info_dict = MessageToDict(
event_info_msg, including_default_value_fields=True
)
# Note: MessageToDict's parameter names are different in different protobuf versions
event_info_dict = MessageToDict(event_info_msg, True)
solver_event = SolverEvent(event.value)
event_info_cls = EventInfoBase.derived_classes.get(solver_event)
# Key names can be different, but their order is the same
Expand Down
4 changes: 2 additions & 2 deletions tests/test_datamodel_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ def cb(obj, cmd, args):
executed += 1

# TODO: In C++ API, we don't need to pass the command name
subscription = service.add_on_command_executed(app_name, "/", "C", root, cb)
subscription = service.add_on_command_executed(app_name, "/", root, cb)
assert executed == 0
assert command is None
assert arguments is None
Expand Down Expand Up @@ -437,7 +437,7 @@ def test_datamodel_api_on_bad_input(
app_name, "/", "CC", "isActive", root, lambda _: None
)
with pytest.raises(RuntimeError if new_api else SubscribeEventError): # TODO: issue
service.add_on_command_executed(app_name, "/BB", "C", root, lambda _: None)
service.add_on_command_executed(app_name, "/BB", root, lambda _: None)


@pytest.mark.fluent_version(">=25.2")
Expand Down
40 changes: 30 additions & 10 deletions tests/test_datamodel_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
)
from ansys.fluent.core.streaming_services.datamodel_streaming import DatamodelStream
from ansys.fluent.core.utils.execution import timeout_loop
from ansys.fluent.core.utils.fluent_version import FluentVersion


@pytest.mark.parametrize(
Expand Down Expand Up @@ -55,8 +56,13 @@ def test_event_subscription(new_meshing_session):
"/workflow/affected/TaskObject",
"/workflow/attribute_changed/TaskObject:TaskObject1/TaskList/isActive",
"/workflow/command_attribute_changed/InitializeWorkflow/arguments",
"/workflow/command_executed/InitializeWorkflow",
]
version = session.get_fluent_version()
if version < FluentVersion.v252:
tags.append("/workflow/command_executed/InitializeWorkflow")
else:
# TODO: path should be appended to the tag
tags.append("/workflow/command_executed")
request = datamodel_se_pb2.SubscribeEventsRequest()
e1 = request.eventrequest.add(rules="workflow")
e1.createdEventRequest.parentpath = ""
Expand Down Expand Up @@ -230,9 +236,15 @@ def test_add_on_affected_at_type_path(new_meshing_session):
def test_add_on_command_executed(new_meshing_session):
meshing = new_meshing_session
data = []
subscription = meshing.meshing.add_on_command_executed(
"ImportGeometry", lambda obj, command, args: data.append(True)
)
version = meshing.get_fluent_version()
if version < FluentVersion.v252:
subscription = meshing.meshing.add_on_command_executed_old(
"ImportGeometry", lambda obj, command, args: data.append(True)
)
else:
subscription = meshing.meshing.add_on_command_executed(
lambda obj, command, args: data.append(True)
)
assert data == []
meshing.workflow.InitializeWorkflow(WorkflowType="Watertight Geometry")
import_file_name = examples.download_file(
Expand Down Expand Up @@ -651,16 +663,24 @@ def test_on_command_executed_lifetime(new_solver_session):
root = create_root_using_datamodelgen(solver._se_service, app_name)
root.A["A1"] = {}
data = []
_ = root.A["A1"].add_on_command_executed("C", lambda *args: data.append(1))
root.A["A1"].add_on_command_executed("C", lambda *args: data.append(2))
version = solver.get_fluent_version()
if version < FluentVersion.v252:
_ = root.A["A1"].add_on_command_executed_old("C", lambda *args: data.append(1))
root.A["A1"].add_on_command_executed_old("C", lambda *args: data.append(2))
tags = ["/test/command_executed/A:A1/C", "/test/command_executed/A:A1/C-1"]
else:
_ = root.A["A1"].add_on_command_executed(lambda *args: data.append(1))
root.A["A1"].add_on_command_executed(lambda *args: data.append(2))
# TODO: path should be appended to the tag
tags = ["/test/command_executed", "/test/command_executed-1"]
gc.collect()
assert "/test/command_executed/A:A1/C" in solver._se_service.subscriptions
assert "/test/command_executed/A:A1/C-1" in solver._se_service.subscriptions
for tag in tags:
assert tag in solver._se_service.subscriptions
root.A["A1"].C()
assert timeout_loop(lambda: data == [1, 2], 5)
del root.A["A1"]
assert "/test/command_executed/A:A1/C" not in solver._se_service.subscriptions
assert "/test/command_executed/A:A1/C-1" not in solver._se_service.subscriptions
for tag in tags:
assert tag not in solver._se_service.subscriptions


@pytest.mark.fluent_version(">=24.2")
Expand Down
Loading

0 comments on commit 6869550

Please sign in to comment.