From de6813f0e27f6b5453f1ae149a0f9c9a9677d713 Mon Sep 17 00:00:00 2001 From: German <28149841+germa89@users.noreply.github.com> Date: Wed, 30 Oct 2024 18:59:59 +0100 Subject: [PATCH] feat: using version instead of exec_path for the MPI checks (#3528) feat: using version instead of exec_path for the MPI checks. Fixing tests. --- doc/changelog.d/3528.miscellaneous.md | 1 + src/ansys/mapdl/core/launcher.py | 34 ++++++++++++--------------- tests/test_launcher.py | 13 +++++----- 3 files changed, 23 insertions(+), 25 deletions(-) create mode 100644 doc/changelog.d/3528.miscellaneous.md diff --git a/doc/changelog.d/3528.miscellaneous.md b/doc/changelog.d/3528.miscellaneous.md new file mode 100644 index 0000000000..12e026ea29 --- /dev/null +++ b/doc/changelog.d/3528.miscellaneous.md @@ -0,0 +1 @@ +feat: using version instead of exec_path for the MPI checks \ No newline at end of file diff --git a/src/ansys/mapdl/core/launcher.py b/src/ansys/mapdl/core/launcher.py index ae36861c3a..7ef1800363 100644 --- a/src/ansys/mapdl/core/launcher.py +++ b/src/ansys/mapdl/core/launcher.py @@ -393,7 +393,7 @@ def generate_mapdl_launch_command( # Windows will spawn a new window, special treatment if os.name == "nt": - exec_file = f'"{exec_file}"' + exec_file = f"{exec_file}" # must start in batch mode on windows to hide APDL window tmp_inp = ".__tmp__.inp" command_parm = [ @@ -888,7 +888,7 @@ def check_lock_file(path, jobname, override): def set_MPI_additional_switches( - add_sw: str, exec_path: str, force_intel: bool = False + add_sw: str, force_intel: bool = False, version: Optional[int] = None ) -> str: """Validate MPI configuration. @@ -899,10 +899,10 @@ def set_MPI_additional_switches( ---------- add_sw : str Additional switches. - exec_path : str - Path to the MAPDL executable. force_intel : bool, optional Force the usage of intelmpi. The default is :class:`False`. + version: int, optional + MAPDL version as integer Returns ------- @@ -915,21 +915,17 @@ def set_MPI_additional_switches( # known issues with distributed memory parallel (DMP) if "smp" not in add_sw_lower_case: # pragma: no cover - if _HAS_ATP: - condition = ( - os.name == "nt" - and not force_intel - and (222 > version_from_path("mapdl", exec_path) >= 210) - ) + if _HAS_ATP and os.name == "nt": + condition = not force_intel and version and (222 > version >= 210) else: - if os.name == "nt": - warnings.warn( - "Because 'ansys-tools-path' is not installed, PyMAPDL cannot check\n" - "if this Ansys version requires the MPI fix, so if you are on Windows,\n" - "the fix is applied by default.\n" - "Use 'force_intel=True' to not apply the fix." - ) - condition = os.name == "nt" and not force_intel + warnings.warn( + "Because 'ansys-tools-path' is not installed, PyMAPDL cannot check\n" + "if this Ansys version requires the MPI fix, so if you are on Windows,\n" + "the fix is applied by default.\n" + "Use 'force_intel=True' to not apply the fix." + ) + + condition = not force_intel if condition: # Workaround to fix a problem when launching ansys in 'dmp' mode in the @@ -1465,8 +1461,8 @@ def launch_mapdl( # Set compatible MPI args["additional_switches"] = set_MPI_additional_switches( args["additional_switches"], - args["exec_file"], force_intel=args["force_intel"], + version=args["version"], ) LOG.debug(f"Using additional switches {args['additional_switches']}.") diff --git a/tests/test_launcher.py b/tests/test_launcher.py index ea86036cf8..f530ba0a8c 100644 --- a/tests/test_launcher.py +++ b/tests/test_launcher.py @@ -152,14 +152,14 @@ def fake_local_mapdl(mapdl): def test_validate_sw(): # ensure that windows adds msmpi # fake windows path - exec_path = "C:/Program Files/ANSYS Inc/v211/ansys/bin/win64/ANSYS211.exe" - add_sw = set_MPI_additional_switches("", exec_path) + version = 211 + add_sw = set_MPI_additional_switches("", version=version) assert "msmpi" in add_sw - add_sw = set_MPI_additional_switches("-mpi intelmpi", exec_path) + add_sw = set_MPI_additional_switches("-mpi intelmpi", version=version) assert "msmpi" in add_sw and "intelmpi" not in add_sw - add_sw = set_MPI_additional_switches("-mpi INTELMPI", exec_path) + add_sw = set_MPI_additional_switches("-mpi INTELMPI", version=version) assert "msmpi" in add_sw and "INTELMPI" not in add_sw @@ -949,7 +949,7 @@ def test_generate_mapdl_launch_command_windows(): assert isinstance(cmd, list) - assert f'"{exec_file}"' in cmd + assert f"{exec_file}" in cmd assert "-j" in cmd assert f"{jobname}" in cmd assert "-port" in cmd @@ -967,7 +967,7 @@ def test_generate_mapdl_launch_command_windows(): assert ".__tmp__.out" in cmd cmd = " ".join(cmd) - assert f'"{exec_file}"' in cmd + assert f"{exec_file}" in cmd assert f" -j {jobname} " in cmd assert f" -port {port} " in cmd assert f" -m {ram*1024} " in cmd @@ -978,6 +978,7 @@ def test_generate_mapdl_launch_command_windows(): assert f" -o .__tmp__.out " in cmd +@patch("os.name", "posix") def test_generate_mapdl_launch_command_linux(): assert os.name != "nt" # Checking mocking is properly done