From ff26078cbd620483f50b2b412d4c0b032f3c2497 Mon Sep 17 00:00:00 2001 From: hpohekar Date: Fri, 26 Sep 2025 22:10:49 +0530 Subject: [PATCH 1/7] fix: Ansys Lab authentication --- .../fluent/core/launcher/pim_launcher.py | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/ansys/fluent/core/launcher/pim_launcher.py b/src/ansys/fluent/core/launcher/pim_launcher.py index dd3788d7a7c4..3740fdc23ec9 100644 --- a/src/ansys/fluent/core/launcher/pim_launcher.py +++ b/src/ansys/fluent/core/launcher/pim_launcher.py @@ -38,7 +38,9 @@ import inspect import logging import os +import time from typing import Any, Dict +import uuid from ansys.fluent.core.fluent_connection import FluentConnection, _get_max_c_int_limit from ansys.fluent.core.launcher.launch_options import ( @@ -50,6 +52,7 @@ UIMode, _get_argvals_and_session, ) +from ansys.fluent.core.session import _parse_server_info_file 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 @@ -245,6 +248,16 @@ def launch_remote_fluent( instance.wait_for_ready() + file_service = PimFileTransferService(pim_instance=instance) + + local_sifile = f"sifile_{uuid.uuid4().hex}" + + file_service.download_file("sifile.txt", os.path.join(os.getcwd(), local_sifile)) + + time.sleep(10) + + ip, port, password = _parse_server_info_file(f"{local_sifile}/sifile.txt") + channel = instance.build_grpc_channel( options=[ ("grpc.max_send_message_length", _get_max_c_int_limit()), @@ -253,6 +266,9 @@ def launch_remote_fluent( ) fluent_connection = create_fluent_connection( + ip=ip, + port=port, + password=password, channel=channel, cleanup_on_exit=cleanup_on_exit, instance=instance, @@ -288,11 +304,20 @@ def create_fluent_instance( def create_fluent_connection( - channel, cleanup_on_exit: bool, instance, launcher_args: Dict[str, Any] | None + ip: str, + port: int, + password: str, + channel, + cleanup_on_exit: bool, + instance, + launcher_args: Dict[str, Any] | None, ): """Create a Fluent connection.""" return FluentConnection( + ip=ip, + port=port, + password=password, channel=channel, cleanup_on_exit=cleanup_on_exit, remote_instance=instance, From cd95808a08a2825321bfb22c2b685f4f164f2c23 Mon Sep 17 00:00:00 2001 From: pyansys-ci-bot <92810346+pyansys-ci-bot@users.noreply.github.com> Date: Fri, 26 Sep 2025 16:45:23 +0000 Subject: [PATCH 2/7] chore: adding changelog file 4503.fixed.md [dependabot-skip] --- doc/changelog.d/4503.fixed.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 doc/changelog.d/4503.fixed.md diff --git a/doc/changelog.d/4503.fixed.md b/doc/changelog.d/4503.fixed.md new file mode 100644 index 000000000000..2223b10105d6 --- /dev/null +++ b/doc/changelog.d/4503.fixed.md @@ -0,0 +1 @@ +Ansys Lab authentication From 761cf6cfeff54af5d62e8a6aa6cc23199d65bfe8 Mon Sep 17 00:00:00 2001 From: Harshal Pohekar <106588300+hpohekar@users.noreply.github.com> Date: Mon, 29 Sep 2025 13:32:39 +0530 Subject: [PATCH 3/7] Update src/ansys/fluent/core/launcher/pim_launcher.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Jérôme Blanche <90267895+jerome-blanche@users.noreply.github.com> --- src/ansys/fluent/core/launcher/pim_launcher.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ansys/fluent/core/launcher/pim_launcher.py b/src/ansys/fluent/core/launcher/pim_launcher.py index 3740fdc23ec9..224ab461aee1 100644 --- a/src/ansys/fluent/core/launcher/pim_launcher.py +++ b/src/ansys/fluent/core/launcher/pim_launcher.py @@ -250,13 +250,13 @@ def launch_remote_fluent( file_service = PimFileTransferService(pim_instance=instance) - local_sifile = f"sifile_{uuid.uuid4().hex}" + local_directory = os.path.join(os.getcwd(), f"sifile_{uuid.uuid4().hex}") - file_service.download_file("sifile.txt", os.path.join(os.getcwd(), local_sifile)) + file_service.download_file("sifile.txt", local_directory) time.sleep(10) - ip, port, password = _parse_server_info_file(f"{local_sifile}/sifile.txt") + ip, port, password = _parse_server_info_file(os.path.join(local_directory, "sifile.txt")) channel = instance.build_grpc_channel( options=[ From b80fc98260e61b3504d3aab242ad84e73b2059db Mon Sep 17 00:00:00 2001 From: hpohekar Date: Mon, 29 Sep 2025 13:40:15 +0530 Subject: [PATCH 4/7] remove hard coded sleep --- .../fluent/core/launcher/pim_launcher.py | 27 +++++++++++++++---- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/src/ansys/fluent/core/launcher/pim_launcher.py b/src/ansys/fluent/core/launcher/pim_launcher.py index 224ab461aee1..33ff3173aaf4 100644 --- a/src/ansys/fluent/core/launcher/pim_launcher.py +++ b/src/ansys/fluent/core/launcher/pim_launcher.py @@ -235,6 +235,11 @@ def launch_remote_fluent( ------- Meshing | PureMeshing | Solver | SolverIcing Session object. + + Raises + ------ + TimeoutError + If unable to download the server info file after multiple retries. """ pim = pypim.connect() @@ -252,11 +257,23 @@ def launch_remote_fluent( local_directory = os.path.join(os.getcwd(), f"sifile_{uuid.uuid4().hex}") - file_service.download_file("sifile.txt", local_directory) - - time.sleep(10) - - ip, port, password = _parse_server_info_file(os.path.join(local_directory, "sifile.txt")) + max_retries = 20 + wait_time_between_retries = 1 # seconds + + for i in range(max_retries): + try: + file_service.download_file("sifile.txt", local_directory) + break + except Exception as ex: + if i == max_retries - 1: + raise TimeoutError( + "Failed to download file after multiple retries." + ) from ex + time.sleep(wait_time_between_retries) + + ip, port, password = _parse_server_info_file( + os.path.join(local_directory, "sifile.txt") + ) channel = instance.build_grpc_channel( options=[ From 8934ede06460a85a59307de41241a0ce402ebb80 Mon Sep 17 00:00:00 2001 From: hpohekar Date: Mon, 29 Sep 2025 14:03:04 +0530 Subject: [PATCH 5/7] remove sifile directory --- src/ansys/fluent/core/launcher/pim_launcher.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/ansys/fluent/core/launcher/pim_launcher.py b/src/ansys/fluent/core/launcher/pim_launcher.py index 33ff3173aaf4..106880938928 100644 --- a/src/ansys/fluent/core/launcher/pim_launcher.py +++ b/src/ansys/fluent/core/launcher/pim_launcher.py @@ -38,6 +38,7 @@ import inspect import logging import os +import shutil import time from typing import Any, Dict import uuid @@ -275,6 +276,8 @@ def launch_remote_fluent( os.path.join(local_directory, "sifile.txt") ) + shutil.rmtree(local_directory) + channel = instance.build_grpc_channel( options=[ ("grpc.max_send_message_length", _get_max_c_int_limit()), From f43b0bd4a2b2166d1f59fb7ef9ce41e316068e9d Mon Sep 17 00:00:00 2001 From: hpohekar Date: Tue, 30 Sep 2025 15:57:57 +0530 Subject: [PATCH 6/7] Create a function --- .../fluent/core/launcher/pim_launcher.py | 75 +++++++++++++------ 1 file changed, 51 insertions(+), 24 deletions(-) diff --git a/src/ansys/fluent/core/launcher/pim_launcher.py b/src/ansys/fluent/core/launcher/pim_launcher.py index 106880938928..867582ba8ce6 100644 --- a/src/ansys/fluent/core/launcher/pim_launcher.py +++ b/src/ansys/fluent/core/launcher/pim_launcher.py @@ -38,10 +38,9 @@ import inspect import logging import os -import shutil +import tempfile import time from typing import Any, Dict -import uuid from ansys.fluent.core.fluent_connection import FluentConnection, _get_max_c_int_limit from ansys.fluent.core.launcher.launch_options import ( @@ -197,6 +196,54 @@ def __call__(self): ) +def get_ip_port_password( + file_service, + filename="sifile.txt", + max_retries=20, + wait_time_between_retries=1, # seconds +): + """ + Downloads the file with retries and parses server info. + + Parameters + ---------- + file_service: PimFileTransferService + Service object with method download_file(filename, target_dir). + filename: str + Name of the file to download. + max_retries: int + Maximum number of attempts. + wait_time_between_retries: int + Seconds to wait between retries. + + Returns + ------- + Tuple (ip, port, password) parsed from the downloaded file. + + Raises + ------ + TimeoutError + If unable to download the server info file after multiple retries. + """ + with tempfile.TemporaryDirectory(prefix="fluent_sifile_") as tmpdir: + for attempt in range(1, max_retries + 1): + try: + file_service.download_file(filename, tmpdir) + break + except Exception as ex: + logger.warning( + f"Attempt {attempt} of {max_retries} failed to download {filename}: {ex}" + ) + if attempt == max_retries: + raise TimeoutError( + f"Failed to download file '{filename}' after {max_retries} attempts " + f"with {wait_time_between_retries}s between retries." + ) from ex + time.sleep(wait_time_between_retries) + + return _parse_server_info_file(os.path.join(tmpdir, filename)) + + def launch_remote_fluent( session_cls, start_transcript: bool, @@ -254,30 +301,10 @@ def launch_remote_fluent( instance.wait_for_ready() - file_service = PimFileTransferService(pim_instance=instance) - - local_directory = os.path.join(os.getcwd(), f"sifile_{uuid.uuid4().hex}") - - max_retries = 20 - wait_time_between_retries = 1 # seconds - - for i in range(max_retries): - try: - file_service.download_file("sifile.txt", local_directory) - break - except Exception as ex: - if i == max_retries - 1: - raise TimeoutError( - "Failed to download file after multiple retries." - ) from ex - time.sleep(wait_time_between_retries) - - ip, port, password = _parse_server_info_file( - os.path.join(local_directory, "sifile.txt") + ip, port, password = get_ip_port_password( + file_service=PimFileTransferService(pim_instance=instance) ) - shutil.rmtree(local_directory) - channel = instance.build_grpc_channel( options=[ ("grpc.max_send_message_length", _get_max_c_int_limit()), From 624cd33f326e72dbf341304f58f6b2acea2faffe Mon Sep 17 00:00:00 2001 From: Harshal Pohekar <106588300+hpohekar@users.noreply.github.com> Date: Wed, 8 Oct 2025 08:35:14 +0530 Subject: [PATCH 7/7] Update src/ansys/fluent/core/launcher/pim_launcher.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/ansys/fluent/core/launcher/pim_launcher.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ansys/fluent/core/launcher/pim_launcher.py b/src/ansys/fluent/core/launcher/pim_launcher.py index 867582ba8ce6..47765c3363a6 100644 --- a/src/ansys/fluent/core/launcher/pim_launcher.py +++ b/src/ansys/fluent/core/launcher/pim_launcher.py @@ -213,8 +213,8 @@ def get_ip_port_password( Name of the file to download. max_retries: int Maximum number of attempts. - wait_time_between_retries: int - Seconds to wait between retries. + wait_time_between_retries: float + Seconds to wait between retries (can be fractional, e.g., 0.5 for half a second). Returns -------