Skip to content

Commit

Permalink
fix: configure remote grpc file transfer service (#2775)
Browse files Browse the repository at this point in the history
* fix: configure remote grpc file transfer service

* add return_without_path=False

* Revert "add return_without_path=False"

This reverts commit 0eaedd9.

* update download_file()

* test fix

* test fix 1

* test fix 2

* name change

* test fix 2

* test fix 4

* fix: Disable remote gRPC FTS

* test update

* configure fix

* configure fix 1

* configure fix 2

* configure fix 3

* configure fix 4

* configure fix 5

* configure fix 6

* configure fix 7

* configure fix 8
  • Loading branch information
hpohekar authored May 7, 2024
1 parent b5c26ca commit 9b5cd1b
Show file tree
Hide file tree
Showing 12 changed files with 197 additions and 71 deletions.
3 changes: 3 additions & 0 deletions src/ansys/fluent/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ def version_info() -> str:
# Whether stream and cache commands state
DATAMODEL_USE_NOCOMMANDS_DIFF_STATE = True

# Whether to use remote gRPC file transfer service
USE_FILE_TRANSFER_SERVICE = False

# Parent directory where codegen writes out API files
GENERATED_API_DIR = (Path(__file__) / ".." / "generated").resolve()

Expand Down
7 changes: 4 additions & 3 deletions src/ansys/fluent/core/examples/downloads.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,10 @@ def download_file(
"""
if return_without_path is None:
if os.getenv("PYFLUENT_LAUNCH_CONTAINER") == "1":
return_without_path = True
else:
return_without_path = False
if pyfluent.USE_FILE_TRANSFER_SERVICE:
return_without_path = False
else:
return_without_path = True

url = _get_file_url(file_name, directory)
head = requests.head(f"{url}")
Expand Down
5 changes: 4 additions & 1 deletion src/ansys/fluent/core/launcher/fluent_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,10 @@ def configure_container_dict(
logger.debug(f"container_dict before processing: {container_dict}")

if not host_mount_path:
host_mount_path = pyfluent.EXAMPLES_PATH
if pyfluent.USE_FILE_TRANSFER_SERVICE:
host_mount_path = pyfluent.USER_DATA_PATH
else:
host_mount_path = pyfluent.EXAMPLES_PATH
elif "volumes" in container_dict:
logger.warning(
"'volumes' keyword specified in 'container_dict', but "
Expand Down
29 changes: 4 additions & 25 deletions src/ansys/fluent/core/utils/file_transfer_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,32 +110,11 @@ def download(

def _get_files(
file_name: Union[str, pathlib.PurePath, list[Union[str, pathlib.PurePath]]],
path: str,
):
if isinstance(file_name, (str, pathlib.PurePath)):
file_name = pathlib.Path(file_name)
file_path_check = os.path.join(path, file_name.name)
files = [file_path_check] if os.path.isfile(file_path_check) else [file_name]
logger.debug(f"\n pyfluent.EXAMPLES_PATH = {pyfluent.EXAMPLES_PATH} \n")
logger.debug(f"\n host_mount_path = {path} \n")
logger.debug(f"\n file_name = {file_name} \n")
logger.debug(f"\n file_name.name = {file_name.name} \n")
logger.debug(f"\n file_path_check = {file_path_check} \n")
logger.debug(f"\n is_file_path_check = {os.path.isfile(file_path_check)} \n")
logger.debug(f"\n files = {files} \n")
files = [pathlib.Path(file_name)]
elif isinstance(file_name, list):
files = []
for file in file_name:
file_path_check = os.path.join(path, os.path.basename(file))
logger.debug(f"\n file_path_check = {file_path_check} \n")
logger.debug(
f"\n is_file_path_check = {os.path.isfile(file_path_check)} \n"
)
if os.path.isfile(file_path_check):
files.append(file_path_check)
else:
files.append(file)
logger.debug(f"\n files = {files} \n")
files = [pathlib.Path(file) for file in file_name]
return files


Expand Down Expand Up @@ -232,7 +211,7 @@ def upload(
FileNotFoundError
If a file does not exist.
"""
files = _get_files(file_name, self.host_mount_path)
files = _get_files(file_name)
if self.client:
for file in files:
is_file_on_remote = self.file_exists_on_remote(os.path.basename(file))
Expand Down Expand Up @@ -265,7 +244,7 @@ def download(
local_directory : str, optional
Local directory. The default is ``None``.
"""
files = _get_files(file_name, self.host_mount_path)
files = _get_files(file_name)
if self.client:
for file in files:
if os.path.isfile(file):
Expand Down
33 changes: 27 additions & 6 deletions tests/parametric/test_parametric_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import ansys.fluent.core as pyfluent
from ansys.fluent.core import examples
from ansys.fluent.core.launcher.fluent_container import DEFAULT_CONTAINER_MOUNT_PATH
from ansys.fluent.core.utils.file_transfer_service import RemoteFileTransferStrategy

PYTEST_RELATIVE_TOLERANCE = 1e-3

Expand All @@ -21,16 +22,28 @@ def test_parametric_workflow():
# parent path needs to exist for mkdtemp
Path(pyfluent.EXAMPLES_PATH).mkdir(parents=True, exist_ok=True)
tmp_save_path = tempfile.mkdtemp(dir=pyfluent.EXAMPLES_PATH)
if pyfluent.USE_FILE_TRANSFER_SERVICE:
file_transfer_service = RemoteFileTransferStrategy(
host_mount_path=tmp_save_path
)
import_file_name = examples.download_file(
"Static_Mixer_main.cas.h5", "pyfluent/static_mixer", save_path=tmp_save_path
)
if os.getenv("PYFLUENT_LAUNCH_CONTAINER") == "1":
inside_container = True
config_dict = {}
config_dict.update(host_mount_path=tmp_save_path)
solver_session = pyfluent.launch_fluent(
processor_count=2, container_dict=config_dict
)
if pyfluent.USE_FILE_TRANSFER_SERVICE:
solver_session = pyfluent.launch_fluent(
processor_count=2,
container_dict=config_dict,
file_transfer_service=file_transfer_service,
)
else:
solver_session = pyfluent.launch_fluent(
processor_count=2,
container_dict=config_dict,
)
container_workdir = PurePosixPath(DEFAULT_CONTAINER_MOUNT_PATH)
else:
inside_container = False
Expand Down Expand Up @@ -164,9 +177,17 @@ def test_parametric_workflow():
solver_session.exit()

if inside_container:
solver_session = pyfluent.launch_fluent(
processor_count=2, container_dict=config_dict
)
if pyfluent.USE_FILE_TRANSFER_SERVICE:
solver_session = pyfluent.launch_fluent(
processor_count=2,
container_dict=config_dict,
file_transfer_service=file_transfer_service,
)
else:
solver_session = pyfluent.launch_fluent(
processor_count=2,
container_dict=config_dict,
)
else:
solver_session = pyfluent.launch_fluent(processor_count=2, cwd=tmp_save_path)

Expand Down
13 changes: 6 additions & 7 deletions tests/test_file_transfer_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,6 @@

from ansys.fluent.core import examples

import_case_file_name = examples.download_file(
"mixing_elbow.cas.h5", "pyfluent/mixing_elbow"
)
import_mesh_file_name = examples.download_file(
"mixing_elbow.msh.h5", "pyfluent/mixing_elbow"
)


def file_downloaded_to_the_client(file_name: str) -> bool:
"""Check if client file exists.
Expand All @@ -39,6 +32,12 @@ def file_downloaded_to_the_client(file_name: str) -> bool:
@pytest.mark.fluent_version(">=24.2")
def test_remote_grpc_fts_container(monkeypatch, new_solver_session, new_mesh_session):
solver = new_solver_session
import_case_file_name = examples.download_file(
"mixing_elbow.cas.h5", "pyfluent/mixing_elbow"
)
import_mesh_file_name = examples.download_file(
"mixing_elbow.msh.h5", "pyfluent/mixing_elbow"
)
solver.file.read_case(file_name=import_case_file_name)
solver.file.write_case(file_name="downloaded_solver_mixing_elbow.cas.h5")
if solver._file_transfer_service:
Expand Down
8 changes: 4 additions & 4 deletions tests/test_launcher_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@
from ansys.fluent.core.utils.networking import get_free_port
import ansys.platform.instancemanagement as pypim

import_file_name = examples.download_file(
"mixing_elbow.msh.h5", "pyfluent/mixing_elbow"
)


def test_launch_remote_instance(monkeypatch, new_solver_session):
fluent = new_solver_session
Expand Down Expand Up @@ -151,6 +147,10 @@ def test_file_purpose_on_remote_instance(
file_transfer_service=file_service,
)

import_file_name = examples.download_file(
"mixing_elbow.msh.h5", "pyfluent/mixing_elbow"
)

solver_session.file.read_case(file_name=import_file_name)
assert len(file_service.uploads()) == 1
assert file_service.uploads()[0] == import_file_name
Expand Down
5 changes: 3 additions & 2 deletions tests/test_meshing_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

from ansys.fluent.core import examples

import_filename = examples.download_file("mixing_elbow.msh.h5", "pyfluent/mixing_elbow")

PYTEST_RELATIVE_TOLERANCE = 0.2


Expand All @@ -16,6 +14,9 @@ def pytest_approx(expected):
@pytest.mark.fluent_version(">=24.2")
def test_meshing_utilities(new_mesh_session):
meshing_session = new_mesh_session
import_filename = examples.download_file(
"mixing_elbow.msh.h5", "pyfluent/mixing_elbow"
)
meshing_session.tui.file.read_case(import_filename)

assert meshing_session.meshing_utilities._cell_zones_labels_fdl() == ["elbow-fluid"]
Expand Down
17 changes: 14 additions & 3 deletions tests/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from ansys.fluent.core.launcher.error_handler import LaunchFluentError
from ansys.fluent.core.session import BaseSession
from ansys.fluent.core.utils.execution import timeout_loop
from ansys.fluent.core.utils.file_transfer_service import RemoteFileTransferStrategy
from ansys.fluent.core.utils.fluent_version import FluentVersion
from ansys.fluent.core.utils.networking import get_free_port

Expand Down Expand Up @@ -357,9 +358,19 @@ def test_read_case_using_lightweight_mode():
import_file_name = examples.download_file(
"mixing_elbow.cas.h5", "pyfluent/mixing_elbow"
)
solver = pyfluent.launch_fluent(
case_file_name=import_file_name, lightweight_mode=True
)
if pyfluent.USE_FILE_TRANSFER_SERVICE:
container_dict = {"host_mount_path": pyfluent.USER_DATA_PATH}
file_transfer_service = RemoteFileTransferStrategy()
solver = pyfluent.launch_fluent(
case_file_name=import_file_name,
lightweight_mode=True,
container_dict=container_dict,
file_transfer_service=file_transfer_service,
)
else:
solver = pyfluent.launch_fluent(
case_file_name=import_file_name, lightweight_mode=True
)
solver.setup.models.energy.enabled = False
old_fluent_connection_id = id(solver._fluent_connection)
timeout_loop(
Expand Down
Loading

0 comments on commit 9b5cd1b

Please sign in to comment.