diff --git a/doc/changelog.d/4028.maintenance.md b/doc/changelog.d/4028.maintenance.md new file mode 100644 index 000000000000..fbf86421c912 --- /dev/null +++ b/doc/changelog.d/4028.maintenance.md @@ -0,0 +1 @@ +Add a way to extract Fluent launch command and subprocess arguments from StandaloneLauncher \ No newline at end of file diff --git a/src/ansys/fluent/core/launcher/launcher.py b/src/ansys/fluent/core/launcher/launcher.py index 723054192eaa..70932c1c789b 100644 --- a/src/ansys/fluent/core/launcher/launcher.py +++ b/src/ansys/fluent/core/launcher/launcher.py @@ -312,8 +312,6 @@ def launch_fluent( The allocated machines and core counts are queried from the scheduler environment and passed to Fluent. """ - if env is None: - env = {} def _mode_to_launcher_type(fluent_launch_mode: LaunchMode): launcher_mode_type = { diff --git a/src/ansys/fluent/core/launcher/slurm_launcher.py b/src/ansys/fluent/core/launcher/slurm_launcher.py index ca12e30784a6..84b7f09916f7 100644 --- a/src/ansys/fluent/core/launcher/slurm_launcher.py +++ b/src/ansys/fluent/core/launcher/slurm_launcher.py @@ -416,6 +416,7 @@ def __init__( """ if not _SlurmWrapper.is_available(): raise RuntimeError("Slurm is not available.") + env = env or {} locals_ = locals().copy() argvals = { arg: locals_.get(arg) diff --git a/src/ansys/fluent/core/launcher/standalone_launcher.py b/src/ansys/fluent/core/launcher/standalone_launcher.py index 8bc4bc392bbc..abc7e16e59ac 100644 --- a/src/ansys/fluent/core/launcher/standalone_launcher.py +++ b/src/ansys/fluent/core/launcher/standalone_launcher.py @@ -40,7 +40,7 @@ import os from pathlib import Path import subprocess -from typing import Any, Dict +from typing import Any from ansys.fluent.core.launcher.error_handler import ( LaunchFluentError, @@ -91,7 +91,7 @@ def __init__( journal_file_names: None | str | list[str] = None, start_timeout: int = 60, additional_arguments: str = "", - env: Dict[str, Any] | None = None, + env: dict[str, Any] | None = None, cleanup_on_exit: bool = True, dry_run: bool = False, start_transcript: bool = True, @@ -184,7 +184,7 @@ def __init__( In job scheduler environments (e.g., SLURM, LSF, PBS), resources and compute nodes are allocated, and core counts are queried from these environments before being passed to Fluent. """ - import ansys.fluent.core as pyfluent + env = env or {} locals_ = locals().copy() argvals = { @@ -234,6 +234,8 @@ def __init__( ) if is_windows(): + import ansys.fluent.core as pyfluent + if pyfluent.LAUNCH_FLUENT_STDOUT or pyfluent.LAUNCH_FLUENT_STDERR: self._launch_cmd = self._launch_string else: @@ -246,6 +248,16 @@ def __init__( else: self._launch_cmd = self._launch_string + @property + def command(self) -> str: + """Return the command for launching Fluent.""" + return self._launch_string + + @property + def subprocess_keywords(self) -> dict[str, Any]: + """Return the keyword arguments for launching Fluent via Python subprocess.""" + return self._kwargs + def __call__(self): if self.argvals["dry_run"]: print(f"Fluent launch string: {self._launch_string}")