From 7e9b52f313f7a77fdd1843f58f4b1e785c4fa3aa Mon Sep 17 00:00:00 2001 From: Harshal Pohekar Date: Wed, 17 Apr 2024 14:09:23 +0530 Subject: [PATCH 01/15] refactor: launcher code refactoring --- .../core/launcher/container_launcher.py | 7 ++ src/ansys/fluent/core/launcher/launcher.py | 39 +------ .../fluent/core/launcher/pim_launcher.py | 7 ++ .../fluent/core/launcher/pyfluent_enums.py | 107 +++++++++++++----- .../core/launcher/standalone_launcher.py | 16 +++ 5 files changed, 110 insertions(+), 66 deletions(-) diff --git a/src/ansys/fluent/core/launcher/container_launcher.py b/src/ansys/fluent/core/launcher/container_launcher.py index d14a3f06772..fa62a30f8c3 100644 --- a/src/ansys/fluent/core/launcher/container_launcher.py +++ b/src/ansys/fluent/core/launcher/container_launcher.py @@ -18,6 +18,7 @@ from typing import Any, Optional, Union from ansys.fluent.core.fluent_connection import FluentConnection +from ansys.fluent.core.launcher.error_handler import GPUSolverSupportError from ansys.fluent.core.launcher.fluent_container import ( configure_container_dict, start_fluent_container, @@ -30,6 +31,8 @@ FluentMode, FluentWindowsGraphicsDriver, UIMode, + _get_graphics_driver, + _get_mode, ) import ansys.fluent.core.launcher.watchdog as watchdog from ansys.fluent.core.utils.file_transfer_service import RemoteFileTransferStrategy @@ -144,6 +147,10 @@ def __init__( The allocated machines and core counts are queried from the scheduler environment and passed to Fluent. """ + if version == "2d" and gpu: + raise GPUSolverSupportError() + graphics_driver = _get_graphics_driver(graphics_driver) + mode = _get_mode(mode) argvals = locals().copy() del argvals["self"] if argvals["start_timeout"] is None: diff --git a/src/ansys/fluent/core/launcher/launcher.py b/src/ansys/fluent/core/launcher/launcher.py index 4bbab01d481..81bb27f2d31 100644 --- a/src/ansys/fluent/core/launcher/launcher.py +++ b/src/ansys/fluent/core/launcher/launcher.py @@ -7,18 +7,11 @@ import logging import os from typing import Any, Dict, Optional, Union -import warnings from ansys.fluent.core.fluent_connection import FluentConnection from ansys.fluent.core.launcher.container_launcher import DockerLauncher -from ansys.fluent.core.launcher.error_handler import ( - GPUSolverSupportError, - _process_invalid_args, -) -from ansys.fluent.core.launcher.launcher_utils import ( - _confirm_watchdog_start, - is_windows, -) +from ansys.fluent.core.launcher.error_handler import _process_invalid_args +from ansys.fluent.core.launcher.launcher_utils import _confirm_watchdog_start from ansys.fluent.core.launcher.pim_launcher import PIMLauncher from ansys.fluent.core.launcher.pyfluent_enums import ( FluentLinuxGraphicsDriver, @@ -27,7 +20,6 @@ LaunchMode, UIMode, _get_fluent_launch_mode, - _get_mode, _get_running_session_mode, ) from ansys.fluent.core.launcher.server_info import _get_server_info @@ -39,7 +31,6 @@ from ansys.fluent.core.session_solver import Solver from ansys.fluent.core.session_solver_icing import SolverIcing from ansys.fluent.core.utils.fluent_version import FluentVersion -from ansys.fluent.core.warnings import PyFluentDeprecationWarning _THIS_DIR = os.path.dirname(__file__) _OPTIONS_FILE = os.path.join(_THIS_DIR, "fluent_launcher_options.json") @@ -80,6 +71,7 @@ def create_launcher(fluent_launch_mode: LaunchMode = None, **kwargs): env=kwargs["env"], cleanup_on_exit=kwargs["cleanup_on_exit"], start_transcript=kwargs["start_transcript"], + show_gui=kwargs["show_gui"], case_file_name=kwargs["case_file_name"], case_data_file_name=kwargs["case_data_file_name"], lightweight_mode=kwargs["lightweight_mode"], @@ -302,37 +294,12 @@ def launch_fluent( The allocated machines and core counts are queried from the scheduler environment and passed to Fluent. """ - if version == "2d" and gpu: - raise GPUSolverSupportError() - if show_gui is not None: - warnings.warn( - "'show_gui' is deprecated, use 'ui_mode' instead", - PyFluentDeprecationWarning, - ) - if show_gui or os.getenv("PYFLUENT_SHOW_SERVER_GUI") == "1": - ui_mode = UIMode.GUI - del show_gui - if ui_mode is None: - # Not using NO_GUI in windows as it opens a new cmd or - # shows Fluent output in the current cmd if start is not used - ui_mode = UIMode.HIDDEN_GUI if is_windows() else UIMode.NO_GUI - if isinstance(ui_mode, str): - ui_mode = UIMode(ui_mode) - if graphics_driver is None: - graphics_driver = "auto" - graphics_driver = str(graphics_driver) - graphics_driver = ( - FluentWindowsGraphicsDriver(graphics_driver) - if is_windows() - else FluentLinuxGraphicsDriver(graphics_driver) - ) fluent_launch_mode = _get_fluent_launch_mode( start_container=start_container, container_dict=container_dict, scheduler_options=scheduler_options, ) del start_container - mode = _get_mode(mode) argvals = locals().copy() _process_invalid_args(dry_run, fluent_launch_mode, argvals) fluent_launch_mode = argvals.pop("fluent_launch_mode") diff --git a/src/ansys/fluent/core/launcher/pim_launcher.py b/src/ansys/fluent/core/launcher/pim_launcher.py index dbe0d9939d6..d53dde0c893 100644 --- a/src/ansys/fluent/core/launcher/pim_launcher.py +++ b/src/ansys/fluent/core/launcher/pim_launcher.py @@ -18,11 +18,14 @@ from typing import Any, Dict, Optional, Union from ansys.fluent.core.fluent_connection import FluentConnection +from ansys.fluent.core.launcher.error_handler import GPUSolverSupportError from ansys.fluent.core.launcher.pyfluent_enums import ( FluentLinuxGraphicsDriver, FluentMode, FluentWindowsGraphicsDriver, UIMode, + _get_graphics_driver, + _get_mode, ) from ansys.fluent.core.session_meshing import Meshing from ansys.fluent.core.session_pure_meshing import PureMeshing @@ -131,6 +134,10 @@ def __init__( The allocated machines and core counts are queried from the scheduler environment and passed to Fluent. """ + if version == "2d" and gpu: + raise GPUSolverSupportError() + graphics_driver = _get_graphics_driver(graphics_driver) + mode = _get_mode(mode) argvals = locals().copy() del argvals["self"] if argvals["start_timeout"] is None: diff --git a/src/ansys/fluent/core/launcher/pyfluent_enums.py b/src/ansys/fluent/core/launcher/pyfluent_enums.py index c2b0a44f014..f2051525280 100644 --- a/src/ansys/fluent/core/launcher/pyfluent_enums.py +++ b/src/ansys/fluent/core/launcher/pyfluent_enums.py @@ -4,16 +4,18 @@ from functools import total_ordering import os from typing import Optional, Union +import warnings from ansys.fluent.core.exceptions import DisallowedValuesError from ansys.fluent.core.fluent_connection import FluentConnection import ansys.fluent.core.launcher.error_handler as exceptions -from ansys.fluent.core.launcher.launcher_utils import check_docker_support +from ansys.fluent.core.launcher.launcher_utils import check_docker_support, is_windows from ansys.fluent.core.session_meshing import Meshing from ansys.fluent.core.session_pure_meshing import PureMeshing from ansys.fluent.core.session_solver import Solver from ansys.fluent.core.session_solver_icing import SolverIcing from ansys.fluent.core.utils.fluent_version import FluentVersion +from ansys.fluent.core.warnings import PyFluentDeprecationWarning import ansys.platform.instancemanagement as pypim @@ -143,35 +145,6 @@ class FluentLinuxGraphicsDriver(FluentEnum): AUTO = ("",) -def _get_mode(mode: Optional[Union[FluentMode, str, None]] = None): - """Update the session information.""" - if mode is None: - mode = FluentMode.SOLVER - - if isinstance(mode, str): - mode = FluentMode.get_mode(mode) - - return mode - - -def _get_running_session_mode( - fluent_connection: FluentConnection, mode: Optional[FluentMode] = None -): - """Get the mode of the running session if the mode has not been explicitly given.""" - if mode: - session_mode = mode - else: - try: - session_mode = FluentMode.get_mode( - "solver" - if fluent_connection._connection_interface.is_solver_mode() - else "meshing" - ) - except Exception as ex: - raise exceptions.InvalidPassword() from ex - return session_mode.value[0] - - def _get_fluent_launch_mode(start_container, container_dict, scheduler_options): """Get the Fluent launch mode. @@ -204,6 +177,49 @@ def _get_fluent_launch_mode(start_container, container_dict, scheduler_options): return fluent_launch_mode +def _get_graphics_driver( + graphics_driver: Union[FluentWindowsGraphicsDriver, FluentLinuxGraphicsDriver, str] +): + if graphics_driver is None: + graphics_driver = "auto" + graphics_driver = str(graphics_driver) + graphics_driver = ( + FluentWindowsGraphicsDriver(graphics_driver) + if is_windows() + else FluentLinuxGraphicsDriver(graphics_driver) + ) + return graphics_driver + + +def _get_mode(mode: Optional[Union[FluentMode, str, None]] = None): + """Update the session information.""" + if mode is None: + mode = FluentMode.SOLVER + + if isinstance(mode, str): + mode = FluentMode.get_mode(mode) + + return mode + + +def _get_running_session_mode( + fluent_connection: FluentConnection, mode: Optional[FluentMode] = None +): + """Get the mode of the running session if the mode has not been explicitly given.""" + if mode: + session_mode = mode + else: + try: + session_mode = FluentMode.get_mode( + "solver" + if fluent_connection._connection_interface.is_solver_mode() + else "meshing" + ) + except Exception as ex: + raise exceptions.InvalidPassword() from ex + return session_mode.value[0] + + def _get_standalone_launch_fluent_version( product_version: Union[FluentVersion, None] ) -> Optional[FluentVersion]: @@ -233,3 +249,34 @@ def _get_standalone_launch_fluent_version( # 2. the latest ANSYS version from AWP_ROOT environment variables return FluentVersion.get_latest_installed() + + +def _get_ui_mode( + show_gui: Optional[bool] = None, +): + """Get the graphics driver. + + Parameters + ---------- + show_gui: bool + Whether to show Fluent GUI. + + Returns + ------- + ui_mode: UIMode + Fluent GUI mode. + """ + if show_gui is not None: + warnings.warn( + "'show_gui' is deprecated, use 'ui_mode' instead", + PyFluentDeprecationWarning, + ) + if show_gui or os.getenv("PYFLUENT_SHOW_SERVER_GUI") == "1": + ui_mode = UIMode.GUI + if ui_mode is None: + # Not using NO_GUI in windows as it opens a new cmd or + # shows Fluent output in the current cmd if start is not used + ui_mode = UIMode.HIDDEN_GUI if is_windows() else UIMode.NO_GUI + if isinstance(ui_mode, str): + ui_mode = UIMode(ui_mode) + return ui_mode diff --git a/src/ansys/fluent/core/launcher/standalone_launcher.py b/src/ansys/fluent/core/launcher/standalone_launcher.py index 402159199e2..d7ed47b9a4a 100644 --- a/src/ansys/fluent/core/launcher/standalone_launcher.py +++ b/src/ansys/fluent/core/launcher/standalone_launcher.py @@ -20,6 +20,7 @@ from typing import Any, Dict, Optional, Union from ansys.fluent.core.launcher.error_handler import ( + GPUSolverSupportError, LaunchFluentError, _raise_non_gui_exception_in_windows, ) @@ -36,7 +37,10 @@ FluentMode, FluentWindowsGraphicsDriver, UIMode, + _get_graphics_driver, + _get_mode, _get_standalone_launch_fluent_version, + _get_ui_mode, ) from ansys.fluent.core.launcher.server_info import ( _get_server_info, @@ -67,6 +71,7 @@ def __init__( env: Optional[Dict[str, Any]] = None, cleanup_on_exit: bool = True, start_transcript: bool = True, + show_gui: Optional[bool] = None, case_file_name: Optional[str] = None, case_data_file_name: Optional[str] = None, lightweight_mode: Optional[bool] = None, @@ -123,6 +128,11 @@ def __init__( default is ``True``. You can stop and start the streaming of the Fluent transcript subsequently via the method calls, ``transcript.start()`` and ``transcript.stop()`` on the session object. + show_gui : bool, optional + Whether to display the Fluent GUI. The default is ``None``, which does not + cause the GUI to be shown. If a value of ``False`` is + not explicitly provided, the GUI will also be shown if + the environment variable ``PYFLUENT_SHOW_SERVER_GUI`` is set to 1. case_file_name : str, optional If provided, the case file at ``case_file_name`` is read into the Fluent session. case_data_file_name : str, optional @@ -172,6 +182,12 @@ def __init__( The allocated machines and core counts are queried from the scheduler environment and passed to Fluent. """ + if version == "2d" and gpu: + raise GPUSolverSupportError() + graphics_driver = _get_graphics_driver(graphics_driver) + ui_mode = _get_ui_mode(show_gui) + del show_gui + mode = _get_mode(mode) argvals = locals().copy() del argvals["self"] if argvals["start_timeout"] is None: From a90ac4516d231b1d5cf01ccec4765a03488924ec Mon Sep 17 00:00:00 2001 From: Harshal Pohekar Date: Wed, 17 Apr 2024 17:42:06 +0530 Subject: [PATCH 02/15] test fix --- src/ansys/fluent/core/launcher/process_launch_string.py | 4 +++- src/ansys/fluent/core/launcher/pyfluent_enums.py | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/ansys/fluent/core/launcher/process_launch_string.py b/src/ansys/fluent/core/launcher/process_launch_string.py index a2149cb05b2..d7ac973d7c6 100644 --- a/src/ansys/fluent/core/launcher/process_launch_string.py +++ b/src/ansys/fluent/core/launcher/process_launch_string.py @@ -5,7 +5,7 @@ from pathlib import Path from ansys.fluent.core.launcher import launcher_utils -from ansys.fluent.core.launcher.pyfluent_enums import FluentMode +from ansys.fluent.core.launcher.pyfluent_enums import FluentMode, UIMode from ansys.fluent.core.scheduler import build_parallel_options, load_machines from ansys.fluent.core.utils.fluent_version import FluentVersion @@ -66,6 +66,8 @@ def _build_fluent_launch_args_string(**kwargs) -> str: elif isinstance(gpu, list): launch_args_string += f" -gpu={','.join(map(str, gpu))}" ui_mode = kwargs.get("ui_mode") + if isinstance(ui_mode, str): + ui_mode = UIMode(ui_mode) if ui_mode and ui_mode.value[0]: launch_args_string += f" -{ui_mode.value[0]}" graphics_driver = kwargs.get("graphics_driver") diff --git a/src/ansys/fluent/core/launcher/pyfluent_enums.py b/src/ansys/fluent/core/launcher/pyfluent_enums.py index f2051525280..11a5ce67fed 100644 --- a/src/ansys/fluent/core/launcher/pyfluent_enums.py +++ b/src/ansys/fluent/core/launcher/pyfluent_enums.py @@ -266,6 +266,7 @@ def _get_ui_mode( ui_mode: UIMode Fluent GUI mode. """ + ui_mode = None if show_gui is not None: warnings.warn( "'show_gui' is deprecated, use 'ui_mode' instead", From cbcd509a83bc128ed38b7ef59879c4996612d826 Mon Sep 17 00:00:00 2001 From: Harshal Pohekar Date: Wed, 17 Apr 2024 17:54:18 +0530 Subject: [PATCH 03/15] test fix 1 --- tests/test_launcher.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/test_launcher.py b/tests/test_launcher.py index 6b63818ab82..c71b58060dc 100644 --- a/tests/test_launcher.py +++ b/tests/test_launcher.py @@ -401,8 +401,9 @@ def test_build_journal_argument(topy, journal_file_names, result, raises): @pytest.mark.filterwarnings("error::FutureWarning") def test_show_gui_raises_warning(): - with pytest.raises(PyFluentDeprecationWarning): - pyfluent.launch_fluent(show_gui=True) + if not check_docker_support(): + with pytest.raises(PyFluentDeprecationWarning): + pyfluent.launch_fluent(show_gui=True) def test_fluent_enums(): From d061aa8738726d293a469ff87f8e617372996738 Mon Sep 17 00:00:00 2001 From: Harshal Pohekar Date: Wed, 17 Apr 2024 18:02:03 +0530 Subject: [PATCH 04/15] test fix 2 --- tests/test_launcher.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_launcher.py b/tests/test_launcher.py index c71b58060dc..da6f231fca3 100644 --- a/tests/test_launcher.py +++ b/tests/test_launcher.py @@ -401,7 +401,7 @@ def test_build_journal_argument(topy, journal_file_names, result, raises): @pytest.mark.filterwarnings("error::FutureWarning") def test_show_gui_raises_warning(): - if not check_docker_support(): + if not check_docker_support() and not pypim.is_configured(): with pytest.raises(PyFluentDeprecationWarning): pyfluent.launch_fluent(show_gui=True) From db49aff7c2d08b9d63fb40d7ec0118f1ac1204b6 Mon Sep 17 00:00:00 2001 From: Harshal Pohekar <106588300+hpohekar@users.noreply.github.com> Date: Thu, 18 Apr 2024 09:46:42 +0530 Subject: [PATCH 05/15] Update src/ansys/fluent/core/launcher/pyfluent_enums.py Co-authored-by: Kathy Pippert <84872299+PipKat@users.noreply.github.com> --- src/ansys/fluent/core/launcher/pyfluent_enums.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ansys/fluent/core/launcher/pyfluent_enums.py b/src/ansys/fluent/core/launcher/pyfluent_enums.py index 11a5ce67fed..0fa43d1ccdd 100644 --- a/src/ansys/fluent/core/launcher/pyfluent_enums.py +++ b/src/ansys/fluent/core/launcher/pyfluent_enums.py @@ -259,7 +259,7 @@ def _get_ui_mode( Parameters ---------- show_gui: bool - Whether to show Fluent GUI. + Whether to show the Fluent GUI. Returns ------- From 06fa1c5395eeca0f02725abe55f3dd7a301ec159 Mon Sep 17 00:00:00 2001 From: Harshal Pohekar <106588300+hpohekar@users.noreply.github.com> Date: Thu, 18 Apr 2024 09:47:01 +0530 Subject: [PATCH 06/15] Update src/ansys/fluent/core/launcher/standalone_launcher.py Co-authored-by: Kathy Pippert <84872299+PipKat@users.noreply.github.com> --- src/ansys/fluent/core/launcher/standalone_launcher.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/ansys/fluent/core/launcher/standalone_launcher.py b/src/ansys/fluent/core/launcher/standalone_launcher.py index d7ed47b9a4a..812c7837677 100644 --- a/src/ansys/fluent/core/launcher/standalone_launcher.py +++ b/src/ansys/fluent/core/launcher/standalone_launcher.py @@ -129,10 +129,11 @@ def __init__( Fluent transcript subsequently via the method calls, ``transcript.start()`` and ``transcript.stop()`` on the session object. show_gui : bool, optional - Whether to display the Fluent GUI. The default is ``None``, which does not - cause the GUI to be shown. If a value of ``False`` is - not explicitly provided, the GUI will also be shown if - the environment variable ``PYFLUENT_SHOW_SERVER_GUI`` is set to 1. + Whether to display the Fluent GUI. The default is ``None``, + in which case the GUI is not shown. If ``False`` is + not explicitly provided, the GUI will be shown if + the ``PYFLUENT_SHOW_SERVER_GUI`` environment + variable is set to 1. case_file_name : str, optional If provided, the case file at ``case_file_name`` is read into the Fluent session. case_data_file_name : str, optional From ce5c3308339a0c85fbf162f23e1310cc029bf58c Mon Sep 17 00:00:00 2001 From: Harshal Pohekar <106588300+hpohekar@users.noreply.github.com> Date: Thu, 18 Apr 2024 09:47:54 +0530 Subject: [PATCH 07/15] Update src/ansys/fluent/core/launcher/standalone_launcher.py Co-authored-by: Kathy Pippert <84872299+PipKat@users.noreply.github.com> --- src/ansys/fluent/core/launcher/standalone_launcher.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ansys/fluent/core/launcher/standalone_launcher.py b/src/ansys/fluent/core/launcher/standalone_launcher.py index 812c7837677..44691019c0d 100644 --- a/src/ansys/fluent/core/launcher/standalone_launcher.py +++ b/src/ansys/fluent/core/launcher/standalone_launcher.py @@ -135,7 +135,8 @@ def __init__( the ``PYFLUENT_SHOW_SERVER_GUI`` environment variable is set to 1. case_file_name : str, optional - If provided, the case file at ``case_file_name`` is read into the Fluent session. + Name of the case file to read into the + Fluent session. The default is ``None``. case_data_file_name : str, optional If provided, the case and data files at ``case_data_file_name`` are read into the Fluent session. lightweight_mode : bool, optional From d316a781cc3b270a26e4d4ef7d950747460b10df Mon Sep 17 00:00:00 2001 From: Harshal Pohekar Date: Thu, 18 Apr 2024 13:27:25 +0530 Subject: [PATCH 08/15] remove _process_invalid_args --- src/ansys/fluent/core/launcher/launcher.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ansys/fluent/core/launcher/launcher.py b/src/ansys/fluent/core/launcher/launcher.py index 81bb27f2d31..2049331709d 100644 --- a/src/ansys/fluent/core/launcher/launcher.py +++ b/src/ansys/fluent/core/launcher/launcher.py @@ -57,6 +57,7 @@ def create_launcher(fluent_launch_mode: LaunchMode = None, **kwargs): If an unknown Fluent launch mode is passed. """ if fluent_launch_mode == LaunchMode.STANDALONE: + _process_invalid_args(kwargs["dry_run"], fluent_launch_mode, kwargs) return StandaloneLauncher( mode=kwargs["mode"], ui_mode=kwargs["ui_mode"], @@ -83,6 +84,7 @@ def create_launcher(fluent_launch_mode: LaunchMode = None, **kwargs): file_transfer_service=kwargs["file_transfer_service"], ) elif fluent_launch_mode == LaunchMode.CONTAINER: + _process_invalid_args(kwargs["dry_run"], fluent_launch_mode, kwargs) return DockerLauncher( mode=kwargs["mode"], ui_mode=kwargs["ui_mode"], @@ -103,6 +105,7 @@ def create_launcher(fluent_launch_mode: LaunchMode = None, **kwargs): file_transfer_service=kwargs["file_transfer_service"], ) elif fluent_launch_mode == LaunchMode.PIM: + _process_invalid_args(kwargs["dry_run"], fluent_launch_mode, kwargs) return PIMLauncher( mode=kwargs["mode"], ui_mode=kwargs["ui_mode"], @@ -301,7 +304,6 @@ def launch_fluent( ) del start_container argvals = locals().copy() - _process_invalid_args(dry_run, fluent_launch_mode, argvals) fluent_launch_mode = argvals.pop("fluent_launch_mode") launcher = create_launcher(fluent_launch_mode, **argvals) return launcher() From 8d3f183350d18aeafde82f163ec7d17c668d7037 Mon Sep 17 00:00:00 2001 From: Harshal Pohekar Date: Thu, 18 Apr 2024 13:41:42 +0530 Subject: [PATCH 09/15] remove _process_invalid_args 1 --- src/ansys/fluent/core/launcher/launcher.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/ansys/fluent/core/launcher/launcher.py b/src/ansys/fluent/core/launcher/launcher.py index 2049331709d..4249740047c 100644 --- a/src/ansys/fluent/core/launcher/launcher.py +++ b/src/ansys/fluent/core/launcher/launcher.py @@ -56,8 +56,8 @@ def create_launcher(fluent_launch_mode: LaunchMode = None, **kwargs): DisallowedValuesError If an unknown Fluent launch mode is passed. """ + _process_invalid_args(kwargs["dry_run"], fluent_launch_mode, kwargs) if fluent_launch_mode == LaunchMode.STANDALONE: - _process_invalid_args(kwargs["dry_run"], fluent_launch_mode, kwargs) return StandaloneLauncher( mode=kwargs["mode"], ui_mode=kwargs["ui_mode"], @@ -84,7 +84,6 @@ def create_launcher(fluent_launch_mode: LaunchMode = None, **kwargs): file_transfer_service=kwargs["file_transfer_service"], ) elif fluent_launch_mode == LaunchMode.CONTAINER: - _process_invalid_args(kwargs["dry_run"], fluent_launch_mode, kwargs) return DockerLauncher( mode=kwargs["mode"], ui_mode=kwargs["ui_mode"], @@ -105,7 +104,6 @@ def create_launcher(fluent_launch_mode: LaunchMode = None, **kwargs): file_transfer_service=kwargs["file_transfer_service"], ) elif fluent_launch_mode == LaunchMode.PIM: - _process_invalid_args(kwargs["dry_run"], fluent_launch_mode, kwargs) return PIMLauncher( mode=kwargs["mode"], ui_mode=kwargs["ui_mode"], From 6d6e1682d727e6e42a178f8c1e5e3de0d809f58e Mon Sep 17 00:00:00 2001 From: Harshal Pohekar <106588300+hpohekar@users.noreply.github.com> Date: Fri, 19 Apr 2024 07:31:52 +0530 Subject: [PATCH 10/15] Update src/ansys/fluent/core/launcher/standalone_launcher.py Co-authored-by: Kathy Pippert <84872299+PipKat@users.noreply.github.com> --- src/ansys/fluent/core/launcher/standalone_launcher.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ansys/fluent/core/launcher/standalone_launcher.py b/src/ansys/fluent/core/launcher/standalone_launcher.py index 44691019c0d..d8a542d10ce 100644 --- a/src/ansys/fluent/core/launcher/standalone_launcher.py +++ b/src/ansys/fluent/core/launcher/standalone_launcher.py @@ -131,7 +131,7 @@ def __init__( show_gui : bool, optional Whether to display the Fluent GUI. The default is ``None``, in which case the GUI is not shown. If ``False`` is - not explicitly provided, the GUI will be shown if + not explicitly provided, the GUI is shown if the ``PYFLUENT_SHOW_SERVER_GUI`` environment variable is set to 1. case_file_name : str, optional From 6728f63232cfdef7a70eff699286c415e45e6294 Mon Sep 17 00:00:00 2001 From: Harshal Pohekar Date: Fri, 19 Apr 2024 16:24:06 +0530 Subject: [PATCH 11/15] refactoring 1 --- .../fluent/core/launcher/container_launcher.py | 7 ------- src/ansys/fluent/core/launcher/launcher.py | 13 ++++++++++++- src/ansys/fluent/core/launcher/pim_launcher.py | 7 ------- .../fluent/core/launcher/standalone_launcher.py | 7 ------- 4 files changed, 12 insertions(+), 22 deletions(-) diff --git a/src/ansys/fluent/core/launcher/container_launcher.py b/src/ansys/fluent/core/launcher/container_launcher.py index fa62a30f8c3..d14a3f06772 100644 --- a/src/ansys/fluent/core/launcher/container_launcher.py +++ b/src/ansys/fluent/core/launcher/container_launcher.py @@ -18,7 +18,6 @@ from typing import Any, Optional, Union from ansys.fluent.core.fluent_connection import FluentConnection -from ansys.fluent.core.launcher.error_handler import GPUSolverSupportError from ansys.fluent.core.launcher.fluent_container import ( configure_container_dict, start_fluent_container, @@ -31,8 +30,6 @@ FluentMode, FluentWindowsGraphicsDriver, UIMode, - _get_graphics_driver, - _get_mode, ) import ansys.fluent.core.launcher.watchdog as watchdog from ansys.fluent.core.utils.file_transfer_service import RemoteFileTransferStrategy @@ -147,10 +144,6 @@ def __init__( The allocated machines and core counts are queried from the scheduler environment and passed to Fluent. """ - if version == "2d" and gpu: - raise GPUSolverSupportError() - graphics_driver = _get_graphics_driver(graphics_driver) - mode = _get_mode(mode) argvals = locals().copy() del argvals["self"] if argvals["start_timeout"] is None: diff --git a/src/ansys/fluent/core/launcher/launcher.py b/src/ansys/fluent/core/launcher/launcher.py index 4249740047c..bc704d2f2f0 100644 --- a/src/ansys/fluent/core/launcher/launcher.py +++ b/src/ansys/fluent/core/launcher/launcher.py @@ -10,7 +10,10 @@ from ansys.fluent.core.fluent_connection import FluentConnection from ansys.fluent.core.launcher.container_launcher import DockerLauncher -from ansys.fluent.core.launcher.error_handler import _process_invalid_args +from ansys.fluent.core.launcher.error_handler import ( + GPUSolverSupportError, + _process_invalid_args, +) from ansys.fluent.core.launcher.launcher_utils import _confirm_watchdog_start from ansys.fluent.core.launcher.pim_launcher import PIMLauncher from ansys.fluent.core.launcher.pyfluent_enums import ( @@ -20,6 +23,8 @@ LaunchMode, UIMode, _get_fluent_launch_mode, + _get_graphics_driver, + _get_mode, _get_running_session_mode, ) from ansys.fluent.core.launcher.server_info import _get_server_info @@ -57,6 +62,12 @@ def create_launcher(fluent_launch_mode: LaunchMode = None, **kwargs): If an unknown Fluent launch mode is passed. """ _process_invalid_args(kwargs["dry_run"], fluent_launch_mode, kwargs) + if kwargs["version"] == "2d" and kwargs["gpu"]: + raise GPUSolverSupportError() + graphics_driver = _get_graphics_driver(kwargs["graphics_driver"]) + kwargs["graphics_driver"] = graphics_driver + mode = _get_mode(kwargs["mode"]) + kwargs["mode"] = mode if fluent_launch_mode == LaunchMode.STANDALONE: return StandaloneLauncher( mode=kwargs["mode"], diff --git a/src/ansys/fluent/core/launcher/pim_launcher.py b/src/ansys/fluent/core/launcher/pim_launcher.py index d53dde0c893..dbe0d9939d6 100644 --- a/src/ansys/fluent/core/launcher/pim_launcher.py +++ b/src/ansys/fluent/core/launcher/pim_launcher.py @@ -18,14 +18,11 @@ from typing import Any, Dict, Optional, Union from ansys.fluent.core.fluent_connection import FluentConnection -from ansys.fluent.core.launcher.error_handler import GPUSolverSupportError from ansys.fluent.core.launcher.pyfluent_enums import ( FluentLinuxGraphicsDriver, FluentMode, FluentWindowsGraphicsDriver, UIMode, - _get_graphics_driver, - _get_mode, ) from ansys.fluent.core.session_meshing import Meshing from ansys.fluent.core.session_pure_meshing import PureMeshing @@ -134,10 +131,6 @@ def __init__( The allocated machines and core counts are queried from the scheduler environment and passed to Fluent. """ - if version == "2d" and gpu: - raise GPUSolverSupportError() - graphics_driver = _get_graphics_driver(graphics_driver) - mode = _get_mode(mode) argvals = locals().copy() del argvals["self"] if argvals["start_timeout"] is None: diff --git a/src/ansys/fluent/core/launcher/standalone_launcher.py b/src/ansys/fluent/core/launcher/standalone_launcher.py index 44691019c0d..84424000fd6 100644 --- a/src/ansys/fluent/core/launcher/standalone_launcher.py +++ b/src/ansys/fluent/core/launcher/standalone_launcher.py @@ -20,7 +20,6 @@ from typing import Any, Dict, Optional, Union from ansys.fluent.core.launcher.error_handler import ( - GPUSolverSupportError, LaunchFluentError, _raise_non_gui_exception_in_windows, ) @@ -37,8 +36,6 @@ FluentMode, FluentWindowsGraphicsDriver, UIMode, - _get_graphics_driver, - _get_mode, _get_standalone_launch_fluent_version, _get_ui_mode, ) @@ -184,12 +181,8 @@ def __init__( The allocated machines and core counts are queried from the scheduler environment and passed to Fluent. """ - if version == "2d" and gpu: - raise GPUSolverSupportError() - graphics_driver = _get_graphics_driver(graphics_driver) ui_mode = _get_ui_mode(show_gui) del show_gui - mode = _get_mode(mode) argvals = locals().copy() del argvals["self"] if argvals["start_timeout"] is None: From 08dfd153edb6f770eda5e77820181836756245e4 Mon Sep 17 00:00:00 2001 From: Harshal Pohekar Date: Sat, 20 Apr 2024 11:14:59 +0530 Subject: [PATCH 12/15] Revert "refactoring 1" This reverts commit 6728f63232cfdef7a70eff699286c415e45e6294. --- .../fluent/core/launcher/container_launcher.py | 7 +++++++ src/ansys/fluent/core/launcher/launcher.py | 13 +------------ src/ansys/fluent/core/launcher/pim_launcher.py | 7 +++++++ .../fluent/core/launcher/standalone_launcher.py | 7 +++++++ 4 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/ansys/fluent/core/launcher/container_launcher.py b/src/ansys/fluent/core/launcher/container_launcher.py index d14a3f06772..fa62a30f8c3 100644 --- a/src/ansys/fluent/core/launcher/container_launcher.py +++ b/src/ansys/fluent/core/launcher/container_launcher.py @@ -18,6 +18,7 @@ from typing import Any, Optional, Union from ansys.fluent.core.fluent_connection import FluentConnection +from ansys.fluent.core.launcher.error_handler import GPUSolverSupportError from ansys.fluent.core.launcher.fluent_container import ( configure_container_dict, start_fluent_container, @@ -30,6 +31,8 @@ FluentMode, FluentWindowsGraphicsDriver, UIMode, + _get_graphics_driver, + _get_mode, ) import ansys.fluent.core.launcher.watchdog as watchdog from ansys.fluent.core.utils.file_transfer_service import RemoteFileTransferStrategy @@ -144,6 +147,10 @@ def __init__( The allocated machines and core counts are queried from the scheduler environment and passed to Fluent. """ + if version == "2d" and gpu: + raise GPUSolverSupportError() + graphics_driver = _get_graphics_driver(graphics_driver) + mode = _get_mode(mode) argvals = locals().copy() del argvals["self"] if argvals["start_timeout"] is None: diff --git a/src/ansys/fluent/core/launcher/launcher.py b/src/ansys/fluent/core/launcher/launcher.py index bc704d2f2f0..4249740047c 100644 --- a/src/ansys/fluent/core/launcher/launcher.py +++ b/src/ansys/fluent/core/launcher/launcher.py @@ -10,10 +10,7 @@ from ansys.fluent.core.fluent_connection import FluentConnection from ansys.fluent.core.launcher.container_launcher import DockerLauncher -from ansys.fluent.core.launcher.error_handler import ( - GPUSolverSupportError, - _process_invalid_args, -) +from ansys.fluent.core.launcher.error_handler import _process_invalid_args from ansys.fluent.core.launcher.launcher_utils import _confirm_watchdog_start from ansys.fluent.core.launcher.pim_launcher import PIMLauncher from ansys.fluent.core.launcher.pyfluent_enums import ( @@ -23,8 +20,6 @@ LaunchMode, UIMode, _get_fluent_launch_mode, - _get_graphics_driver, - _get_mode, _get_running_session_mode, ) from ansys.fluent.core.launcher.server_info import _get_server_info @@ -62,12 +57,6 @@ def create_launcher(fluent_launch_mode: LaunchMode = None, **kwargs): If an unknown Fluent launch mode is passed. """ _process_invalid_args(kwargs["dry_run"], fluent_launch_mode, kwargs) - if kwargs["version"] == "2d" and kwargs["gpu"]: - raise GPUSolverSupportError() - graphics_driver = _get_graphics_driver(kwargs["graphics_driver"]) - kwargs["graphics_driver"] = graphics_driver - mode = _get_mode(kwargs["mode"]) - kwargs["mode"] = mode if fluent_launch_mode == LaunchMode.STANDALONE: return StandaloneLauncher( mode=kwargs["mode"], diff --git a/src/ansys/fluent/core/launcher/pim_launcher.py b/src/ansys/fluent/core/launcher/pim_launcher.py index dbe0d9939d6..d53dde0c893 100644 --- a/src/ansys/fluent/core/launcher/pim_launcher.py +++ b/src/ansys/fluent/core/launcher/pim_launcher.py @@ -18,11 +18,14 @@ from typing import Any, Dict, Optional, Union from ansys.fluent.core.fluent_connection import FluentConnection +from ansys.fluent.core.launcher.error_handler import GPUSolverSupportError from ansys.fluent.core.launcher.pyfluent_enums import ( FluentLinuxGraphicsDriver, FluentMode, FluentWindowsGraphicsDriver, UIMode, + _get_graphics_driver, + _get_mode, ) from ansys.fluent.core.session_meshing import Meshing from ansys.fluent.core.session_pure_meshing import PureMeshing @@ -131,6 +134,10 @@ def __init__( The allocated machines and core counts are queried from the scheduler environment and passed to Fluent. """ + if version == "2d" and gpu: + raise GPUSolverSupportError() + graphics_driver = _get_graphics_driver(graphics_driver) + mode = _get_mode(mode) argvals = locals().copy() del argvals["self"] if argvals["start_timeout"] is None: diff --git a/src/ansys/fluent/core/launcher/standalone_launcher.py b/src/ansys/fluent/core/launcher/standalone_launcher.py index a002988229f..d8a542d10ce 100644 --- a/src/ansys/fluent/core/launcher/standalone_launcher.py +++ b/src/ansys/fluent/core/launcher/standalone_launcher.py @@ -20,6 +20,7 @@ from typing import Any, Dict, Optional, Union from ansys.fluent.core.launcher.error_handler import ( + GPUSolverSupportError, LaunchFluentError, _raise_non_gui_exception_in_windows, ) @@ -36,6 +37,8 @@ FluentMode, FluentWindowsGraphicsDriver, UIMode, + _get_graphics_driver, + _get_mode, _get_standalone_launch_fluent_version, _get_ui_mode, ) @@ -181,8 +184,12 @@ def __init__( The allocated machines and core counts are queried from the scheduler environment and passed to Fluent. """ + if version == "2d" and gpu: + raise GPUSolverSupportError() + graphics_driver = _get_graphics_driver(graphics_driver) ui_mode = _get_ui_mode(show_gui) del show_gui + mode = _get_mode(mode) argvals = locals().copy() del argvals["self"] if argvals["start_timeout"] is None: From b4dd6752605083dd214819182542e3bdb39db386 Mon Sep 17 00:00:00 2001 From: Harshal Pohekar Date: Sat, 20 Apr 2024 11:27:13 +0530 Subject: [PATCH 13/15] use _validate_gpu --- .../fluent/core/launcher/container_launcher.py | 5 ++--- src/ansys/fluent/core/launcher/pim_launcher.py | 5 ++--- src/ansys/fluent/core/launcher/pyfluent_enums.py | 14 ++++++++++++++ .../fluent/core/launcher/standalone_launcher.py | 5 ++--- 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/ansys/fluent/core/launcher/container_launcher.py b/src/ansys/fluent/core/launcher/container_launcher.py index fa62a30f8c3..cb52d2325d4 100644 --- a/src/ansys/fluent/core/launcher/container_launcher.py +++ b/src/ansys/fluent/core/launcher/container_launcher.py @@ -18,7 +18,6 @@ from typing import Any, Optional, Union from ansys.fluent.core.fluent_connection import FluentConnection -from ansys.fluent.core.launcher.error_handler import GPUSolverSupportError from ansys.fluent.core.launcher.fluent_container import ( configure_container_dict, start_fluent_container, @@ -33,6 +32,7 @@ UIMode, _get_graphics_driver, _get_mode, + _validate_gpu, ) import ansys.fluent.core.launcher.watchdog as watchdog from ansys.fluent.core.utils.file_transfer_service import RemoteFileTransferStrategy @@ -147,8 +147,7 @@ def __init__( The allocated machines and core counts are queried from the scheduler environment and passed to Fluent. """ - if version == "2d" and gpu: - raise GPUSolverSupportError() + _validate_gpu(gpu, version) graphics_driver = _get_graphics_driver(graphics_driver) mode = _get_mode(mode) argvals = locals().copy() diff --git a/src/ansys/fluent/core/launcher/pim_launcher.py b/src/ansys/fluent/core/launcher/pim_launcher.py index d53dde0c893..4e53e92a676 100644 --- a/src/ansys/fluent/core/launcher/pim_launcher.py +++ b/src/ansys/fluent/core/launcher/pim_launcher.py @@ -18,7 +18,6 @@ from typing import Any, Dict, Optional, Union from ansys.fluent.core.fluent_connection import FluentConnection -from ansys.fluent.core.launcher.error_handler import GPUSolverSupportError from ansys.fluent.core.launcher.pyfluent_enums import ( FluentLinuxGraphicsDriver, FluentMode, @@ -26,6 +25,7 @@ UIMode, _get_graphics_driver, _get_mode, + _validate_gpu, ) from ansys.fluent.core.session_meshing import Meshing from ansys.fluent.core.session_pure_meshing import PureMeshing @@ -134,8 +134,7 @@ def __init__( The allocated machines and core counts are queried from the scheduler environment and passed to Fluent. """ - if version == "2d" and gpu: - raise GPUSolverSupportError() + _validate_gpu(gpu, version) graphics_driver = _get_graphics_driver(graphics_driver) mode = _get_mode(mode) argvals = locals().copy() diff --git a/src/ansys/fluent/core/launcher/pyfluent_enums.py b/src/ansys/fluent/core/launcher/pyfluent_enums.py index 0fa43d1ccdd..a5f1e65c46d 100644 --- a/src/ansys/fluent/core/launcher/pyfluent_enums.py +++ b/src/ansys/fluent/core/launcher/pyfluent_enums.py @@ -281,3 +281,17 @@ def _get_ui_mode( if isinstance(ui_mode, str): ui_mode = UIMode(ui_mode) return ui_mode + + +def _validate_gpu(gpu: Union[bool, list], version: str): + """Raise an exception if the GPU Solver is unsupported. + + Parameters + ---------- + gpu : bool or list, optional + This option will start Fluent with the GPU Solver. + version : str, optional + Geometric dimensionality of the Fluent simulation. + """ + if version == "2d" and gpu: + raise exceptions.GPUSolverSupportError() diff --git a/src/ansys/fluent/core/launcher/standalone_launcher.py b/src/ansys/fluent/core/launcher/standalone_launcher.py index d8a542d10ce..ffb04ae9e28 100644 --- a/src/ansys/fluent/core/launcher/standalone_launcher.py +++ b/src/ansys/fluent/core/launcher/standalone_launcher.py @@ -20,7 +20,6 @@ from typing import Any, Dict, Optional, Union from ansys.fluent.core.launcher.error_handler import ( - GPUSolverSupportError, LaunchFluentError, _raise_non_gui_exception_in_windows, ) @@ -41,6 +40,7 @@ _get_mode, _get_standalone_launch_fluent_version, _get_ui_mode, + _validate_gpu, ) from ansys.fluent.core.launcher.server_info import ( _get_server_info, @@ -184,8 +184,7 @@ def __init__( The allocated machines and core counts are queried from the scheduler environment and passed to Fluent. """ - if version == "2d" and gpu: - raise GPUSolverSupportError() + _validate_gpu(gpu, version) graphics_driver = _get_graphics_driver(graphics_driver) ui_mode = _get_ui_mode(show_gui) del show_gui From 6e14f27c907fe36ac8923bab181054b3c2fe6cd2 Mon Sep 17 00:00:00 2001 From: Harshal Pohekar <106588300+hpohekar@users.noreply.github.com> Date: Sat, 20 Apr 2024 11:29:19 +0530 Subject: [PATCH 14/15] Update src/ansys/fluent/core/launcher/pyfluent_enums.py Co-authored-by: Kathy Pippert <84872299+PipKat@users.noreply.github.com> --- src/ansys/fluent/core/launcher/pyfluent_enums.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ansys/fluent/core/launcher/pyfluent_enums.py b/src/ansys/fluent/core/launcher/pyfluent_enums.py index a5f1e65c46d..19442ea6834 100644 --- a/src/ansys/fluent/core/launcher/pyfluent_enums.py +++ b/src/ansys/fluent/core/launcher/pyfluent_enums.py @@ -269,7 +269,7 @@ def _get_ui_mode( ui_mode = None if show_gui is not None: warnings.warn( - "'show_gui' is deprecated, use 'ui_mode' instead", + "'show_gui' is deprecated. Use 'ui_mode' instead.", PyFluentDeprecationWarning, ) if show_gui or os.getenv("PYFLUENT_SHOW_SERVER_GUI") == "1": From 5fa31bf89a5c086ea8a3dfe18292d97795da3cd0 Mon Sep 17 00:00:00 2001 From: Harshal Pohekar <106588300+hpohekar@users.noreply.github.com> Date: Sat, 20 Apr 2024 11:29:30 +0530 Subject: [PATCH 15/15] Update src/ansys/fluent/core/launcher/standalone_launcher.py Co-authored-by: Kathy Pippert <84872299+PipKat@users.noreply.github.com> --- src/ansys/fluent/core/launcher/standalone_launcher.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ansys/fluent/core/launcher/standalone_launcher.py b/src/ansys/fluent/core/launcher/standalone_launcher.py index ffb04ae9e28..79d040d9f04 100644 --- a/src/ansys/fluent/core/launcher/standalone_launcher.py +++ b/src/ansys/fluent/core/launcher/standalone_launcher.py @@ -138,7 +138,7 @@ def __init__( Name of the case file to read into the Fluent session. The default is ``None``. case_data_file_name : str, optional - If provided, the case and data files at ``case_data_file_name`` are read into the Fluent session. + Name of the case data file. If names of both a case file and case data file are provided, they are read into the Fluent session. lightweight_mode : bool, optional Whether to run in lightweight mode. In lightweight mode, the lightweight settings are read into the current Fluent solver session. The mesh is read into a background Fluent solver session which will