Skip to content

Commit 0876455

Browse files
fix: Update get_si_unit_for_fluent_quantity and from_container (#4573)
--- ## Context Before this change, certain utility functions in PyFluent — specifically `get_si_unit_for_fluent_quantity` (in `flunits.py`) and `from_container` (in `session_utilities.py`) — had issues handling units or container-based settings correctly. For example, `get_si_unit_for_fluent_quantity` needed better handling when the input `quantity` was `None`, a list, or an empty string. Also, `from_container` had parameters or logic that required adjustment for container-mode launches and file-transfer workflows. The existing behavior could lead to unexpected results when working with quantity units or launching sessions with containers. --- ## Change Summary The PR makes the following changes: * In `flunits.py`, the `get_si_unit_for_fluent_quantity` function has been updated to improve handling of various cases: when `quantity` is `None`, when it's a list (especially an empty list), when it is not a string, or when it is a string but empty. * In `session_utilities.py`, the `from_container` function signature and/or its default parameters were adjusted (added parameters like `gpu: bool | None = None`, `file_transfer_service: Any | None = None`, `use_podman_compose: bool | None = None`). This expands the function’s ability to launch Fluent in container mode with more flexibility. * A changelog entry (`doc/changelog.d/4573.fixed.md`) was added summarizing “Update get_si_unit_for_fluent_quantity and from_container”. * Some tests were modified (in `tests/test_flobject.py`) to reflect updated behavior or remove outdated assertions. --- ## Rationale * The `get_si_unit_for_fluent_quantity` change ensures that unit handling is robust and predictable even for edge cases: lists, `None`, empty strings. Since PyFluent integrates with the `ansys-units` library and supports quantity objects, it is important that units are determined correctly. * The `from_container` changes are motivated by the need to better support containerised workflows of Fluent (e.g., using Docker or Podman) and enabling file transfer services for these sessions. Having additional parameters gives users more control (GPU usage, whether to use Docker Compose or Podman Compose, file transfer service) in launching Fluent via Python. * Overall, the changes aim to reduce brittleness in unit-handling and broaden the support of containerised execution scenarios, improving reliability and usability of PyFluent in advanced workflows. --- ## Impact * The functions `get_si_unit_for_fluent_quantity` and `from_container` are internal utilities used by the PyFluent core library (`ansys.fluent.core`). Workflows that involve retrieving or interpreting units of Fluent quantities will benefit (or may require slight adjustments if they relied on previous behavior). * Session launch workflows, especially those using container mode (Docker or Podman) or using custom file-transfer services, will see enhanced capabilities and possibly changed interfaces (because `from_container` now has more parameters/defaults). * Test and code-quality improvements: since the tests were adjusted, developers extending or modifying PyFluent should see fewer false positives/failures around unit and container-session utilities. * Downstream code that introspects or depends on unit strings (via `units()` or `as_quantity()` on settings objects) may need to consider the changed handling of lists/None/empty strings in `get_si_unit_for_fluent_quantity`. * Because these are utility changes rather than front-end user APIs, the impact on everyday usage of PyFluent (e.g., reading cases, solving) may be small for many users. But for advanced users leveraging units or container workflows, the improvements should lead to more predictable behavior. --- --------- Co-authored-by: pyansys-ci-bot <[email protected]>
1 parent f8083f6 commit 0876455

File tree

4 files changed

+9
-3
lines changed

4 files changed

+9
-3
lines changed

doc/changelog.d/4573.fixed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Update get_si_unit_for_fluent_quantity and from_container

src/ansys/fluent/core/session_utilities.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,8 @@ def from_container(
190190
gpu: bool | None = None,
191191
start_watchdog: bool | None = None,
192192
file_transfer_service: Any | None = None,
193+
use_docker_compose: bool | None = None,
194+
use_podman_compose: bool | None = None,
193195
):
194196
"""
195197
Launch a Fluent session in container mode.
@@ -242,6 +244,10 @@ def from_container(
242244
GUI-less Fluent sessions started by PyFluent are properly closed when the current Python process ends.
243245
file_transfer_service : Any, optional
244246
Service for uploading/downloading files to/from the server.
247+
use_docker_compose: bool
248+
Whether to use Docker Compose to launch Fluent.
249+
use_podman_compose: bool
250+
Whether to use Podman Compose to launch Fluent.
245251
246252
Returns
247253
-------

src/ansys/fluent/core/solver/flunits.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,9 +296,9 @@ def get_si_unit_for_fluent_quantity(
296296
"""
297297
# The settings API should return None for the units-quantity
298298
# attribute only for dimensionless variables
299-
if quantity is None:
299+
if not quantity:
300300
return ""
301-
if isinstance(quantity, list): # real vector
301+
if isinstance(quantity, list):
302302
quantity = quantity[0]
303303
if not isinstance(quantity, str):
304304
raise InvalidQuantityType(quantity)

tests/test_flobject.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1033,7 +1033,6 @@ def _check_vector_units(obj, units):
10331033
assert obj.as_quantity() == ansys.units.Quantity(obj.get_state(), units)
10341034

10351035

1036-
@pytest.mark.skip("https://github.com/ansys/pyfluent/issues/4498")
10371036
@pytest.mark.fluent_version(">=24.1")
10381037
def test_ansys_units_integration(mixing_elbow_settings_session):
10391038
solver = mixing_elbow_settings_session

0 commit comments

Comments
 (0)