Skip to content

Commit

Permalink
fix: Skip Fluent's automatic transcript by default (#3488)
Browse files Browse the repository at this point in the history
* fix: Skip Fluent's automatic transcript by default

* feat: Add test

* feat: Add test

* feat: Add test

* fix: fix for container

* fix: style
  • Loading branch information
mkundu1 authored Nov 17, 2024
1 parent 1b73626 commit 5135056
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 6 deletions.
7 changes: 5 additions & 2 deletions src/ansys/fluent/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,11 @@ def version_info() -> str:
# Whether to zip settings API files during codegen
CODEGEN_ZIP_SETTINGS = os.getenv("PYFLUENT_CODEGEN_ZIP_SETTINGS", False)

# Whether to show mesh after case read
SHOW_MESH_AFTER_CASE_READ = False
# Whether to show mesh in Fluent after case read
FLUENT_SHOW_MESH_AFTER_CASE_READ = False

# Whether to write the automatic transcript in Fluent
FLUENT_AUTOMATIC_TRANSCRIPT = False

# Whether to interrupt Fluent solver from PyFluent
SUPPORT_SOLVER_INTERRUPT = False
Expand Down
5 changes: 5 additions & 0 deletions src/ansys/fluent/core/launcher/fluent_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,11 @@ def configure_container_dict(

container_dict["fluent_image"] = fluent_image

if not pyfluent.FLUENT_AUTOMATIC_TRANSCRIPT:
if "environment" not in container_dict:
container_dict["environment"] = {}
container_dict["environment"]["FLUENT_NO_AUTOMATIC_TRANSCRIPT"] = "1"

fluent_commands = ["-gu", f"-sifile={container_server_info_file}"] + args

container_dict_default = {}
Expand Down
9 changes: 6 additions & 3 deletions src/ansys/fluent/core/launcher/launcher_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def is_windows():


def _get_subprocess_kwargs_for_fluent(env: Dict[str, Any], argvals) -> Dict[str, Any]:
from ansys.fluent.core import CLEAR_FLUENT_PARA_ENVS, INFER_REMOTING_IP
import ansys.fluent.core as pyfluent

scheduler_options = argvals.get("scheduler_options")
is_slurm = scheduler_options and scheduler_options["scheduler"] == "slurm"
Expand All @@ -35,16 +35,19 @@ def _get_subprocess_kwargs_for_fluent(env: Dict[str, Any], argvals) -> Dict[str,
fluent_env = os.environ.copy()
fluent_env.update({k: str(v) for k, v in env.items()})
fluent_env["REMOTING_THROW_LAST_TUI_ERROR"] = "1"
if CLEAR_FLUENT_PARA_ENVS:
if pyfluent.CLEAR_FLUENT_PARA_ENVS:
del fluent_env["PARA_NPROCS"]
del fluent_env["PARA_MESH_NPROCS"]

if not is_slurm:
if INFER_REMOTING_IP and "REMOTING_SERVER_ADDRESS" not in fluent_env:
if pyfluent.INFER_REMOTING_IP and "REMOTING_SERVER_ADDRESS" not in fluent_env:
remoting_ip = find_remoting_ip()
if remoting_ip:
fluent_env["REMOTING_SERVER_ADDRESS"] = remoting_ip

if not pyfluent.FLUENT_AUTOMATIC_TRANSCRIPT:
fluent_env["FLUENT_NO_AUTOMATIC_TRANSCRIPT"] = "1"

kwargs.update(env=fluent_env)
return kwargs

Expand Down
2 changes: 1 addition & 1 deletion src/ansys/fluent/core/launcher/process_launch_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def _generate_launch_string(
if " " in server_info_file_name:
server_info_file_name = '"' + server_info_file_name + '"'
launch_string += f" -sifile={server_info_file_name}"
if not pyfluent.SHOW_MESH_AFTER_CASE_READ:
if not pyfluent.FLUENT_SHOW_MESH_AFTER_CASE_READ:
launch_string += " -nm"
return launch_string

Expand Down
13 changes: 13 additions & 0 deletions tests/test_launcher.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
from pathlib import Path
import platform
from tempfile import TemporaryDirectory

import pytest

Expand Down Expand Up @@ -486,3 +487,15 @@ def test_container_warning_for_mount_source(caplog):
_ = pyfluent.launch_fluent(container_dict=container_dict)
assert container_dict["mount_source"] in caplog.text
assert container_dict["mount_target"] in caplog.text


# runs only in container till cwd is supported for container launch
def test_fluent_automatic_transcript(monkeypatch):
with monkeypatch.context() as m:
m.setattr(pyfluent, "FLUENT_AUTOMATIC_TRANSCRIPT", True)
with TemporaryDirectory(dir=pyfluent.EXAMPLES_PATH) as tmp_dir:
with pyfluent.launch_fluent(container_dict=dict(working_dir=tmp_dir)):
assert list(Path(tmp_dir).glob("*.trn"))
with TemporaryDirectory(dir=pyfluent.EXAMPLES_PATH) as tmp_dir:
with pyfluent.launch_fluent(container_dict=dict(working_dir=tmp_dir)):
assert not list(Path(tmp_dir).glob("*.trn"))

0 comments on commit 5135056

Please sign in to comment.